]> git.lizzy.rs Git - cheatdb.git/commitdiff
Add Docker support
authorrubenwardy <rw@rubenwardy.com>
Wed, 9 Jan 2019 21:58:11 +0000 (21:58 +0000)
committerrubenwardy <rw@rubenwardy.com>
Wed, 9 Jan 2019 21:58:11 +0000 (21:58 +0000)
.gitignore
Dockerfile [new file with mode: 0644]
docker-compose.yml [new file with mode: 0644]
runprodguni.sh
setup.py

index 64fb527bee145e496260f7c6e7d976843981b205..03d9779941b1d1fef8ff7b03a10a3a07bf6f329a 100644 (file)
@@ -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 (file)
index 0000000..21f35ed
--- /dev/null
@@ -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 (file)
index 0000000..685d4c5
--- /dev/null
@@ -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
index 7069034660f627294a28dd37690d4dfe91609946..fca01c0d51c76ecd38db5878ab9262b18acc7ff7 100644 (file)
@@ -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
index df57698556b11eac63ddff4b61d2dc296e215e6e..5d75cc580bacae8c4a27953d26ea175098f054c5 100644 (file)
--- 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")