test suite with docker container and linter

This commit is contained in:
2026-09-05 20:57:59 +02:00
parent d32a30f39e
commit aaecbd8472
9 changed files with 777 additions and 3 deletions
+73
View File
@@ -0,0 +1,73 @@
# 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
USER "$USERNAME"
ENV HOME="/home/$USERNAME"
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 "$USERNAME"
WORKDIR /dotfiles
COPY --chown="$USERNAME" . /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 "$USERNAME"
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"]