-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bc975f
commit 9213c0a
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Ignore everything | ||
* | ||
|
||
# Except code | ||
!/src/ | ||
!/deploy/docker-entrypoint.sh | ||
!/pyproject.toml | ||
!/poetry.lock | ||
|
||
# And ignore cache files in the code | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Based on https://github.com/svx/poetry-fastapi-docker/blob/main/Dockerfile | ||
|
||
########################################################### | ||
# Base Python image. Set shared environment variables. | ||
FROM python:3.11-slim-bullseye AS base | ||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PIP_NO_CACHE_DIR=off \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
POETRY_HOME="/opt/poetry" \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=true \ | ||
POETRY_NO_INTERACTION=1 \ | ||
POETRY_INSTALLER_MAX_WORKERS=10 \ | ||
PYSETUP_PATH="/opt/pysetup" \ | ||
VENV_PATH="/opt/pysetup/.venv" | ||
|
||
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" | ||
|
||
|
||
########################################################### | ||
# Builder stage. Build dependencies. | ||
FROM base AS builder | ||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
curl \ | ||
vim \ | ||
netcat \ | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Poetry. Respects $POETRY_VERSION and $POETRY_HOME | ||
ENV POETRY_VERSION=1.7.1 | ||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=${POETRY_HOME} python3 - --version ${POETRY_VERSION} && \ | ||
chmod a+x /opt/poetry/bin/poetry | ||
|
||
# We copy our Python requirements here to cache them | ||
# and install only runtime deps using poetry | ||
WORKDIR $PYSETUP_PATH | ||
COPY ./poetry.lock ./pyproject.toml ./ | ||
RUN poetry install --only main,prod | ||
|
||
|
||
########################################################### | ||
# Production stage. Copy only runtime deps that were installed in the Builder stage. | ||
FROM base AS production | ||
|
||
COPY --from=builder $VENV_PATH $VENV_PATH | ||
|
||
COPY ./deploy/docker-entrypoint.sh /docker-entrypoint.sh | ||
RUN chmod +x /docker-entrypoint.sh | ||
|
||
# Create user with the name poetry | ||
RUN groupadd -g 1500 poetry && \ | ||
useradd -m -u 1500 -g poetry poetry | ||
|
||
COPY --chown=poetry:poetry . /code | ||
USER poetry | ||
WORKDIR /code | ||
|
||
EXPOSE 8000 | ||
ENTRYPOINT /docker-entrypoint.sh $0 $@ | ||
CMD [ "gunicorn", "--worker-class uvicorn.workers.UvicornWorker", "--bind 0.0.0.0:8000", "--workers 1", "src.api.app:app" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# activate our virtual environment here | ||
. /opt/pysetup/.venv/bin/activate | ||
|
||
# You can put other setup logic here | ||
alembic upgrade head | ||
|
||
# Evaluating passed command: | ||
exec "$@" |