diff --git a/Dockerfile b/Dockerfile index c6f604d..ecbfdef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,13 +4,11 @@ COPY poetry.lock pyproject.toml /code/ RUN apk add --no-cache build-base libffi-dev curl netcat-openbsd ENV POETRY_NO_INTERACTION=1 \ - POETRY_VIRTUALENVS_IN_PROJECT=1 \ - POETRY_VIRTUALENVS_CREATE=1 \ + POETRY_VIRTUALENVS_CREATE=false \ POETRY_HOME=/usr/local \ POETRY_VERSION=1.7.1 -RUN curl -sSL https://install.python-poetry.org | python3 - - -RUN poetry install --no-interaction --no-ansi --only main +RUN curl -sSL https://install.python-poetry.org | python3 - && \ + poetry install --no-interaction --no-ansi --only main # - - - - - - - - - - - - - - - - - - - - # @@ -18,13 +16,16 @@ FROM python:3.10.6-alpine WORKDIR /code COPY --from=builder /code /code +COPY --from=builder /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/ +COPY --from=builder /usr/local/bin/ /usr/local/bin/ COPY ./src /code/src COPY ./alembic.ini /code/alembic.ini COPY ./alembic /code/alembic -COPY ./docker_start.sh /code/docker_start.sh +COPY entrypoint.sh /code/entrypoint.sh -RUN addgroup --gid 1000 pyweb -RUN adduser pyweb -h /code -u 1000 -G pyweb -DH +RUN chmod +x /code/entrypoint.sh && \ + addgroup --gid 1000 pyweb && \ + adduser pyweb -h /code -u 1000 -G pyweb -DH USER 1000 -CMD ["/bin/sh", "/code/docker_start.sh"] +ENTRYPOINT ["/code/entrypoint.sh"] diff --git a/docker_start.sh b/docker_start.sh deleted file mode 100644 index 724cbec..0000000 --- a/docker_start.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# Run migrations -/code/.venv/bin/alembic upgrade head - -# Start the application -if [ "$RELOAD" = "true" ] -then - /code/.venv/bin/uvicorn src.main:app --host 0.0.0.0 --port 80 --reload -else - /code/.venv/bin/uvicorn src.main:app --host 0.0.0.0 --port 80 -fi diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..a078bfe --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +echo "Waiting for PostgreSQL..." +while ! nc -z db 5432; do + sleep 0.1 +done +echo "PostgreSQL started" + +echo "Running migrations..." +alembic upgrade head +echo "Migrations done" + +if [ "$RELOAD" = "true" ] +then +uvicorn src.main:app --host 0.0.0.0 --port 80 --reload +else +uvicorn src.main:app --host 0.0.0.0 --port 80 +fi + +exec "$@" \ No newline at end of file