Skip to content

Commit

Permalink
fix: docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Maximenyuk committed Apr 5, 2024
1 parent 43e2595 commit b5907b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
44 changes: 24 additions & 20 deletions Dockerfile.jinja
Original file line number Diff line number Diff line change
@@ -1,33 +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 -m pip install setuptools && \
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.2.2 && \
poetry config virtualenvs.in-project true
# Set app env vars
ENV UVICORN_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 @@ -38,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 --only main && \
rm -rf ~/.netrc
poetry install --only main && \
rm -rf ~/.netrc
{% else %}
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 && \
gunicorn "app.main:get_application()" --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0
uvicorn --host=0.0.0.0 $UVICORN_CMD_ARGS --factory app.main:get_application
2 changes: 1 addition & 1 deletion docker-compose.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
build: .
container_name: {{bot_project_name}}-worker
# '$$' prevents docker-compose from interpolating a value
command: bash -c 'PYTHONPATH="$$PYTHONPATH:$$PWD" saq app.worker.worker.settings'
command: /bin/sh -c 'PYTHONPATH="$$PYTHONPATH:$$PWD" saq app.worker.worker.settings'
environment: *environment
restart: always
depends_on: *depends_on
Expand Down

0 comments on commit b5907b3

Please sign in to comment.