Skip to content

Commit e03bc78

Browse files
committed
fix(handouts): use only root user in env image
1 parent 74dda5b commit e03bc78

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

src/build-handouts/build-handouts.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ if [ "$ALWAYS_REBUILD_IMAGE" = "y" ]; then
2727
fi
2828

2929
docker run --rm -it \
30+
--user $(id -u):$(id -g) \
3031
--name "$CONTAINER_NAME" \
32+
--hostname "$CONTAINER_NAME" \
3133
--mount type=bind,source="${REPO_ROOT}/src/handouts",target=/app/src/handouts,readonly \
3234
--mount type=bind,source="$BUILD_PATH",target=/app/build \
33-
--hostname "$CONTAINER_NAME" \
3435
"${IMAGE_NAME}:${IMAGE_TAG}"

src/build-handouts/env-image/Dockerfile

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,45 @@ ARG UBUNTU_IMAGE_TAG=noble-20250127
22

33
FROM ubuntu:${UBUNTU_IMAGE_TAG}
44

5-
ARG UID_USER=1000
6-
ARG GID_USER=1000
7-
ARG USERNAME=user
8-
ARG HOME_DIR=/home/"${USERNAME}"
9-
105
# set timezone and install TeX Live dependencies
116
# reference: https://stackoverflow.com/a/40235306
127
RUN ln -fs /usr/share/zoneinfo/Asia/Taipei /etc/localtime && \
138
apt -qqy update && \
149
apt -qqy install wget perl tzdata && \
15-
apt clean
16-
17-
# create a normal user
18-
RUN groupadd -g $GID_USER "${USERNAME}" && \
19-
useradd -m -g "${USERNAME}" -u $UID_USER -s /bin/bash "${USERNAME}"
10+
rm -rf /var/lib/apt/lists/*
2011

21-
# install TeX Live and dependencies with a normal user
22-
USER ${USERNAME}
23-
ENV HOME="$HOME_DIR"
24-
ENV PATH="$HOME/.texlive/bin/x86_64-linux/:$PATH"
12+
# install TeX Live and dependencies
13+
ENV TL_ROOT="/opt/texlive"
14+
ENV PATH="$TL_ROOT/bin/x86_64-linux/:$PATH"
2515
ARG INSTALL_TL_URL="https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz"
26-
ARG TL_DOC_PATH=$HOME/.texlive/texmf-dist/doc/
16+
ARG TL_DOC_PATH="$TL_ROOT/texmf-dist/doc/"
2717
RUN cd /tmp && \
2818
echo "Downloading TeX Live installer..." && \
2919
wget -qO- "$INSTALL_TL_URL" --no-check-certificate | tar -xz && \
3020
cd install-tl-* && \
3121
echo "Installing TeX Live with basic scheme..." && \
32-
perl ./install-tl -scheme=scheme-basic --no-interaction -texdir="~/.texlive" -no-doc-install -no-src-install && \
22+
perl ./install-tl -scheme=scheme-basic --no-interaction -texdir="$TL_ROOT" -no-doc-install -no-src-install && \
3323
tlmgr backup -q --all --clean=0 && \
3424
rm -rf "$TL_DOC_PATH" && \
35-
find ~/.texlive -name *src* -exec rm {} \; && \
25+
find "$TL_ROOT" -name *src* -exec rm {} \; && \
3626
cd /tmp && \
37-
rm -rf ./*
27+
rm -rf *
3828

3929
# install required packages to build the handouts
4030
ARG PACKAGES=mathtools
4131
RUN echo "Installing TeX Live packages: ${PACKAGES}" && \
4232
tlmgr install ${PACKAGES} && \
4333
tlmgr backup -q --all --clean=0 && \
4434
rm -rf "$TL_DOC_PATH" && \
45-
find ~/.texlive -name *src* -exec rm {} \;
35+
find "$TL_ROOT" -name *src* -exec rm {} \;
4636

4737
# patch missing fonts
4838
ARG SCRIPT_PATCH_FONTS=/tmp/patch-missing-fonts.sh
49-
COPY --chown=$USERNAME:$USERNAME ./patch-missing-fonts.sh $SCRIPT_PATCH_FONTS
50-
RUN $SCRIPT_PATCH_FONTS && \
39+
COPY ./patch-missing-fonts.sh /tmp/patch.sh
40+
RUN /tmp/patch.sh && \
5141
rm -rf /tmp/*
5242

53-
USER root
43+
# prepare container startup
5444
WORKDIR /app
5545
COPY entrypoint.sh ./entrypoint.sh
56-
RUN chmod +x ./entrypoint.sh && \
57-
apt autopurge -qqy wget perl
58-
# after uninstalling perl, you can not use tlmgr command any more
59-
60-
USER ${USERNAME}
6146
ENTRYPOINT [ "./entrypoint.sh" ]

0 commit comments

Comments
 (0)