-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
74 lines (57 loc) · 3.11 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.13.0
FROM python:$PYTHON_VERSION-slim AS base
LABEL org.opencontainers.image.description="A Python tool for API testing and development in your terminal."
# Configure Python to print tracebacks on crash [1], and to not buffer stdout and stderr [2].
# [1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONFAULTHANDLER
# [2] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED
ENV PYTHONFAULTHANDLER=1
ENV PYTHONUNBUFFERED=1
# Install Poetry.
ENV POETRY_VERSION=1.8.4
RUN --mount=type=cache,target=/root/.cache/pip/ \
pip install poetry==$POETRY_VERSION
# Install curl & compilers that may be required for certain packages or platforms.
# The stock ubuntu image cleans up /var/cache/apt automatically. This makes the build process slow.
# Enable apt caching by removing docker-clean
RUN rm /etc/apt/apt.conf.d/docker-clean
RUN --mount=type=cache,target=/var/cache/apt/ \
--mount=type=cache,target=/var/lib/apt/ \
apt-get update && apt-get install --no-install-recommends --yes curl build-essential
# Create and activate a virtual environment.
RUN python -m venv /opt/zapman-env
ENV PATH=/opt/zapman-env/bin:$PATH
ENV VIRTUAL_ENV=/opt/zapman-env
# Set the working directory.
WORKDIR /workspaces/zapman/
# Touch minimal files to allow Poetry to install dependencies.
RUN mkdir -p /root/.cache/pypoetry/ && mkdir -p /root/.config/pypoetry/ && \
mkdir -p src/zapman/ && touch src/zapman/__init__.py && touch README.md
FROM base AS dev
# Install DevContainer utilities: zsh, git, docker cli, starship prompt.
# Docker: only docker cli is installeed and not the entire engine.
RUN --mount=type=cache,target=/var/cache/apt/ \
--mount=type=cache,target=/var/lib/apt/ \
apt-get update && apt-get install --yes --no-install-recommends openssh-client git zsh gnupg && \
# Install docker cli (based on https://get.docker.com/)
install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL "https://download.docker.com/linux/debian/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg && \
chmod a+r /etc/apt/keyrings/docker.gpg && \
apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" && \
echo "$apt_repo" > /etc/apt/sources.list.d/docker.list && \
apt-get update && apt-get --yes --no-install-recommends install docker-ce-cli docker-compose-plugin && \
# Install starship prompt
sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- "--yes" && \
# Mark the workspace as safe for git
git config --system --add safe.directory '*'
# Install the run time Python dependencies in the virtual environment.
COPY poetry.lock* pyproject.toml /workspaces/zapman/
RUN --mount=type=cache,target=/root/.cache/pypoetry/ \
poetry install --no-interaction --no-ansi
# Install pre-commit hooks & activate starship.
COPY .pre-commit-config.yaml /workspaces/zapman/
RUN git init && pre-commit install --install-hooks && \
echo 'eval "$(starship init zsh)"' >> ~/.zshrc && \
echo 'poe --help' >> ~/.zshrc && \
zsh -c 'source ~/.zshrc'
CMD ["zsh"]