Compare commits
17 Commits
gitlab
...
66d68701c2
| Author | SHA1 | Date | |
|---|---|---|---|
| 66d68701c2 | |||
| 94a626e7f1 | |||
| 0ba3b5f037 | |||
| 7544e3c447 | |||
| 96790be6f7 | |||
| 89dcffa6bb | |||
| 4f736f763e | |||
| f84994999a | |||
| 74cd6c6d4b | |||
| 49f981708a | |||
| 54139d6f76 | |||
| 4ab80616a6 | |||
| 04905c59db | |||
| c4602b9d4e | |||
| 2f5867028e | |||
| 1aa4be2e47 | |||
| 3aa77129ec |
22
.drone.yml
Normal file
22
.drone.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
kind: pipeline
|
||||
type: exec
|
||||
name: build
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- docker-compose -p pycms build
|
||||
|
||||
- name: test
|
||||
commands:
|
||||
- docker-compose -p pycms up --build --abort-on-container-exit
|
||||
|
||||
- name: push
|
||||
commands:
|
||||
- docker-compose -p pycms push
|
||||
- name: run
|
||||
commands:
|
||||
- docker-compose -p pycms down
|
||||
- docker-compose -p pycms up -d
|
||||
|
||||
|
||||
@@ -4,9 +4,13 @@ services:
|
||||
build: .
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- ./config.ini:/app/config.ini
|
||||
depends_on:
|
||||
- db
|
||||
db:
|
||||
image: mongo
|
||||
tests:
|
||||
build: .
|
||||
command: bash ./test.sh
|
||||
depends_on:
|
||||
- db
|
||||
- server
|
||||
|
||||
24
main.py
24
main.py
@@ -44,11 +44,15 @@ class Config:
|
||||
self.createConfig(config)
|
||||
|
||||
db = config['DB']
|
||||
|
||||
self.host = db['host']
|
||||
self.port = int(db['port'])
|
||||
self.dbname = db['name']
|
||||
|
||||
app = config['App']
|
||||
self.apphost = app['host']
|
||||
self.appport = int(app['port'])
|
||||
self.appdebug = bool(app['debug'])
|
||||
|
||||
def createConfig(self, config):
|
||||
"""
|
||||
Create config file
|
||||
@@ -59,6 +63,12 @@ class Config:
|
||||
db['port'] = '27017'
|
||||
db['name'] = 'pycms'
|
||||
|
||||
config['App'] = {}
|
||||
app = config['App']
|
||||
app['port'] = '8080'
|
||||
app['debug'] = 'True'
|
||||
app['host'] = '0.0.0.0'
|
||||
|
||||
with open('config.ini', 'w') as cfgfile:
|
||||
config.write(cfgfile)
|
||||
|
||||
@@ -104,6 +114,16 @@ class Back():
|
||||
return bool(posts.delete_one({'name': name}).deleted_count)
|
||||
|
||||
|
||||
class Metrics:
|
||||
def alive():
|
||||
return str("alive 1")
|
||||
|
||||
|
||||
@route('/metrics')
|
||||
def metrics():
|
||||
return Metrics.alive()
|
||||
|
||||
|
||||
@route('/post/<name>')
|
||||
def post(name):
|
||||
'''
|
||||
@@ -148,4 +168,4 @@ if __name__ == '__main__':
|
||||
print("Configured")
|
||||
back = Back()
|
||||
posts = cfg.posts
|
||||
run(host='0.0.0.0', port=8080, reloader=True, debug=True)
|
||||
run(host=cfg.apphost, port=cfg.appport, reloader=cfg.appdebug, debug=cfg.appdebug)
|
||||
|
||||
12
test.sh
Normal file
12
test.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
curl_cmd='curl -s -w "%{http_code}" -o /dev/null'
|
||||
url='server:8080'
|
||||
$curl_cmd -X POST $url/admin/post/test -F 'body=testpage' && echo ": Create success" || echo ': create fail'
|
||||
|
||||
$curl_cmd $url/post/test && echo ": get Success" || echo ': get fail'
|
||||
|
||||
$curl_cmd -X POST $url/admin/post/test -F 'body=testpage2' && echo ": Update success" || echo ': update fail'
|
||||
|
||||
$curl_cmd -X DELETE $url/admin/post/test && echo ": delete success" || echo ': delete fail'
|
||||
|
||||
$curl_cmd $url/metrics && echo ": metrics available" || echo ': metrics unavailable'
|
||||
Reference in New Issue
Block a user