-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.test
More file actions
105 lines (98 loc) · 4.64 KB
/
Dockerfile.test
File metadata and controls
105 lines (98 loc) · 4.64 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# syntax=docker/dockerfile:1.4
# Dockerfile for running the full test suite (unit + BDD) with all dependencies.
# Mirrors the pdfbro production image: Chromium + LibreOffice (via LOK — no unoserver).
#
# Uses BuildKit cache mounts for the Cargo registry + target dir so incremental
# compilation works across builds. First build: ~10 min. Subsequent builds after
# a small source change: ~30-90 s.
#
# Usage:
# docker build -f Dockerfile.test --progress=plain .
#
# Tests run during the build step. Exit 0 = all tests passed.
ARG RUST_VERSION=1.88
FROM rust:${RUST_VERSION}
WORKDIR /app
# Runtime deps for Chromium and LibreOffice needed at test time.
# This layer is cached unless the package list changes.
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
# Chromium
chromium \
libgtk-3-0 libx11-xcb1 libxcomposite1 libxcursor1 \
libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 \
libxrandr2 libasound2 libatk1.0-0 libatk-bridge2.0-0 \
libpangocairo-1.0-0 libpango-1.0-0 libcairo2 \
libgdk-pixbuf2.0-0 libglib2.0-0 libgl1-mesa-glx \
fonts-liberation \
# LibreOffice — LOK (liblibreofficekit.so) is bundled in libreoffice-core
&& echo "deb http://deb.debian.org/debian bookworm-backports main" \
> /etc/apt/sources.list.d/backports.list \
&& apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y -t bookworm-backports \
-qq --no-install-recommends \
libreoffice-writer \
libreoffice-calc \
libreoffice-impress \
libreoffice-draw \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
# PDF tools used by BDD assertion steps
poppler-utils \
qpdf \
ghostscript \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV CHROME_PATH=/usr/bin/chromium
ENV CHROME_BIN=/usr/bin/chromium
# Required so Chromium can run as root inside the container
ENV NO_SANDBOX=true
ENV SAL_USE_VCLPLUGIN=svp
# LOK program directory — liblibreofficekit.so lives here
ENV LOK_PROGRAM_PATH=/usr/lib/libreoffice/program
ENV RUST_LOG=info
# UTF-8 locale so LibreOffice can open files with non-ASCII names (e.g.
# `Special_Chars_ß.docx`). Bookworm's default `C` locale fails LO type
# detection on those paths with `Unsupported URL: type detection failed`.
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
COPY . .
# --mount=type=cache keeps /usr/local/cargo (registry + git) and /app/target
# alive between builds — Cargo sees prior artifacts and only recompiles what changed.
# Cache mounts are committed even on non-zero exit, so a test failure still
# preserves compiled artifacts for the next build.
#
# --test-threads=1 because LOK allows only one Office instance per process;
# integration tests share a single static engine via OnceCell.
#
# Two failure modes we care about:
# 1. Compile errors — libtest never runs, no "test result" line is emitted.
# We catch these by running `cargo test --no-run` first; any non-zero exit
# there is a real compile failure and must fail the build.
# 2. Test failures — libtest prints "test result: FAILED" / "failures:".
# We catch these by greping the test-run output.
#
# We then ignore cargo's exit code on the *test-run* invocation only:
# LibreOffice ≥ 6.5 has a known atexit/teardown bug that bumps the test
# binary's exit code to non-zero even when every test passed (see
# libreofficekit-rs README). Trusting libtest's printed verdict at that
# point is the documented workaround.
# Bust ONLY this layer when you want a fresh test run without nuking the
# apt-install / COPY layers. Pass `--build-arg TEST_RUN_ID=$(date +%s)`
# to the buildx invocation. The default keeps the layer cacheable so a
# repeat build with no source changes is a no-op.
ARG TEST_RUN_ID=0
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/app/target \
bash -c 'set -e -o pipefail; \
echo "::compile pass — failing fast on any compile error (TEST_RUN_ID=${TEST_RUN_ID:-0})"; \
cargo test --no-fail-fast --no-run; \
echo "::run pass — ignoring LO atexit teardown noise on cargo exit"; \
set +e; \
cargo test --no-fail-fast -- --test-threads=1 2>&1 | tee /tmp/cargo_test.log; \
cargo_status=$?; \
set -e; \
if grep -qE "^test result: FAILED|^failures:$|^error\\[" /tmp/cargo_test.log; then \
echo "::test failures detected in libtest output"; \
exit 1; \
fi; \
echo "::all libtest sections reported ok (cargo exit was $cargo_status — ignoring LO atexit teardown noise)"; \
exit 0'