22
33ARG ARCHTAG
44
5- FROM docker.io/library/archlinux:base-devel$ARCHTAG AS builder
5+ FROM docker.io/library/archlinux:$ARCHTAG AS base
6+
7+ # Initialize keys so we can do package management
8+ RUN pacman-key --init && pacman-key --populate
9+
10+ # This hack can convince Docker its cache is obsolete; e.g. when the contents
11+ # of downloaded resources have changed since being fetched. It's helpful to have
12+ # this as a separate layer because it saves time for local builds. Incrementing
13+ # this when pushing dependency updates to Caleb's Arch user repository or just
14+ # when the remote Docker Hub builds die should be enough.
15+ ARG DOCKER_HUB_CACHE=1
616
717ARG RUNTIME_DEPS
8- ARG BUILD_DEPS
918
1019# Enable system locales for everything we have localizations for so tools like
1120# `date` will output matching localized strings. By default Arch Docker images
@@ -14,60 +23,70 @@ ARG BUILD_DEPS
1423RUN sed -i -e '/^NoExtract.*locale/d' /etc/pacman.conf
1524
1625# Freshen all base system packages
17- RUN pacman-key --init
18- RUN pacman --needed --noconfirm -Syq archlinux-keyring
19- RUN pacman --needed --noconfirm -Suq
26+ RUN pacman --needed --noconfirm -Syuq && yes | pacman -Sccq
2027
2128# Make sure *at least* glibc actually got reinstalled after enabling
22- # extraaction of locale files even if the version was fresh so we can use the
29+ # extraction of locale files even if the version was fresh so we can use the
2330# locale support out of it later.
2431RUN pacman --noconfirm -Sq glibc && yes | pacman -Sccq
2532
2633# Install run-time dependencies
27- RUN pacman --needed --noconfirm -Sq $RUNTIME_DEPS $BUILD_DEPS
34+ RUN pacman --needed --noconfirm -Sq $RUNTIME_DEPS && yes | pacman -Sccq
35+
36+ # Setup LuaRocks for use with LuaJIT roughly matching SILE's internal VM
37+ RUN luarocks config lua_version 5.1 && \
38+ luarocks config lua_interpreter luajit && \
39+ luarocks config variables.LUA "$(command -v luajit)" && \
40+ luarocks config variables.LUA_INCDIR /usr/include/luajit-2.1/
41+
42+ # Setup separate image for build so we don’t bloat the final image
43+ FROM base AS builder
44+
45+ ARG BUILD_DEPS
46+
47+ # Install build time dependencies
48+ RUN pacman --needed --noconfirm -Sq $BUILD_DEPS && yes | pacman -Sccq
2849
2950# Set at build time, forces Docker’s layer caching to reset at this point
3051ARG REVISION
3152
3253COPY ./ /src
3354WORKDIR /src
3455
35- # Rebuild locale database after having added our supported locales.
56+ # Take note of SILE's supported locales so the final system can build localized messages
3657RUN ls i18n/ | sed 's/[.-].*$/_/;s/^/^/' | sort -u | grep -Ef - /usr/share/i18n/SUPPORTED > /etc/locale.gen
37- RUN locale-gen
3858
3959# GitHub Actions builder stopped providing git history :(
4060# See feature request at https://github.com/actions/runner/issues/767
4161RUN build-aux/docker-bootstrap.sh
4262
63+ # Use clang and mold instead of gcc and ld for speed
64+ ENV RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold"
65+
4366RUN ./bootstrap.sh
44- RUN ./configure --with-system-lua-sources --without-manual
67+ RUN ./configure \
68+ --disable-embeded-resources \
69+ --with-system-lua-sources \
70+ --without-system-luarocks \
71+ --without-manual
4572RUN make
4673RUN make install DESTDIR=/pkgdir
4774
48- # Work around BuiltKit / buildx bug, they can’t copy to symlinks only dirs
49- RUN mv /pkgdir/usr/local/{share/,}/man
50-
51- FROM docker.io/library/archlinux:base$ARCHTAG AS final
75+ FROM base AS final
5276
5377# Same args as above, repeated because they went out of scope with FROM
54- ARG RUNTIME_DEPS
55- ARG VERSION
5678ARG REVISION
79+ ARG VERSION
5780
5881# Allow `su` with no root password so non-priv users can install dependencies
5982RUN sed -i -e '/.so$/s/$/ nullok/' /etc/pam.d/su
6083
6184# Set system locale to something other than 'C' that resolves to a real language
6285ENV LANG=en_US.UTF-8
6386
64- # Freshen all base system packages (and cleanup cache)
65- RUN pacman-key --init
66- RUN pacman --needed --noconfirm -Syq archlinux-keyring && yes | pacman -Sccq
67- RUN pacman --needed --noconfirm -Suq && yes | pacman -Sccq
68-
69- # Install run-time dependencies
70- RUN pacman --needed --noconfirm -Sq $RUNTIME_DEPS && yes | pacman -Sccq
87+ # Rebuild locale database so system apps have localized messages for SILE's supported locales
88+ COPY --from=builder /etc/locale.gen /etc
89+ RUN locale-gen
7190
7291LABEL org.opencontainers.image.title="SILE"
7392LABEL org.opencontainers.image.description="A containerized version of the SILE typesetter"
@@ -80,8 +99,19 @@ LABEL org.opencontainers.image.revision="$REVISION"
8099
81100COPY build-aux/docker-fontconfig.conf /etc/fonts/conf.d/99-docker.conf
82101
102+ # Inform the system Lua manifest where SILE's vendored modules are so they are
103+ # available to 3rd party packages even outside of SILE's runtime. Most notably
104+ # useful so that luarocks can find them as existing dependencies when
105+ # installing 3rd party modules. We replace the user tree instead of inserting
106+ # a new one because it doesn't make sense in Docker anyway and the default
107+ # priority works out better having it first.
108+ RUN luarocks config rocks_trees[1].root /usr/local/share/sile/lua_modules && \
109+ luarocks config rocks_trees[1].name sile && \
110+ luarocks config deps_mode all
111+
83112COPY --from=builder /pkgdir /
84113COPY --from=builder /src/src/sile-entry.sh /usr/local/bin
114+
85115RUN sile --version
86116
87117WORKDIR /data
0 commit comments