Files
dotfiles/test/Dockerfile
T
2026-09-05 21:40:41 +02:00

78 lines
2.6 KiB
Docker

# test/Dockerfile
#
# Docker test harness for the dotfiles repo.
#
# Two stages:
# --target dev : fast shellcheck/lint environment (no heavy installs)
# --target test : smoke-test environment that can run the install scripts
#
# Build with (repo root as context; .dockerignore trims heavy/binary dirs):
# docker build --target test -t dotfiles-test -f test/Dockerfile .
# Run with:
# docker run --rm -v "$PWD":/dotfiles dotfiles-test
#
# Or simply use the Makefile targets:
# make test-lint-docker # build dev stage, run shellcheck+lint
# make test-smoke # dry probes; add RUN_SMOKE=1 for real installs
#
# See README.md ("Testing") and test/entrypoint-test.sh for details.
FROM archlinux:latest AS base
# Non-root test user that mirrors the workstation account.
ARG UID_ARG=1000
ARG USERNAME=mathias
RUN pacman -Syu --noconfirm \
base-devel \
git \
stow \
curl \
which \
sudo \
&& pacman -Scc --noconfirm
RUN useradd -m -u "$UID_ARG" -s /bin/bash -G wheel "$USERNAME"
# Passwordless sudo so scripts that call `sudo pacman`, `sudo systemctl`, etc.
# do not hang on a password prompt inside the container.
RUN printf '%%wheel ALL=(ALL) NOPASSWD: ALL\n' > /etc/sudoers.d/wheel-nopasswd \
&& chmod 440 /etc/sudoers.d/wheel-nopasswd
# Use a literal (not the ARG) for USER/ENV: the legacy builder can silently
# ignore a `USER "$ARG"` when the variable resolves after a stage boundary,
# leaving the container running as root (which breaks git ownership checks on
# the mounted host-owned repo). The value is fixed at mathias by default anyway.
USER mathias
ENV HOME="/home/mathias"
WORKDIR /dotfiles
# ---------------------------------------------------------------------------
# dev stage: shellcheck/lint only. Fast, no install heavy-lifting.
# ---------------------------------------------------------------------------
FROM base AS dev
USER root
RUN pacman -S --noconfirm --needed shellcheck
USER mathias
WORKDIR /dotfiles
COPY --chown=mathias . /dotfiles
CMD ["bash", "test/lint.sh"]
# ---------------------------------------------------------------------------
# test stage: prepared to actually run the install scripts & probe stow.
# Uses the mounted repo (see -v $PWD:/dotfiles in the Makefile) so scripts
# see the live workspace checkout.
# ---------------------------------------------------------------------------
FROM base AS test
USER mathias
WORKDIR /dotfiles
# The entrypoint drives the smoke tests. The repo is mounted at /dotfiles
# via the Makefile's `docker run -v`.
ENTRYPOINT ["bash", "/dotfiles/test/entrypoint-test.sh"]