Add Docker support

This commit is contained in:
rubenwardy 2019-01-09 21:58:11 +00:00
parent 0db49efe4a
commit a45df0e173
5 changed files with 59 additions and 6 deletions

2
.gitignore vendored

@ -1,5 +1,6 @@
config.cfg
config.prod.cfg
*.env
*.sqlite
custom.css
tmp
@ -8,6 +9,7 @@ log.txt
uploads
thumbnails
celerybeat-schedule
/data
# Created by https://www.gitignore.io/api/linux,macos,python,windows

19
Dockerfile Normal file

@ -0,0 +1,19 @@
FROM python:3.7
WORKDIR /home/cdb
COPY requirements.txt requirements.txt
RUN pip install -r ./requirements.txt
RUN pip install gunicorn
RUN pip install psycopg2
COPY runprodguni.sh ./
RUN chmod +x runprodguni.sh
COPY setup.py ./setup.py
COPY app app
COPY migrations migrations
COPY config.prod.cfg ./config.prod.cfg
EXPOSE 5123
ENTRYPOINT ["./runprodguni.sh"]

29
docker-compose.yml Normal file

@ -0,0 +1,29 @@
version: '3'
services:
db:
image: "postgres:9.6.5"
restart: always
volumes:
- "./data/db:/var/lib/postgresql/data"
env_file:
- db.env
networks:
- db_nw
app:
build: .
ports:
- 5123:5123
volumes:
- "./data/uploads:/home/app/public/uploads"
networks:
- db_nw
- web_nw
depends_on:
- db
networks:
db_nw:
driver: bridge
web_nw:
driver: bridge

@ -1,3 +1,3 @@
#!/bin/bash
gunicorn -w 4 -b 127.0.0.1:5123 -e FLASK_APP=app/__init__.py -e FLASK_CONFIG=../config.prod.cfg -e FLASK_DEBUG=0 app:app
gunicorn -w 4 -b :5123 -e FLASK_APP=app/__init__.py -e FLASK_CONFIG=../config.prod.cfg -e FLASK_DEBUG=0 app:app

@ -20,7 +20,9 @@ import os, sys, datetime
if not "FLASK_CONFIG" in os.environ:
os.environ["FLASK_CONFIG"] = "../config.cfg"
test_data = len(sys.argv) >= 2 and sys.argv[1].strip() == "-t"
delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
create_db = not (len(sys.argv) >= 2 and sys.argv[1].strip() == "-o")
test_data = len(sys.argv) >= 2 and sys.argv[1].strip() == "-t" or not create_db
from app.models import *
from app.utils import make_flask_user_password
@ -333,13 +335,14 @@ Uses the CTF PvP Engine.
db.session.add(dep)
delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
if delete_db and os.path.isfile("db.sqlite"):
os.remove("db.sqlite")
print("Creating database tables...")
db.create_all()
if create_db:
print("Creating database tables...")
db.create_all()
print("Filling database...")
ruben = User("rubenwardy")