Compare commits
6 Commits
85a860eb1a
...
gitlab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76282e9e28 | ||
|
|
0b7d20dcaa | ||
| 32a2678170 | |||
| 6cd33f25be | |||
| 7c7db5bca0 | |||
| 755e7c5ce4 |
39
.gitlab-ci.yml
Normal file
39
.gitlab-ci.yml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# This file is a template, and might need editing before it works on your project.
|
||||||
|
# To contribute improvements to CI/CD templates, please follow the Development guide at:
|
||||||
|
# https://docs.gitlab.com/ee/development/cicd/templates.html
|
||||||
|
# This specific template is located at:
|
||||||
|
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
|
||||||
|
|
||||||
|
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
|
||||||
|
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
|
||||||
|
# it uses echo commands to simulate the pipeline execution.
|
||||||
|
#
|
||||||
|
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
|
||||||
|
# Stages run in sequential order, but jobs within stages run in parallel.
|
||||||
|
#
|
||||||
|
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
|
||||||
|
|
||||||
|
stages: # List of stages for jobs, and their order of execution
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
build-job: # This job runs in the build stage, which runs first.
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- echo "Compiling the code..."
|
||||||
|
- docker build .
|
||||||
|
- echo "Compile complete."
|
||||||
|
|
||||||
|
test-job: # This job also runs in the test stage.
|
||||||
|
stage: test # It can run at the same time as unit-test-job (in parallel).
|
||||||
|
script:
|
||||||
|
- echo "Linting code... This will take about 10 seconds."
|
||||||
|
- docker-compose up --build --abort-on-container-exit
|
||||||
|
- echo "No lint issues found."
|
||||||
|
|
||||||
|
deploy-job: # This job runs in the deploy stage.
|
||||||
|
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
|
||||||
|
script:
|
||||||
|
- echo "Deploying application..."
|
||||||
|
- echo "Application successfully deployed."
|
||||||
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]
|
[DB]
|
||||||
host = localhost
|
host = db
|
||||||
port = 27017
|
port = 27017
|
||||||
name = pycms
|
name = pycms
|
||||||
|
|
||||||
|
|||||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
server:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
volumes:
|
||||||
|
- ./config.ini:/app/config.ini
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
db:
|
||||||
|
image: mongo
|
||||||
14
main.py
14
main.py
@@ -1,10 +1,11 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from bottle import abort, route, run, request
|
from bottle import abort, route, run, request
|
||||||
import pymongo
|
import pymongo
|
||||||
|
import time
|
||||||
# TODO: auth to /admin
|
# TODO: auth to /admin
|
||||||
# TODO: timestamps to posts
|
# TODO: timestamps to posts
|
||||||
# TODO: author to posts and multiple users
|
# TODO: author to posts and multiple users
|
||||||
|
# TODO: add bottle's params to config
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@@ -23,9 +24,13 @@ class Config:
|
|||||||
self.readConfig()
|
self.readConfig()
|
||||||
|
|
||||||
mongoclient = pymongo.MongoClient(self.host, self.port)
|
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]
|
database = mongoclient[self.dbname]
|
||||||
|
|
||||||
# TODO: Create table if not exists
|
# TODO: Create table if not exists
|
||||||
|
if 'posts' not in database.list_collection_names():
|
||||||
|
print('Table not fount, creating')
|
||||||
posts = database['posts']
|
posts = database['posts']
|
||||||
self.posts = posts
|
self.posts = posts
|
||||||
|
|
||||||
@@ -90,7 +95,8 @@ class Back():
|
|||||||
return str(posts.update_one({'name': name}, newPost))
|
return str(posts.update_one({'name': name}, newPost))
|
||||||
# Else - create new
|
# Else - create new
|
||||||
else:
|
else:
|
||||||
newPost = {'name': name, 'text': body}
|
newPost = {'name': name, 'text': body,
|
||||||
|
'create_timestamp': str(time.time())}
|
||||||
return str(posts.insert_one(newPost).inserted_id)
|
return str(posts.insert_one(newPost).inserted_id)
|
||||||
|
|
||||||
def deletePost(self, name):
|
def deletePost(self, name):
|
||||||
@@ -137,7 +143,9 @@ def index():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
print("Init")
|
||||||
cfg = Config()
|
cfg = Config()
|
||||||
|
print("Configured")
|
||||||
back = Back()
|
back = Back()
|
||||||
posts = cfg.posts
|
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
|
||||||
Reference in New Issue
Block a user