From fb57ae23424e744605496a8bf1d6c19e7b160080 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Fri, 3 Nov 2023 14:46:25 +0100 Subject: [PATCH] add an entrypoint for running the db migrations in runtime --- Dockerfile | 19 ++++++------------- entrypoint.sh | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 07825fab..36e5af27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,22 +17,15 @@ RUN pip install \ # NOTE: a real config must be mounted at /etc/gso/config.json when running the container RUN mkdir -p /etc/gso && \ chown -R appuser:appgroup /etc/gso -COPY --chown=appuser:appgroup gso/oss-params-example.json /etc/gso/config.json - -# Expose port 8080 for the FastAPI application -EXPOSE 8080 +COPY --chown=appuser:appgroup gso/oss-params-example.json /app/config.json # The app reads the configuration from this location. # No need to set environment variables in your docker-compose. -ENV OSS_PARAMS_FILENAME=/etc/gso/config.json +ENV OSS_PARAMS_FILENAME=/app/config.json # Set the environment variable for the translations directory 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 ["python", "-m", "uvicorn", "gso.main:app", "--host", "0.0.0.0", "--port", "8080"] +COPY --chown=appuser:appgroup --chmod=755 entrypoint.sh /app/entrypoint.sh + +EXPOSE 8080 +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..471f51da --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Run database migrations +cd gso || exit 1 +mv migrations migrations_temp && \ + PYTHONPATH=.. python main.py db init && \ + rm -rf migrations && \ + mv migrations_temp migrations + +PYTHONPATH=.. python main.py db upgrade heads + +# Start the FastAPI application +cd .. +python -m uvicorn "gso.main:app" --host "0.0.0.0" --port 8080 -- GitLab