From 63246390640c872d05197ac68561731bd6e3f576 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 21 Jun 2023 17:20:27 +0200 Subject: [PATCH] Docker - install fittrackee in a virtual env --- Dockerfile | 9 ++++----- Makefile | 12 ++++++------ Makefile.config | 4 ---- docker-compose-dev.yml | 1 - docker/lint-python.sh | 4 +++- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 17fb5e683..ac910520c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,13 +8,12 @@ WORKDIR /usr/src/app COPY . /usr/src/app # install requirements +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" 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 . $VIRTUAL_ENV/bin/activate && poetry install --no-interaction --quiet # 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 b283bdda7..84e6710a3 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ clean-install: clean ## Docker commands for evaluation purposes docker-bandit: - docker-compose -f docker-compose-dev.yml exec fittrackee $(DOCKER_BANDIT) -r fittrackee -c pyproject.toml + docker-compose -f docker-compose-dev.yml exec fittrackee bandit -r fittrackee -c pyproject.toml docker-build: docker-compose -f docker-compose-dev.yml build fittrackee @@ -56,7 +56,7 @@ docker-build-client: docker-check-all: docker-bandit docker-lint-all docker-type-check docker-test-client docker-test-python docker-downgrade-db: - docker-compose -f docker-compose-dev.yml exec fittrackee $(DOCKER_FLASK) db downgrade --directory $(DOCKER_MIGRATIONS) + docker-compose -f docker-compose-dev.yml exec fittrackee flask db downgrade --directory $(DOCKER_MIGRATIONS) docker-init: docker-run docker-init-db docker-restart docker-run-workers @@ -76,7 +76,7 @@ docker-logs: docker-compose -f docker-compose-dev.yml logs --follow docker-migrate-db: - docker-compose -f docker-compose-dev.yml exec fittrackee $(DOCKER_FLASK) db migrate --directory $(DOCKER_MIGRATIONS) + docker-compose -f docker-compose-dev.yml exec fittrackee flask db migrate --directory $(DOCKER_MIGRATIONS) docker-rebuild: docker-compose -f docker-compose-dev.yml build --no-cache @@ -86,7 +86,7 @@ docker-restart: docker-compose -f docker-compose-dev.yml exec -d fittrackee docker/run-workers.sh docker-revision: - docker-compose -f docker-compose-dev.yml exec fittrackee $(DOCKER_FLASK) db revision --directory $(DOCKER_MIGRATIONS) --message $(MIGRATION_MESSAGE) + docker-compose -f docker-compose-dev.yml exec fittrackee flask db revision --directory $(DOCKER_MIGRATIONS) --message $(MIGRATION_MESSAGE) docker-run-all: docker-run docker-run-workers @@ -123,13 +123,13 @@ docker-test-python: docker-run docker-type-check: echo 'Running mypy in docker...' - docker-compose -f docker-compose-dev.yml exec fittrackee $(DOCKER_MYPY) fittrackee + docker-compose -f docker-compose-dev.yml exec fittrackee mypy fittrackee docker-up: docker-compose -f docker-compose-dev.yml up fittrackee docker-upgrade-db: - docker-compose -f docker-compose-dev.yml exec fittrackee $(DOCKER_FTCLI) db upgrade + docker-compose -f docker-compose-dev.yml exec fittrackee ftcli db upgrade downgrade-db: $(FLASK) db downgrade --directory $(MIGRATIONS) diff --git a/Makefile.config b/Makefile.config index 557517985..ab903dece 100644 --- a/Makefile.config +++ b/Makefile.config @@ -31,10 +31,6 @@ FTCLI = $(VENV)/bin/ftcli # Docker env export DOCKER_APP_DIR = /usr/src/app export DOCKER_MIGRATIONS = $(DOCKER_APP_DIR)/fittrackee/migrations -export DOCKER_FLASK = /usr/local/bin/flask -export DOCKER_FTCLI = /usr/local/bin/ftcli -export DOCKER_BANDIT = /usr/local/bin/bandit -export DOCKER_MYPY = /usr/local/bin/mypy # Node env NODE_MODULES = $(PWD)/fittrackee_client/node_modules diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 4eed8d1c2..ecca78ecb 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -28,7 +28,6 @@ services: - mail volumes: - .:/usr/src/app - - ./data/workouts:/usr/src/app/workouts - ./data/uploads:/usr/src/app/uploads networks: - fittrackee-net diff --git a/docker/lint-python.sh b/docker/lint-python.sh index b2425d539..486a4178c 100755 --- a/docker/lint-python.sh +++ b/docker/lint-python.sh @@ -5,4 +5,6 @@ cd /usr/src/app source .env mypy fittrackee -pytest --flake8 --isort --black -m "flake8 or isort or black" fittrackee e2e --ignore=fittrackee/migrations \ No newline at end of file +pytest --isort --black -m "isort or black" fittrackee e2e --ignore=fittrackee/migrations +echo 'Running flake8...' +flake8 fittrackee e2e \ No newline at end of file