Skip to content

Commit

Permalink
Cleanup dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Jan 1, 2025
1 parent 0f0842a commit 107b6ad
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 59 deletions.
10 changes: 4 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@ USER root
# - postgresql-common for the apt.postgresql.org.sh script
# - postgresql-client-17 for a current version of psql
RUN sudo apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y --no-install-recommends \
bash-completion \
gettext \
postgresql-common \
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
&& apt-get install -y --no-install-recommends \
postgresql-client-17 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

USER vscode

# pipx is already installed in the base devcontainers Python image
RUN pipx install invoke && \
invoke --print-completion-script=bash >> ~/.bash_completion
RUN pipx install invoke \
&& invoke --print-completion-script=bash >> ~/.bash_completion

RUN pipx install poetry && \
poetry completions bash >> ~/.bash_completion
RUN pipx install poetry \
&& poetry completions bash >> ~/.bash_completion
50 changes: 32 additions & 18 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
FROM gitpod/workspace-python-3.12

USER root

# Install system dependencies
# - bash-completion for shell completions of invoke
# - gettext for Django translations
# - postgresql-common for the apt.postgresql.org.sh script
# - postgresql-client-17 for a current version of psql
RUN sudo apt-get update \
&& apt-get install -y --no-install-recommends \
bash-completion \
gettext \
postgresql-common \
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
&& apt-get install -y --no-install-recommends \
postgresql-client-17 \
&& rm -rf /var/lib/apt/lists/*

USER gitpod

ENV NVM_DIR $HOME/.nvm
ENV NVM_VERSION 0.39.7
ENV NODE_VERSION 20.12.2
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

# Node is not available in in the Gitpod Python image, so we install is manually
RUN mkdir $NVM_DIR && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$NVM_VERSION/install.sh | bash && \
. $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default

RUN python3 -m pip install --user pipx && \
python3 -m pipx ensurepath

RUN python3 -m pipx install invoke && \
invoke --print-completion-script=bash >> $HOME/.bash_completion
# Node is not available in in the Gitpod Python image, so we install it
RUN mkdir $NVM_DIR \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$NVM_VERSION/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

RUN python3 -m pipx install playwright && playwright install --with-deps chromium
RUN python3 -m pip install --user pipx \
&& python3 -m pipx ensurepath

ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
RUN python3 -m pipx install invoke \
&& invoke --print-completion-script=bash >> $HOME/.bash_completion

# Poetry is already installed in the base Gitpod Python image,
# but we make sure uses the latest version and make bash completions available
RUN poetry self update && \
poetry completions bash >> ~/.bash_completion
RUN poetry self update \
&& poetry completions bash >> ~/.bash_completion
74 changes: 39 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,56 @@ FROM python:3.12-bullseye AS python-base
# python
# ENV variables are also available in the later build stages
ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# poetry
# https://python-poetry.org/docs/#installing-with-the-official-installer
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.8.3 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
# it gets named `.venv`
POETRY_VIRTUALENVS_IN_PROJECT=true \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv" \
# needed for adit-radis-shared to be found
PYTHONPATH="/app"
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# poetry
# https://python-poetry.org/docs/#installing-with-the-official-installer
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.8.3 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
# it gets named `.venv`
POETRY_VIRTUALENVS_IN_PROJECT=true \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv" \
# needed for adit-radis-shared to be found
PYTHONPATH="/app"

# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"

# deps for db management commands
# make sure to match the postgres version to the service in the compose file
RUN apt-get update \
&& apt-get install --no-install-recommends -y postgresql-common \
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
&& apt-get install --no-install-recommends -y \
postgresql-client-17
&& apt-get install --no-install-recommends -y postgresql-common \
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
&& apt-get install --no-install-recommends -y \
postgresql-client-17 \
&& rm -rf /var/lib/apt/lists/*


# `builder-base` stage is used to build deps + create our virtual environment
FROM python-base AS builder-base

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
curl \
# deps for building python deps
build-essential
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
curl \
# deps for building python deps
build-essential \
&& rm -rf /var/lib/apt/lists/*

# install poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://install.python-poetry.org | python3 -
Expand All @@ -64,6 +67,7 @@ RUN poetry install --without dev

# `development` image is used during development / testing
FROM python-base AS development

WORKDIR $PYSETUP_PATH

# copy in our built poetry + venv
Expand Down

0 comments on commit 107b6ad

Please sign in to comment.