aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Dockerfile19
-rw-r--r--docker-compose.yml29
-rw-r--r--runprodguni.sh2
-rw-r--r--setup.py13
5 files changed, 59 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 64fb527..03d9779 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..21f35ed
--- /dev/null
+++ b/Dockerfile
@@ -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"]
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..685d4c5
--- /dev/null
+++ b/docker-compose.yml
@@ -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
diff --git a/runprodguni.sh b/runprodguni.sh
index 7069034..fca01c0 100644
--- a/runprodguni.sh
+++ b/runprodguni.sh
@@ -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
diff --git a/setup.py b/setup.py
index df57698..5d75cc5 100644
--- a/setup.py
+++ b/setup.py
@@ -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")