add docker for evaluation purposes

This commit is contained in:
Sam 2021-01-31 11:30:37 +01:00
parent ef7533d9f9
commit 4fb9d3ffd7
9 changed files with 167 additions and 0 deletions

11
.dockerignore Normal file
View File

@ -0,0 +1,11 @@
.idea
.git
.mypy_cache
.pytest_cache
.venv
.env
.coverage
.eslintcache
docker-compose-dev.yml
Makefile.custom.config
*.log

28
.env.docker Normal file
View File

@ -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=

22
Dockerfile Normal file
View File

@ -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

View File

@ -21,6 +21,41 @@ clean-install: clean
rm -rf *.egg-info rm -rf *.egg-info
rm -rf dist/ 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: downgrade-db:
$(FLASK) db downgrade --directory $(MIGRATIONS) $(FLASK) db downgrade --directory $(MIGRATIONS)

5
db/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM postgres:13
MAINTAINER SamR1@users.noreply.github.com
COPY create.sql /docker-entrypoint-initdb.d

43
docker-compose-dev.yml Normal file
View File

@ -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

9
docker/init-database.sh Executable file
View File

@ -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

7
docker/run-workers.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
cd /usr/src/app
source .env.docker
flask worker --processes=$WORKERS_PROCESSES >> dramatiq.log 2>&1

7
docker/shell.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
cd /usr/src/app
source .env.docker
/bin/bash