Skip to content

Commit

Permalink
Add docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
yakimka committed Apr 24, 2024
1 parent 7fc39d6 commit 6a7e627
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# https://github.com/python-poetry/poetry/discussions/1879#discussioncomment-216865
# `python-base` sets up all our shared environment variables
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim-bullseye as python-base

ENV PYTHONUNBUFFERED=1 \
PYTHONDEVMODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.5.1 \
VENV_PATH="/opt/venv" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
CODE_PATH="/opt/code"

ENV XDG_CACHE_HOME="$CODE_PATH/.cache" \
XDG_CONFIG_HOME="/tmp/.config"


ENV PATH="$VENV_PATH/bin:$CODE_PATH/.venv/bin:$PATH"
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG USER_NAME=app

RUN addgroup --gid $GROUP_ID --system $USER_NAME \
&& adduser --uid $USER_ID --system --no-create-home --shell=/bin/false --disabled-password --group $USER_NAME \
&& mkdir $CODE_PATH \
&& chown -R $USER_ID:$GROUP_ID $CODE_PATH

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
make \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# For pre-commit
# TODO PRE_COMMIT_HOME
RUN mkdir -p $XDG_CONFIG_HOME/git \
&& touch $XDG_CONFIG_HOME/git/config \
&& chown -R $USER_ID:$GROUP_ID $XDG_CONFIG_HOME \
&& git config --global safe.directory $CODE_PATH


FROM python-base as builder-base
RUN set -ex \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for building python deps
build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN python -m venv $VENV_PATH
RUN pip install poetry==$POETRY_VERSION


# `development` image is used during development / testing
FROM python-base as development
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR $CODE_PATH

COPY --from=builder-base $VENV_PATH $VENV_PATH

USER $USER_NAME

CMD ["poetry", "install"]
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

x-common: &common
build:
target: development
context: .
dockerfile: Dockerfile-dev
args:
- PYTHON_VERSION=${PYTHON_VERSION:-3.11}
image: "picodi:dev"
volumes:
- .:/opt/code

services:
devtools:
<<: *common
command: sleep infinity

app:
<<: *common
restart: "no"
ports:
- "8000:8000"

0 comments on commit 6a7e627

Please sign in to comment.