|
1 | 1 | # syntax=docker/dockerfile:1
|
2 |
| -ARG PYTHON_VERSION=3.10 |
3 |
| -FROM python:$PYTHON_VERSION-slim AS base |
| 2 | +FROM ghcr.io/astral-sh/uv:python3.10-bookworm AS dev |
4 | 3 |
|
5 |
| -# Remove docker-clean so we can keep the apt cache in Docker build cache. |
6 |
| -RUN rm /etc/apt/apt.conf.d/docker-clean |
| 4 | +# Create and activate a virtual environment [1]. |
| 5 | +# [1] https://docs.astral.sh/uv/concepts/projects/config/#project-environment-path |
| 6 | +ENV VIRTUAL_ENV=/opt/venv |
| 7 | +ENV PATH=$VIRTUAL_ENV/bin:$PATH |
| 8 | +ENV UV_PROJECT_ENVIRONMENT=$VIRTUAL_ENV |
7 | 9 |
|
8 |
| -# Configure Python to print tracebacks on crash [1], and to not buffer stdout and stderr [2]. |
9 |
| -# [1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONFAULTHANDLER |
10 |
| -# [2] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED |
11 |
| -ENV PYTHONFAULTHANDLER 1 |
12 |
| -ENV PYTHONUNBUFFERED 1 |
| 10 | +# Tell Git that the workspace is safe to avoid 'detected dubious ownership in repository' warnings. |
| 11 | +RUN git config --system --add safe.directory '*' |
13 | 12 |
|
14 |
| -# Create a non-root user and switch to it [1]. |
| 13 | +# Create a non-root user and give it passwordless sudo access [1]. |
15 | 14 | # [1] https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
|
16 |
| -ARG UID=1000 |
17 |
| -ARG GID=$UID |
18 |
| -RUN groupadd --gid $GID user && \ |
19 |
| - useradd --create-home --gid $GID --uid $UID user --no-log-init && \ |
20 |
| - chown user /opt/ |
21 |
| -USER user |
22 |
| - |
23 |
| -# Create and activate a virtual environment. |
24 |
| -ENV VIRTUAL_ENV /opt/wtpsplit-lite-env |
25 |
| -ENV PATH $VIRTUAL_ENV/bin:$PATH |
26 |
| -RUN python -m venv $VIRTUAL_ENV |
27 |
| - |
28 |
| -# Set the working directory. |
29 |
| -WORKDIR /workspaces/wtpsplit-lite/ |
30 |
| - |
31 |
| - |
32 |
| - |
33 |
| -FROM base AS poetry |
34 |
| - |
35 |
| -USER root |
36 |
| - |
37 |
| -# Install Poetry in separate venv so it doesn't pollute the main venv. |
38 |
| -ENV POETRY_VERSION 1.8.0 |
39 |
| -ENV POETRY_VIRTUAL_ENV /opt/poetry-env |
40 |
| -RUN --mount=type=cache,target=/root/.cache/pip/ \ |
41 |
| - python -m venv $POETRY_VIRTUAL_ENV && \ |
42 |
| - $POETRY_VIRTUAL_ENV/bin/pip install poetry~=$POETRY_VERSION && \ |
43 |
| - ln -s $POETRY_VIRTUAL_ENV/bin/poetry /usr/local/bin/poetry |
44 |
| - |
45 |
| -# Install compilers that may be required for certain packages or platforms. |
46 |
| -RUN --mount=type=cache,target=/var/cache/apt/ \ |
47 |
| - --mount=type=cache,target=/var/lib/apt/ \ |
48 |
| - apt-get update && \ |
49 |
| - apt-get install --no-install-recommends --yes build-essential |
50 |
| - |
51 |
| -USER user |
52 |
| - |
53 |
| -# Install the run time Python dependencies in the virtual environment. |
54 |
| -COPY --chown=user:user poetry.lock* pyproject.toml /workspaces/wtpsplit-lite/ |
55 |
| -RUN mkdir -p /home/user/.cache/pypoetry/ && mkdir -p /home/user/.config/pypoetry/ && \ |
56 |
| - mkdir -p src/wtpsplit_lite/ && touch src/wtpsplit_lite/__init__.py && touch README.md |
57 |
| -RUN --mount=type=cache,uid=$UID,gid=$GID,target=/home/user/.cache/pypoetry/ \ |
58 |
| - poetry install --only main --all-extras --no-interaction |
59 |
| - |
60 |
| - |
61 |
| - |
62 |
| -FROM poetry AS dev |
63 |
| - |
64 |
| -# Install development tools: curl, git, gpg, ssh, starship, sudo, vim, and zsh. |
65 |
| -USER root |
66 | 15 | RUN --mount=type=cache,target=/var/cache/apt/ \
|
67 | 16 | --mount=type=cache,target=/var/lib/apt/ \
|
68 |
| - apt-get update && \ |
69 |
| - apt-get install --no-install-recommends --yes curl git gnupg ssh sudo vim zsh && \ |
70 |
| - sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- "--yes" && \ |
71 |
| - usermod --shell /usr/bin/zsh user && \ |
| 17 | + groupadd --gid 1000 user && \ |
| 18 | + useradd --create-home --no-log-init --gid 1000 --uid 1000 --shell /usr/bin/bash user && \ |
| 19 | + chown user:user /opt/ && \ |
| 20 | + apt-get update && apt-get install --no-install-recommends --yes sudo && \ |
72 | 21 | echo 'user ALL=(root) NOPASSWD:ALL' > /etc/sudoers.d/user && chmod 0440 /etc/sudoers.d/user
|
73 |
| -RUN git config --system --add safe.directory '*' |
74 | 22 | USER user
|
75 | 23 |
|
76 |
| -# Install the development Python dependencies in the virtual environment. |
77 |
| -RUN --mount=type=cache,uid=$UID,gid=$GID,target=/home/user/.cache/pypoetry/ \ |
78 |
| - poetry install --all-extras --no-interaction |
79 |
| - |
80 |
| -# Persist output generated during docker build so that we can restore it in the dev container. |
81 |
| -COPY --chown=user:user .pre-commit-config.yaml /workspaces/wtpsplit-lite/ |
82 |
| -RUN mkdir -p /opt/build/poetry/ && cp poetry.lock /opt/build/poetry/ && \ |
83 |
| - git init && pre-commit install --install-hooks && \ |
84 |
| - mkdir -p /opt/build/git/ && cp .git/hooks/commit-msg .git/hooks/pre-commit /opt/build/git/ |
85 |
| - |
86 | 24 | # Configure the non-root user's shell.
|
87 |
| -ENV ANTIDOTE_VERSION 1.8.6 |
88 |
| -RUN git clone --branch v$ANTIDOTE_VERSION --depth=1 https://github.com/mattmc3/antidote.git ~/.antidote/ && \ |
89 |
| - echo 'zsh-users/zsh-syntax-highlighting' >> ~/.zsh_plugins.txt && \ |
90 |
| - echo 'zsh-users/zsh-autosuggestions' >> ~/.zsh_plugins.txt && \ |
91 |
| - echo 'source ~/.antidote/antidote.zsh' >> ~/.zshrc && \ |
92 |
| - echo 'antidote load' >> ~/.zshrc && \ |
93 |
| - echo 'eval "$(starship init zsh)"' >> ~/.zshrc && \ |
94 |
| - echo 'HISTFILE=~/.history/.zsh_history' >> ~/.zshrc && \ |
95 |
| - echo 'HISTSIZE=1000' >> ~/.zshrc && \ |
96 |
| - echo 'SAVEHIST=1000' >> ~/.zshrc && \ |
97 |
| - echo 'setopt share_history' >> ~/.zshrc && \ |
98 |
| - echo 'bindkey "^[[A" history-beginning-search-backward' >> ~/.zshrc && \ |
99 |
| - echo 'bindkey "^[[B" history-beginning-search-forward' >> ~/.zshrc && \ |
100 |
| - mkdir ~/.history/ && \ |
101 |
| - zsh -c 'source ~/.zshrc' |
| 25 | +RUN mkdir ~/.history/ && \ |
| 26 | + echo 'HISTFILE=~/.history/.bash_history' >> ~/.bashrc && \ |
| 27 | + echo 'bind "\"\e[A\": history-search-backward"' >> ~/.bashrc && \ |
| 28 | + echo 'bind "\"\e[B\": history-search-forward"' >> ~/.bashrc && \ |
| 29 | + echo 'eval "$(starship init bash)"' >> ~/.bashrc |
0 commit comments