Skip to content

Commit

Permalink
Merge pull request #2116 from alerque/fix-docker-locale
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque authored Sep 28, 2024
2 parents 9bffe4b + ef07361 commit 3a3b1bc
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
run: |
make fake-manual
make distdir
- name: Build from package
- name: Build from dist tree
run: |
make docker-test-dist
Expand Down
76 changes: 53 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

ARG ARCHTAG

FROM docker.io/library/archlinux:base-devel$ARCHTAG AS builder
FROM docker.io/library/archlinux:$ARCHTAG AS base

# Initialize keys so we can do package management
RUN pacman-key --init && pacman-key --populate

# This hack can convince Docker its cache is obsolete; e.g. when the contents
# of downloaded resources have changed since being fetched. It's helpful to have
# this as a separate layer because it saves time for local builds. Incrementing
# this when pushing dependency updates to Caleb's Arch user repository or just
# when the remote Docker Hub builds die should be enough.
ARG DOCKER_HUB_CACHE=1

ARG RUNTIME_DEPS
ARG BUILD_DEPS

# Enable system locales for everything we have localizations for so tools like
# `date` will output matching localized strings. By default Arch Docker images
Expand All @@ -14,60 +23,70 @@ ARG BUILD_DEPS
RUN sed -i -e '/^NoExtract.*locale/d' /etc/pacman.conf

# Freshen all base system packages
RUN pacman-key --init
RUN pacman --needed --noconfirm -Syq archlinux-keyring
RUN pacman --needed --noconfirm -Suq
RUN pacman --needed --noconfirm -Syuq && yes | pacman -Sccq

# Make sure *at least* glibc actually got reinstalled after enabling
# extraaction of locale files even if the version was fresh so we can use the
# extraction of locale files even if the version was fresh so we can use the
# locale support out of it later.
RUN pacman --noconfirm -Sq glibc && yes | pacman -Sccq

# Install run-time dependencies
RUN pacman --needed --noconfirm -Sq $RUNTIME_DEPS $BUILD_DEPS
RUN pacman --needed --noconfirm -Sq $RUNTIME_DEPS && yes | pacman -Sccq

# Setup LuaRocks for use with LuaJIT roughly matching SILE's internal VM
RUN luarocks config lua_version 5.1 && \
luarocks config lua_interpreter luajit && \
luarocks config variables.LUA "$(command -v luajit)" && \
luarocks config variables.LUA_INCDIR /usr/include/luajit-2.1/

# Setup separate image for build so we don’t bloat the final image
FROM base AS builder

ARG BUILD_DEPS

# Install build time dependencies
RUN pacman --needed --noconfirm -Sq $BUILD_DEPS && yes | pacman -Sccq

# Set at build time, forces Docker’s layer caching to reset at this point
ARG REVISION

COPY ./ /src
WORKDIR /src

# Rebuild locale database after having added our supported locales.
# Take note of SILE's supported locales so the final system can build localized messages
RUN ls i18n/ | sed 's/[.-].*$/_/;s/^/^/' | sort -u | grep -Ef - /usr/share/i18n/SUPPORTED > /etc/locale.gen
RUN locale-gen

# GitHub Actions builder stopped providing git history :(
# See feature request at https://github.com/actions/runner/issues/767
RUN build-aux/docker-bootstrap.sh

# Use clang and mold instead of gcc and ld for speed
ENV RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold"

RUN ./bootstrap.sh
RUN ./configure --with-system-lua-sources --without-manual
RUN ./configure \
--disable-embeded-resources \
--with-system-lua-sources \
--without-system-luarocks \
--without-manual
RUN make
RUN make install DESTDIR=/pkgdir

# Work around BuiltKit / buildx bug, they can’t copy to symlinks only dirs
RUN mv /pkgdir/usr/local/{share/,}/man

FROM docker.io/library/archlinux:base$ARCHTAG AS final
FROM base AS final

# Same args as above, repeated because they went out of scope with FROM
ARG RUNTIME_DEPS
ARG VERSION
ARG REVISION
ARG VERSION

# Allow `su` with no root password so non-priv users can install dependencies
RUN sed -i -e '/.so$/s/$/ nullok/' /etc/pam.d/su

