Skip to content

Commit c2f31f5

Browse files
committed
Cleanup dockerfiles
1 parent 84cc13d commit c2f31f5

File tree

3 files changed

+76
-56
lines changed

3 files changed

+76
-56
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@ USER root
88
# - postgresql-common for the apt.postgresql.org.sh script
99
# - postgresql-client-17 for a current version of psql
1010
RUN sudo apt-get update \
11-
&& export DEBIAN_FRONTEND=noninteractive \
1211
&& apt-get install -y --no-install-recommends \
1312
bash-completion \
1413
gettext \
1514
postgresql-common \
1615
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
1716
&& apt-get install -y --no-install-recommends \
1817
postgresql-client-17 \
19-
&& apt-get clean \
2018
&& rm -rf /var/lib/apt/lists/*
2119

2220
USER vscode
2321

2422
# pipx is already installed in the base devcontainers Python image
25-
RUN pipx install invoke && \
26-
invoke --print-completion-script=bash >> ~/.bash_completion && \
23+
RUN pipx install invoke \
24+
&& invoke --print-completion-script=bash >> ~/.bash_completion \
2725
pipx uninstall invoke
2826

29-
RUN pipx install poetry && \
30-
poetry completions bash >> ~/.bash_completion
27+
RUN pipx install poetry \
28+
&& poetry completions bash >> ~/.bash_completion

.gitpod.Dockerfile

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
FROM gitpod/workspace-python-3.12
22

3+
USER root
4+
5+
# Install system dependencies
6+
# - bash-completion for shell completions of invoke
7+
# - gettext for Django translations
8+
# - postgresql-common for the apt.postgresql.org.sh script
9+
# - postgresql-client-17 for a current version of psql
10+
RUN sudo apt-get update \
11+
&& apt-get install -y --no-install-recommends \
12+
bash-completion \
13+
gettext \
14+
postgresql-common \
15+
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
16+
&& apt-get install -y --no-install-recommends \
17+
postgresql-client-17 \
18+
&& rm -rf /var/lib/apt/lists/*
19+
320
USER gitpod
421

522
ENV NVM_DIR $HOME/.nvm
623
ENV NODE_VERSION 20.11.0
7-
8-
RUN mkdir $NVM_DIR && \
9-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash && \
10-
. $NVM_DIR/nvm.sh && \
11-
nvm install $NODE_VERSION && \
12-
nvm alias default $NODE_VERSION && \
13-
nvm use default
14-
15-
RUN python3 -m pip install --user pipx && \
16-
python3 -m pipx ensurepath && \
17-
python3 -m pipx install invoke && \
18-
invoke --print-completion-script=bash >> $HOME/.bash_completion && \
19-
pipx uninstall invoke
20-
2124
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
2225
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
2326

27+
# Node is not available in in the Gitpod Python image, so we install it
28+
RUN mkdir $NVM_DIR \
29+
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
30+
&& . $NVM_DIR/nvm.sh \
31+
&& nvm install $NODE_VERSION \
32+
&& nvm alias default $NODE_VERSION \
33+
&& nvm use default
34+
35+
RUN python3 -m pip install --user pipx \
36+
&& python3 -m pipx ensurepath \
37+
&& python3 -m pipx install invoke \
38+
&& invoke --print-completion-script=bash >> $HOME/.bash_completion \
39+
&& pipx uninstall invoke
40+
2441
# Poetry is already installed in the base Gitpod Python image,
2542
# but we need to upgrade it
26-
RUN poetry self update && \
27-
poetry completions bash >> ~/.bash_completion
43+
RUN poetry self update \
44+
&& poetry completions bash >> ~/.bash_completion

Dockerfile

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,56 @@ FROM python:3.12-bullseye AS python-base
33
# python
44
# ENV variables are also available in the later build stages
55
ENV PYTHONUNBUFFERED=1 \
6-
# prevents python creating .pyc files
7-
PYTHONDONTWRITEBYTECODE=1 \
8-
\
9-
# pip
10-
PIP_NO_CACHE_DIR=off \
11-
PIP_DISABLE_PIP_VERSION_CHECK=on \
12-
PIP_DEFAULT_TIMEOUT=100 \
13-
\
14-
# poetry
15-
# https://python-poetry.org/docs/#installing-with-the-official-installer
16-
# https://python-poetry.org/docs/configuration/#using-environment-variables
17-
POETRY_VERSION=1.8.3 \
18-
# make poetry install to this location
19-
POETRY_HOME="/opt/poetry" \
20-
# make poetry create the virtual environment in the project's root
21-
# it gets named `.venv`
22-
POETRY_VIRTUALENVS_IN_PROJECT=true \
23-
# do not ask any interactive question
24-
POETRY_NO_INTERACTION=1 \
25-
\
26-
# paths
27-
# this is where our requirements + virtual environment will live
28-
PYSETUP_PATH="/opt/pysetup" \
29-
VENV_PATH="/opt/pysetup/.venv"
6+
# prevents python creating .pyc files
7+
PYTHONDONTWRITEBYTECODE=1 \
8+
\
9+
# pip
10+
PIP_NO_CACHE_DIR=off \
11+
PIP_DISABLE_PIP_VERSION_CHECK=on \
12+
PIP_DEFAULT_TIMEOUT=100 \
13+
\
14+
# poetry
15+
# https://python-poetry.org/docs/#installing-with-the-official-installer
16+
# https://python-poetry.org/docs/configuration/#using-environment-variables
17+
POETRY_VERSION=1.8.3 \
18+
# make poetry install to this location
19+
POETRY_HOME="/opt/poetry" \
20+
# make poetry create the virtual environment in the project's root
21+
# it gets named `.venv`
22+
POETRY_VIRTUALENVS_IN_PROJECT=true \
23+
# do not ask any interactive question
24+
POETRY_NO_INTERACTION=1 \
25+
\
26+
# paths
27+
# this is where our requirements + virtual environment will live
28+
PYSETUP_PATH="/opt/pysetup" \
29+
VENV_PATH="/opt/pysetup/.venv"
3030

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

3434
# deps for db management commands and transferring to an archive
3535
# make sure to match the postgres version to the service in the compose file
3636
RUN apt-get update \
37-
&& apt-get install --no-install-recommends -y postgresql-common \
38-
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
39-
&& apt-get install --no-install-recommends -y \
40-
postgresql-client-17 \
41-
p7zip-full
37+
&& apt-get install --no-install-recommends -y \
38+
postgresql-common \
39+
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
40+
&& apt-get install --no-install-recommends -y \
41+
postgresql-client-17 \
42+
p7zip-full \
43+
&& rm -rf /var/lib/apt/lists/*
4244

4345

4446
# `builder-base` stage is used to build deps + create our virtual environment
4547
FROM python-base AS builder-base
48+
4649
RUN apt-get update \
47-
&& apt-get install --no-install-recommends -y \
48-
# deps for installing poetry
49-
curl \
50-
# deps for building python deps
51-
build-essential
50+
&& apt-get install --no-install-recommends -y \
51+
# deps for installing poetry
52+
curl \
53+
# deps for building python deps
54+
build-essential \
55+
&& rm -rf /var/lib/apt/lists/*
5256

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

6468
# `development` image is used during development / testing
6569
FROM python-base AS development
70+
6671
WORKDIR $PYSETUP_PATH
6772

6873
# copy in our built poetry + venv

0 commit comments

Comments
 (0)