Compare commits

..

20 Commits

Author SHA1 Message Date
93ff836e08 The real drone yml
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-08-28 13:20:12 +03:00
cd47d4aa84 The real drone yml
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-08-28 13:04:13 +03:00
2785d3d6b6 Пофиксил баг
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2021-11-01 06:07:41 +03:00
f4732836ad Сделал нормальные JSON ответы
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 06:05:33 +03:00
b0bd579357 Верну тишину
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 05:56:22 +03:00
fd341bd9df Поправил тест
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 05:54:36 +03:00
4608125fdf Smol fixes 2021-11-01 05:25:57 +03:00
8e52e543f9 Верну проброс конфига
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 05:19:39 +03:00
80aeafa013 Короче проще поправить конфиг 2021-11-01 05:17:40 +03:00
66d68701c2 Revert "В репе конфиг не нужен"
Some checks failed
continuous-integration/drone/push Build is failing
Все пошло не так

This reverts commit 0ba3b5f037.
2021-11-01 05:13:35 +03:00
94a626e7f1 Не будем пробрасывать конфиг (а нужно ли его вытаскивать наружу?)
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 05:07:50 +03:00
0ba3b5f037 В репе конфиг не нужен
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is failing
2021-11-01 05:02:12 +03:00
7544e3c447 Добавил конфигурацию самого приложения
Some checks failed
continuous-integration/drone/push Build is failing
2021-11-01 04:58:13 +03:00
96790be6f7 Вернул метрики
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 04:46:07 +03:00
89dcffa6bb Merge pull request 'prometheus-monitoring' (#3) from prometheus-monitoring into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: http://git.lulzette.ru/lulzette/pycms/pulls/3
2021-11-01 04:40:18 +03:00
4f736f763e Нет, надо вот так
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing
2021-11-01 04:38:54 +03:00
f84994999a Добавил остановку текущих контейнеров
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
2021-11-01 04:36:41 +03:00
74cd6c6d4b Revert "Добавил простую метрику"
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is passing
Тут этого быть не должно 0_0

This reverts commit 54139d6f76.
2021-11-01 04:30:27 +03:00
49f981708a Добавил шагов
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 04:28:02 +03:00
54139d6f76 Добавил простую метрику
All checks were successful
continuous-integration/drone/push Build is passing
2021-10-31 02:24:54 +03:00
5 changed files with 70 additions and 28 deletions

View File

@ -1,20 +1,25 @@
kind: pipeline kind: pipeline
type: exec type: exec
name: default name: build
platform:
os: linux
arch: amd64
steps: steps:
- name: build - name: build
commands: commands:
- docker-compose -p pycms build - docker-compose -p pycms build
- name: test - docker-compose -p pycms push
commands:
- docker-compose -p pycms up --build --abort-on-container-exit
- name: run
commands:
- docker-compose -p pycms up -d
---
name: test
type: docker
kind: pipeline
steps:
- name: run db
image: mongo
detach: true
- name: run_tests
image: pycms_server
commands:
- bash ./test.sh
depends_on:
- build

View File

@ -2,4 +2,7 @@
host = db host = db
port = 27017 port = 27017
name = pycms name = pycms
[App]
host = 0.0.0.0
port = 8080
debug = True

View File

@ -4,10 +4,10 @@ services:
build: . build: .
ports: ports:
- 8080:8080 - 8080:8080
volumes:
- ./config.ini:/app/config.ini
depends_on: depends_on:
- db - db
volumes:
- ./config.ini:/app/config.ini
db: db:
image: mongo image: mongo
tests: tests:

53
main.py
View File

@ -16,6 +16,10 @@ class Config:
- host - host
- port - port
- dbname - dbname
App:
- host
- port
- debug
""" """
def __init__(self): def __init__(self):
""" """
@ -28,9 +32,8 @@ class Config:
print('DB not found, creating') print('DB not found, creating')
database = mongoclient[self.dbname] database = mongoclient[self.dbname]
# TODO: Create table if not exists
if 'posts' not in database.list_collection_names(): if 'posts' not in database.list_collection_names():
print('Table not fount, creating') print('Table not found, creating')
posts = database['posts'] posts = database['posts']
self.posts = posts self.posts = posts
@ -44,11 +47,15 @@ class Config:
self.createConfig(config) self.createConfig(config)
db = config['DB'] db = config['DB']
self.host = db['host'] self.host = db['host']
self.port = int(db['port']) self.port = int(db['port'])
self.dbname = db['name'] 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): def createConfig(self, config):
""" """
Create config file Create config file
@ -59,6 +66,12 @@ class Config:
db['port'] = '27017' db['port'] = '27017'
db['name'] = 'pycms' 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: with open('config.ini', 'w') as cfgfile:
config.write(cfgfile) config.write(cfgfile)
@ -88,20 +101,38 @@ class Back():
return str(dict_posts) return str(dict_posts)
def updatePost(self, name, body): def updatePost(self, name, body):
# TODO: return RESTful error/success result
# If post exists, update it # If post exists, update it
if posts.find_one({'name': name}): if posts.find_one({'name': name}):
newPost = {'$set': {'text': body}} newPostJson = {'$set': {'text': body}}
return str(posts.update_one({'name': name}, newPost)) newPost = posts.update_one({'name': name}, newPostJson)
result = dict(
status=200, state='updated', count=newPost.matched_count
)
# Else - create new # Else - create new
else: else:
newPost = {'name': name, 'text': body, newPostJson = {'name': name, 'text': body,
'create_timestamp': str(time.time())} 'create_timestamp': str(time.time())}
return str(posts.insert_one(newPost).inserted_id) newPost = posts.insert_one(newPostJson).inserted_id
result = dict(status=200, state='new')
return str(result)
def deletePost(self, name): def deletePost(self, name):
# TODO: return RESTful error/success result delete = posts.delete_one({'name': name}).deleted_count
return bool(posts.delete_one({'name': name}).deleted_count) if not delete:
result = dict(status=500, count=delete)
else:
result = dict(status=200, count=delete)
return str(result)
class Metrics:
def alive():
return str("alive 1")
@route('/metrics')
def metrics():
return Metrics.alive()
@route('/post/<name>') @route('/post/<name>')
@ -148,4 +179,4 @@ if __name__ == '__main__':
print("Configured") print("Configured")
back = Back() back = Back()
posts = cfg.posts 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)

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
curl_cmd='curl -s -w "%{http_code}" -o /dev/null' curl_cmd='curl -s -w :%{http_code}'
#curl_cmd='curl -s -w "%{http_code}\t%{stdout}" -o /dev/null'
url='server:8080' url='server:8080'
$curl_cmd -X POST $url/admin/post/test -F 'body=testpage' && echo ": Create success" || echo ': create fail' $curl_cmd -X POST $url/admin/post/test -F 'body=testpage' && echo ": Create success" || echo ': create fail'
@ -8,3 +9,5 @@ $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 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 -X DELETE $url/admin/post/test && echo ": delete success" || echo ': delete fail'
$curl_cmd $url/metrics && echo ": metrics available" || echo ': metrics unavailable'