# Set system locale to something other than 'C' that resolves to a real language
ENV LANG=en_US.UTF-8

# Freshen all base system packages (and cleanup cache)
RUN pacman-key --init
RUN pacman --needed --noconfirm -Syq archlinux-keyring && yes | pacman -Sccq
RUN pacman --needed --noconfirm -Suq && yes | pacman -Sccq

# Install run-time dependencies
RUN pacman --needed --noconfirm -Sq $RUNTIME_DEPS && yes | pacman -Sccq
# Rebuild locale database so system apps have localized messages for SILE's supported locales
COPY --from=builder /etc/locale.gen /etc
RUN locale-gen

LABEL org.opencontainers.image.title="SILE"
LABEL org.opencontainers.image.description="A containerized version of the SILE typesetter"
Expand All @@ -80,8 +99,19 @@ LABEL org.opencontainers.image.revision="$REVISION"

COPY build-aux/docker-fontconfig.conf /etc/fonts/conf.d/99-docker.conf

# Inform the system Lua manifest where SILE's vendored modules are so they are
# available to 3rd party packages even outside of SILE's runtime. Most notably
# useful so that luarocks can find them as existing dependencies when
# installing 3rd party modules. We replace the user tree instead of inserting
# a new one because it doesn't make sense in Docker anyway and the default
# priority works out better having it first.
RUN luarocks config rocks_trees[1].root /usr/local/share/sile/lua_modules && \
luarocks config rocks_trees[1].name sile && \
luarocks config deps_mode all

COPY --from=builder /pkgdir /
COPY --from=builder /src/src/sile-entry.sh /usr/local/bin

RUN sile --version

WORKDIR /data
Expand Down
6 changes: 3 additions & 3 deletions hooks/build
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env sh
set -e

: "${ARCHTAG:=}"
: "${ARCHTAG:=latest}"
: "${DOCKERFILE:=Dockerfile}"

REVISION=$(git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')

RUNTIME_DEPS='fontconfig freetype2 gentium-plus-font glibc harfbuzz icu libpng luajit zlib'\
' libertinus-font luarocks noto-fonts-cjk ttf-hack'
BUILD_DEPS='cargo git jq lua51 poppler'
' otf-libertinus luarocks noto-fonts-cjk ttf-hack'
BUILD_DEPS='base-devel cargo clang git jq mold poppler'

: "${DOCKER_BUILDKIT:=1}"
export DOCKER_BUILDKIT
Expand Down
22 changes: 14 additions & 8 deletions tests/Dockerfile-dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
#syntax=docker/dockerfile:1.2

ARG ARCHTAG

FROM docker.io/library/archlinux:base-devel$ARCHTAG
FROM docker.io/library/archlinux:base

ARG RUNTIME_DEPS
ARG BUILD_DEPS

# Freshen all base system packages
RUN pacman-key --init
RUN pacman --needed --noconfirm -Syq archlinux-keyring
RUN pacman --needed --noconfirm -Suq
RUN pacman --needed --noconfirm -Syuq

# Install build and run-time dependencies
RUN pacman --needed --noconfirm -Sq $RUNTIME_DEPS $BUILD_DEPS

# Remove autotools, building the source distributions should not require them
RUN pacman --noconfirm -Rn autoconf automake libtool base-devel
RUN pacman --noconfirm -Rn autoconf automake libtool base-devel hwloc onetbb clang mold

# Setup LuaRocks for use with LuaJIT roughly matching SILE's internal VM
RUN luarocks config lua_version 5.1 && \
luarocks config lua_interpreter luajit && \
luarocks config variables.LUA "$(command -v luajit)" && \
luarocks config variables.LUA_INCDIR /usr/include/luajit-2.1/

# Set at build time, forces Docker’s layer caching to reset at this point
ARG VERSION

COPY ./sile-$VERSION /src
WORKDIR /src

RUN ./configure --with-system-lua-sources --without-manual
RUN ./configure \
--disable-embeded-resources \
--with-system-lua-sources \
--without-system-luarocks \
--without-manual
RUN make
RUN make install

Expand Down

0 comments on commit 3a3b1bc

Please sign in to comment.