diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..fdd3ba35 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.idea +.git +.mypy_cache +.pytest_cache +.venv +.env +.coverage +.eslintcache +docker-compose-dev.yml +Makefile.custom.config +*.log \ No newline at end of file diff --git a/.env.docker b/.env.docker new file mode 100644 index 00000000..ddb2981d --- /dev/null +++ b/.env.docker @@ -0,0 +1,28 @@ +# Custom variables initialisation + +# Application +export FLASK_APP=fittrackee/__main__.py +# export HOST= +# export PORT= +export APP_SETTINGS=fittrackee.config.DevelopmentConfig +export APP_SECRET_KEY='just for test' +# export APP_WORKERS= +export APP_LOG=fittrackee.log +export UPLOAD_FOLDER=/usr/src/app/uploads + +# Database +export DATABASE_URL=postgres://fittrackee:fittrackee@fittrackee-db:5432/fittrackee +export DATABASE_TEST_URL=postgres://fittrackee:fittrackee@fittrackee-db:5432/fittrackee_test +export DATABASE_DISABLE_POOLING= + +# Emails +export UI_URL=http://0.0.0.0:5000 +export EMAIL_URL=smtp://none:none@mail:1025 +export SENDER_EMAIL=fittrackee@example.com +export REDIS_URL=redis://redis:6379 +export WORKERS_PROCESSES=2 + +# Activities +#export TILE_SERVER_URL= +#export MAP_ATTRIBUTION= +#export WEATHER_API_KEY= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..07d39c8a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.9 + +MAINTAINER SamR1@users.noreply.github.com + +# set working directory +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +# copy source files +COPY . /usr/src/app + +# install requirements +RUN pip install --upgrade pip +RUN pip install poetry +RUN poetry config virtualenvs.create false +RUN poetry install --no-interaction --quiet + +# create uploads folder +CMD mkdir /usr/src/app/uploads + +# run fittrackee server +CMD flask run --with-threads -h 0.0.0.0 \ No newline at end of file diff --git a/Makefile b/Makefile index c6c31f8c..fb29af4b 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,41 @@ clean-install: clean rm -rf *.egg-info rm -rf dist/ +## Docker commands for evaluation purposes +docker-build: + docker-compose -f docker-compose-dev.yml build + +docker-init: docker-init-db docker-restart docker-run-workers + +docker-init-db: + docker-compose -f docker-compose-dev.yml exec fittrackee docker/init-database.sh + +docker-logs: + docker-compose -f docker-compose-dev.yml logs --follow + +docker-rebuild: + docker-compose -f docker-compose-dev.yml build --no-cache + +docker-restart: + docker-compose -f docker-compose-dev.yml restart fittrackee + +docker-run-all: docker-run docker-run-workers + +docker-run: + docker-compose -f docker-compose-dev.yml up -d + +docker-run-workers: + docker-compose -f docker-compose-dev.yml exec -d fittrackee docker/run-workers.sh + +docker-shell: + docker-compose -f docker-compose-dev.yml exec fittrackee docker/shell.sh + +docker-stop: + docker-compose -f docker-compose-dev.yml stop + +docker-up: + docker-compose -f docker-compose-dev.yml up + downgrade-db: $(FLASK) db downgrade --directory $(MIGRATIONS) diff --git a/db/Dockerfile b/db/Dockerfile new file mode 100644 index 00000000..85a74ffb --- /dev/null +++ b/db/Dockerfile @@ -0,0 +1,5 @@ +FROM postgres:13 + +MAINTAINER SamR1@users.noreply.github.com + +COPY create.sql /docker-entrypoint-initdb.d \ No newline at end of file diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 00000000..44a807c5 --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,43 @@ +version: '3.8' + +services: + + fittrackee-db: + container_name: fittrackee-db + build: ./db + ports: + - 5435:5432 + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + + fittrackee: + container_name: fittrackee + build: . + ports: + - 5000:5000 + env_file: + - .env.docker + depends_on: + - fittrackee-db + - redis + - mail + links: + - fittrackee-db + - redis + - mail + + redis: + container_name: fittrackee-redis + image: "redis:latest" + hostname: redis + ports: + - 6379:6379 + + mail: + container_name: fittrackee-mailhog + image: "mailhog/mailhog" + ports: + - 1025:1025 + - 8025:8025 + diff --git a/docker/init-database.sh b/docker/init-database.sh new file mode 100755 index 00000000..ece8cc19 --- /dev/null +++ b/docker/init-database.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +cd /usr/src/app + +source .env.docker + +flask drop-db +flask db upgrade --directory fittrackee/migrations +flask init-data \ No newline at end of file diff --git a/docker/run-workers.sh b/docker/run-workers.sh new file mode 100755 index 00000000..c7937a1c --- /dev/null +++ b/docker/run-workers.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +cd /usr/src/app + +source .env.docker + +flask worker --processes=$WORKERS_PROCESSES >> dramatiq.log 2>&1 diff --git a/docker/shell.sh b/docker/shell.sh new file mode 100755 index 00000000..241fa823 --- /dev/null +++ b/docker/shell.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +cd /usr/src/app + +source .env.docker + +/bin/bash \ No newline at end of file