Repository navigation
Expand file tree
/
Copy pathDockerfile.script-runner
More file actions
124 lines (106 loc) · 6.6 KB
/
Copy pathDockerfile.script-runner
File metadata and controls
124 lines (106 loc) · 6.6 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Sandbox images for the script runner. One multi-stage Dockerfile, two build
# targets, two images:
#
# podman build --target restricted -t quest-script-runner-<mode> -f Dockerfile.script-runner .
# podman build --target public -t quest-script-runner-public-<mode> -f Dockerfile.script-runner .
#
# The `base` stage holds everything the two sandboxes have in common (the
# Debian tools, the pip packages, headless LibreOffice with fonts, the warm
# caches). The `restricted` and `public` stages add what differs: the
# restricted sandbox gets socat for the proxy bridge to the Quest API, the
# public one gets the internet-workload packages (fetching, scraping, API
# clients) -- each with its own entrypoint. Keep the stages separate rather
# than a mode switch so the tooling in each can still diverge; keep the
# shared part in `base` so podman builds it once: the two images share the
# base layers (~850 MB, nearly all LibreOffice + fonts + pip), so the second
# build is a few seconds of thin layers and the id-mapped layer copy that
# run.py warms after a build is paid once for the shared part.
FROM python:3.12-slim AS base
# Bump this date to make every deployment rebuild the images from fresh layers
# the next time run.py starts: a newer python:3.12-slim base (run.py pulls it
# before a rebuild), current Debian packages and current pip packages, e.g.
# after a security fix in the base image, ca-certificates or certifi. run.py
# rebuilds when this file changes, but podman would otherwise reuse every
# cached layer because no instruction below changed; a changed ARG value
# used in the LABEL invalidates the cache from here down.
ARG QUEST_IMAGE_REVISION=2026-10-23
LABEL org.quest.image-revision=${QUEST_IMAGE_REVISION}
RUN apt-get update && \
apt-get install -y --no-install-recommends curl wget jq bash iptables zip unzip ca-certificates && \
rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir requests openpyxl python-docx matplotlib seaborn pypdf PyPDFForm
# LibreOffice (headless, no GUI toolkit) plus fonts, for high-fidelity
# document conversion inside the sandbox (Word / ODT / RTF / HTML -> PDF and
# the other LibreOffice formats, also xlsx / pptx -> PDF). The system prompt
# and the system:workspace skill steer the model here for every document
# conversion instead of stitching PDFs together from python-docx output.
#
# Fonts: the metric-compatible clones LibreOffice substitutes automatically
# (Carlito for Calibri, Caladea for Cambria, Liberation for Arial / Times New
# Roman / Courier New) plus DejaVu and Noto for coverage. Microsoft's "Core
# fonts for the Web" (Arial, Times New Roman, Courier New, Verdana, Georgia,
# Trebuchet MS, Comic Sans MS, Impact, Andale Mono, Webdings) are
# EULA-redistributable and downloaded at build time by the `contrib` package
# ttf-mscorefonts-installer; the Office-era fonts (Calibri, Cambria, Segoe UI,
# Aptos, ...) are not redistributable, hence the clones. A build host without
# egress to the fonts' download mirror still succeeds with the clones only.
RUN sed -i 's/ main$/ main contrib/' /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
apt-get install -y --no-install-recommends \
libreoffice-writer-nogui libreoffice-calc-nogui libreoffice-impress-nogui \
fontconfig fonts-crosextra-carlito fonts-crosextra-caladea \
fonts-liberation fonts-liberation2 fonts-dejavu fonts-noto-core && \
( echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \
apt-get install -y --no-install-recommends ttf-mscorefonts-installer \
|| echo "WARNING: Microsoft core fonts not installed (download failed?); continuing with the metric-compatible clones only" ) && \
rm -rf /var/lib/apt/lists/* && \
fc-cache -f
# `soffice` wrapper that seeds a per-run copy of a pre-built LibreOffice
# user profile (first-start profile creation costs ~1-2 s per container
# otherwise; HOME is a fresh /tmp on every run). The warm-up conversion
# below creates the profile at image build time.
COPY script-runner-soffice.sh /usr/local/bin/soffice
RUN chmod +x /usr/local/bin/soffice && ln -s soffice /usr/local/bin/libreoffice && \
mkdir -p /opt/libreoffice-profile && echo "warm-up" > /tmp/warm-up.txt && \
LIBREOFFICE_PROFILE_DIR=/opt/libreoffice-profile \
soffice --headless --convert-to pdf --outdir /tmp /tmp/warm-up.txt >/dev/null && \
rm -f /tmp/warm-up.txt /tmp/warm-up.pdf && chmod -R a+rX /opt/libreoffice-profile
ENV MPLBACKEND=Agg
# Pre-build matplotlib's font cache at image build time. Containers run with
# a fresh HOME=/tmp, so without this every run that imports matplotlib
# rebuilds fontlist.json from scratch (~1.2s). The directory must stay
# writable: matplotlib falls back to a throwaway temp dir (and rebuilds)
# when MPLCONFIGDIR is not writable by the unprivileged run user.
ENV MPLCONFIGDIR=/opt/matplotlib
RUN python3 -c "import matplotlib.pyplot" && chmod -R a+rwX /opt/matplotlib
WORKDIR /workspace
# ---------------------------------------------------------------------------
# Restricted sandbox (default): internal-data processing, no internet.
# ---------------------------------------------------------------------------
FROM base AS restricted
# socat for the entrypoint's proxy bridge (the public sandbox has no bridge
# and does not get it).
RUN apt-get update && \
apt-get install -y --no-install-recommends socat && \
rm -rf /var/lib/apt/lists/*
# Entrypoint script that starts a socat forwarder so scripts can reach
# the host API proxy at localhost:8000 (forwarded to 10.0.2.2:8000 via
# slirp4netns), then execs the user's command.
COPY script-runner-entry.sh /usr/local/bin/script-runner-entry.sh
RUN chmod +x /usr/local/bin/script-runner-entry.sh
ENTRYPOINT ["/usr/local/bin/script-runner-entry.sh"]
# Setting ENTRYPOINT resets the CMD inherited from `base`; restate it.
CMD ["python3"]
# ---------------------------------------------------------------------------
# Public-project sandbox: internet workloads (fetching, scraping, API clients).
# ---------------------------------------------------------------------------
FROM base AS public
RUN pip install --no-cache-dir httpx beautifulsoup4 lxml
# Entrypoint script that opens internet egress while REJECTing all private /
# link-local destinations (LAN, cloud metadata service), then drops
# privileges. No socat proxy bridge: public containers have no path -- and
# no credential -- to the Quest API.
COPY script-runner-entry-public.sh /usr/local/bin/script-runner-entry-public.sh
RUN chmod +x /usr/local/bin/script-runner-entry-public.sh
ENTRYPOINT ["/usr/local/bin/script-runner-entry-public.sh"]
CMD ["python3"]