diff --git a/README.md b/README.md index 0d90a6c..461f79b 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,17 @@ Just A Cool Online Ballot-Box ## Requirements - Python 3.11 + +## Docker for development + +You can use docker and avoid any setup. Just run: + +``` +docker-compose -f dev.yaml build +docker-compose -f dev.yaml up +``` + +which will spin up the Flask application (http://localhost:5000), a Postgres instance, and an Adminer instance to poke at the database (http://localhost:5001). +Any changes to the `app/` folder will be immediately reflected inside the Flask container. +To wipe the database, delete the `jacob_dev_db_data` volume. +By default, webservers are only visible to localhost. \ No newline at end of file diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..dd3813f --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.11 + +WORKDIR /app +COPY requirements.txt . +RUN pip install -r requirements.txt +COPY . . + +CMD ["python", "app.py"] \ No newline at end of file diff --git a/admin.py b/app/admin.py similarity index 100% rename from admin.py rename to app/admin.py diff --git a/app.py b/app/app.py similarity index 51% rename from app.py rename to app/app.py index 3e006a2..14c0a3b 100644 --- a/app.py +++ b/app/app.py @@ -15,4 +15,11 @@ def about(): import admin if __name__ == '__main__': - app.run() + import os + + if os.environ.get('PRODUCTION'): + raise Exception("Can't run interactively in PRODUCTION") + + app.run(host=os.environ.get('FLASK_HOST', '127.0.0.1'), + port=os.environ.get('FLASK_PORT', 5000), + debug=os.environ.get('FLASK_DEBUG', True)) diff --git a/elections.py b/app/elections.py similarity index 100% rename from elections.py rename to app/elections.py diff --git a/requirements.txt b/app/requirements.txt similarity index 100% rename from requirements.txt rename to app/requirements.txt diff --git a/static/style.css b/app/static/style.css similarity index 100% rename from static/style.css rename to app/static/style.css diff --git a/templates/about.html b/app/templates/about.html similarity index 100% rename from templates/about.html rename to app/templates/about.html diff --git a/templates/audit.html b/app/templates/audit.html similarity index 100% rename from templates/audit.html rename to app/templates/audit.html diff --git a/templates/create_election.html b/app/templates/create_election.html similarity index 100% rename from templates/create_election.html rename to app/templates/create_election.html diff --git a/templates/create_society.html b/app/templates/create_society.html similarity index 100% rename from templates/create_society.html rename to app/templates/create_society.html diff --git a/templates/election.html b/app/templates/election.html similarity index 100% rename from templates/election.html rename to app/templates/election.html diff --git a/templates/includes/header.html b/app/templates/includes/header.html similarity index 100% rename from templates/includes/header.html rename to app/templates/includes/header.html diff --git a/templates/index.html b/app/templates/index.html similarity index 100% rename from templates/index.html rename to app/templates/index.html diff --git a/templates/results.html b/app/templates/results.html similarity index 100% rename from templates/results.html rename to app/templates/results.html diff --git a/templates/vote.html b/app/templates/vote.html similarity index 100% rename from templates/vote.html rename to app/templates/vote.html diff --git a/dev.yaml b/dev.yaml new file mode 100644 index 0000000..7c5d837 --- /dev/null +++ b/dev.yaml @@ -0,0 +1,36 @@ +version: '3.8' + +services: + # Flask app + app: + build: ./app/ + ports: + - 127.0.0.1:5000:5000 + volumes: + - type: bind # For development, we pass through the existing files for ez reload + source: app/ + target: /app/ + depends_on: + - db + environment: + - FLASK_HOST=0.0.0.0 + + # Postgres DB + db: + image: postgres + volumes: + - dev_db_data:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=dev + expose: + - 5432 # visible to other containers only + + # Admin panel for Postgres DB - DEVELOPMENT ONLY + # Use login credentials postgres/dev + adminer: + image: adminer + ports: + - 127.0.0.1:5001:8080 + +volumes: + dev_db_data: