From dbf7063f81488794e0569889cc583ca9aaf92ae8 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Fri, 3 Nov 2023 12:38:26 +0100 Subject: [PATCH] update Dockerfile - move to alpine-based image for reduced size - apk add requirements - pip install to target dir in /app - add translations as environment variable - automatically install all required database migrations --- Dockerfile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index d00cbc51..234abb6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,16 @@ -FROM python:3.11 +FROM python:3.11-alpine ARG ARTIFACT_VERSION +RUN apk add gcc libc-dev libffi-dev RUN pip install \ --pre \ --extra-index-url https://artifactory.software.geant.org/artifactory/api/pypi/geant-swd-pypi/simple \ + --target /app \ geant-service-orchestrator==${ARTIFACT_VERSION} +WORKDIR /app + # Create the directory for the configuration and copy the example config into it # NOTE: a real config must be mounted at /etc/gso/config.json when running the container RUN mkdir -p /etc/gso @@ -19,7 +23,12 @@ EXPOSE 8080 # No need to set environment variables in your docker-compose. ENV OSS_PARAMS_FILENAME=/etc/gso/config.json # Set the environment variable for the translations directory -ENV TRANSLATIONS_DIR=$(python3 -c "from os import path; import gso; print(path.join(path.split(gso.__file__)[0], 'translations'))" | tail -n 1) +ENV TRANSLATIONS_DIR=/app/gso/translations/ +# Run database migrations +RUN mv gso/migrations gso/migrations_temp +RUN PYTHONPATH=. python gso/main.py db init +RUN rm -rf gso/migrations && mv gso/migrations_temp gso/migrations +RUN PYTHONPATH=. python gso/main.py db upgrade heads # Start the FastAPI application -CMD ["uvicorn", "gso.main:app", "--host", "0.0.0.0", "--port", "8080"] +CMD ["python", "-m", "uvicorn", "gso.main:app", "--host", "0.0.0.0", "--port", "8080"] -- GitLab