Compare commits
15 Commits
85a860eb1a
...
prometheus
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f736f763e | |||
| f84994999a | |||
| 74cd6c6d4b | |||
| 49f981708a | |||
| 54139d6f76 | |||
| 4ab80616a6 | |||
| 04905c59db | |||
| c4602b9d4e | |||
| 2f5867028e | |||
| 1aa4be2e47 | |||
| 3aa77129ec | |||
| 32a2678170 | |||
| 6cd33f25be | |||
| 7c7db5bca0 | |||
| 755e7c5ce4 |
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
|
||||
|
||||
|
||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM python:latest
|
||||
|
||||
ADD . /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN pip3 install --upgrade pip && pip3 install -r requirements.txt
|
||||
EXPOSE 8080
|
||||
CMD python3 main.py
|
||||
@@ -1,5 +1,5 @@
|
||||
[DB]
|
||||
host = localhost
|
||||
host = db
|
||||
port = 27017
|
||||
name = pycms
|
||||
|
||||
|
||||
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
version: '3'
|
||||
services:
|
||||
server:
|
||||
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
|
||||
14
main.py
14
main.py
@@ -1,10 +1,11 @@
|
||||
#!/usr/bin/python3
|
||||
from bottle import abort, route, run, request
|
||||
import pymongo
|
||||
|
||||
import time
|
||||
# TODO: auth to /admin
|
||||
# TODO: timestamps to posts
|
||||
# TODO: author to posts and multiple users
|
||||
# TODO: add bottle's params to config
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -23,9 +24,13 @@ class Config:
|
||||
self.readConfig()
|
||||
|
||||
mongoclient = pymongo.MongoClient(self.host, self.port)
|
||||
if self.dbname not in mongoclient.list_database_names():
|
||||
print('DB not found, creating')
|
||||
database = mongoclient[self.dbname]
|
||||
|
||||
# TODO: Create table if not exists
|
||||
if 'posts' not in database.list_collection_names():
|
||||
print('Table not fount, creating')
|
||||
posts = database['posts']
|
||||
self.posts = posts
|
||||
|
||||
@@ -90,7 +95,8 @@ class Back():
|
||||
return str(posts.update_one({'name': name}, newPost))
|
||||
# Else - create new
|
||||
else:
|
||||
newPost = {'name': name, 'text': body}
|
||||
newPost = {'name': name, 'text': body,
|
||||
'create_timestamp': str(time.time())}
|
||||
return str(posts.insert_one(newPost).inserted_id)
|
||||
|
||||
def deletePost(self, name):
|
||||
@@ -137,7 +143,9 @@ def index():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Init")
|
||||
cfg = Config()
|
||||
print("Configured")
|
||||
back = Back()
|
||||
posts = cfg.posts
|
||||
run(host='0.0.0.0', port=8081, reloader=True, debug=True)
|
||||
run(host='0.0.0.0', port=8080, reloader=True, debug=True)
|
||||
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
bottle==0.12.19
|
||||
pymongo==3.12.0
|
||||
10
test.sh
Normal file
10
test.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/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'
|
||||
Reference in New Issue
Block a user