Skip to content

Commit

Permalink
chore: move to the alpine docker image version
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Maximenyuk committed Apr 8, 2024
1 parent 937b7c5 commit 7fc8d77
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions Dockerfile.jinja
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
FROM python:3.10-slim
FROM python:3.11.5-alpine

{% if from_ccsteam %}LABEL Maintainer="eXpress Unlimited Production"{% endif %}

ENV PYTHONUNBUFFERED 1
ENV UVICORN_CMD_ARGS ""

EXPOSE 8000

# Install system-wide dependencies
RUN apt-get update && \
apt-get install --no-install-recommends -y git curl gcc python3-dev && \
apt-get clean autoclean && \
apt-get autoremove --yes && \
rm -rf /var/lib/apt/lists/*
RUN apk update && \
apk add --no-cache --clean-protected git curl gcc python3-dev && \
rm -rf /var/cache/apk/*

# Create user for app
ENV APP_USER=appuser
RUN useradd --create-home $APP_USER
RUN adduser -D $APP_USER
WORKDIR /home/$APP_USER
USER $APP_USER

# Set python env vars
ENV PYTHONUNBUFFERED 1
ENV PYTHONNODEBUGRANGES 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONPATH="/home/$APP_USER:$PYTHONPATH"

# Use venv directly via PATH
ENV VENV_PATH=/home/$APP_USER/.venv/bin
ENV USER_PATH=/home/$APP_USER/.local/bin
ENV PATH="$VENV_PATH:$USER_PATH:$PATH"

RUN pip install --user --no-cache-dir poetry==1.4.0 && \
poetry config virtualenvs.in-project true
# Set app env vars
ENV GUNICORN_CMD_ARGS ""

# Set build env vars
ARG CI_COMMIT_SHA=""
ENV GIT_COMMIT_SHA=${CI_COMMIT_SHA}

RUN pip install --user --no-cache-dir poetry==1.4.2 && \
poetry config virtualenvs.in-project true

COPY poetry.lock pyproject.toml ./

Expand All @@ -37,17 +43,16 @@ ARG GIT_PASSWORD=${CI_JOB_TOKEN}
ARG GIT_LOGIN="gitlab-ci-token"
# Poetry can't read password to download private repos
RUN echo -e "machine ${GIT_HOST}\nlogin ${GIT_LOGIN}\npassword ${GIT_PASSWORD}" > ~/.netrc && \
poetry install --no-dev && \
rm -rf ~/.netrc
poetry install --only main && \
rm -rf ~/.netrc
{% else %}
RUN poetry install --no-dev
RUN poetry install --only main
{% endif %}

COPY alembic.ini .
COPY app app

ARG CI_COMMIT_SHA=""
ENV GIT_COMMIT_SHA=${CI_COMMIT_SHA}
EXPOSE 8000

CMD alembic upgrade head && \
uvicorn --host=0.0.0.0 $UVICORN_CMD_ARGS --factory app.main:get_application
gunicorn "app.main:get_application()" --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0 $GUNICORN_CMD_ARGS

0 comments on commit 7fc8d77

Please sign in to comment.