Skip to content

Commit 73ee020

Browse files
committed
Fix buildah image, clean up base dockerfile
Signed-off-by: Tim Etchells <[email protected]>
1 parent bb7fc00 commit 73ee020

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

base/Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ RUN dnf -y upgrade --security && \
88

99
# The UID env var should be used in child dockerfiles.
1010
ENV UID=1000
11-
# ENV GID=0
12-
ENV USERNAME="build"
11+
ENV GID=0
12+
ENV USERNAME="runner"
1313

1414
# Create our user and their home directory
1515
RUN useradd -m $USERNAME -u $UID
16+
# This is to mimic the OpenShift behaviour of adding the dynamic user to group 0.
1617
RUN usermod -G 0 $USERNAME
1718
ENV HOME /home/${USERNAME}
1819
WORKDIR /home/${USERNAME}
@@ -25,7 +26,7 @@ ENV RUNNER_WORKDIR /home/${USERNAME}/_work
2526
ENV RUNNER_LABELS ""
2627

2728
# Allow group 0 to modify these /etc/ files since on openshift, the dynamically-assigned user is always part of group 0.
28-
# Also see uid.sh
29+
# Also see ./uid.sh for the usage of these permissions.
2930
RUN chmod g+w /etc/passwd && \
3031
touch /etc/sub{g,u}id && \
3132
chmod -v ug+rw /etc/sub{g,u}id
@@ -34,14 +35,13 @@ COPY --chown=${USERNAME}:0 get-runner-release.sh ./
3435
RUN ./get-runner-release.sh
3536
RUN ./bin/installdependencies.sh
3637

37-
# Set permissions so that we can allow the openshift-generated container user to access home and /etc/passwd.
38+
# Set permissions so that we can allow the openshift-generated container user to access home.
3839
# https://docs.openshift.com/container-platform/3.3/creating_images/guidelines.html#openshift-container-platform-specific-guidelines
3940
RUN chown -R ${USERNAME}:0 /home/${USERNAME}/ && \
4041
chgrp -R 0 /home/${USERNAME}/ && \
4142
chmod -R g=u /home/${USERNAME}/
4243

4344
COPY --chown=${USERNAME}:0 entrypoint.sh uid.sh ./
44-
# RUN chmod -v ug+x *.sh
4545

4646
USER $UID
4747

base/uid.sh

+10-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ if ! whoami &> /dev/null; then
2121
tail -n 1 /etc/passwd
2222
else
2323
echo "No write permission to /etc/passwd!" 1>&2
24-
exit 1
2524
fi
2625
else
2726
echo "User already has passwd entry"
@@ -31,18 +30,16 @@ echo "whoami=$(whoami)"
3130
echo "groups=$(groups 2>/dev/null)"
3231

3332
set +x
34-
#if ! grep $username /etc/subuid &> /dev/null; then
35-
echo "Creating sub{u,g}id entries for $username"
36-
subuids_start=$(expr $uid + 1000)
37-
subgids_start=$(expr $gid + 1000)
38-
39-
no_subids=50000
40-
41-
echo "${username}:${subuids_start}:${no_subids}" | tee /etc/subuid
42-
echo "${username}:${subgids_start}:${no_subids}" | tee /etc/subgid
43-
#else
44-
# echo "subuid entry already exists for $username"
45-
#fi
33+
echo "Creating sub{u,g}id entries for $username"
34+
subuids_start=$(expr $uid + 1000)
35+
subgids_start=$(expr $gid + 1000)
36+
37+
# Do not allocate too many.
38+
# https://github.com/containers/buildah/issues/3053
39+
no_subids=50000
40+
41+
echo "${username}:${subuids_start}:${no_subids}" | tee /etc/subuid
42+
echo "${username}:${subgids_start}:${no_subids}" | tee /etc/subgid
4643

4744
# set -x
4845
# tail -n +1 /etc/sub{u,g}id

buildah/Dockerfile

+3-15
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,27 @@ FROM $BASE_IMG AS buildah-runner
33

44
USER root
55

6-
# Some complex config is required to allow buildah to run in a nonprivileged container.
76
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
87
# https://github.com/containers/buildah/blob/master/contrib/buildahimage/stable/Dockerfile
98
# https://github.com/containers/buildah/issues/1011
9+
# https://github.com/containers/buildah/issues/3053
1010

11-
RUN dnf -y install shadow-utils xz slirp4netns buildah podman fuse-overlayfs --exclude container-selinux && \
11+
RUN dnf -y install xz slirp4netns buildah podman fuse-overlayfs --exclude container-selinux && \
12+
dnf -y reinstall shadow-utils && \
1213
dnf clean all
1314

1415
ENV BUILDAH_ISOLATION=chroot
1516

1617
ADD https://raw.githubusercontent.com/containers/buildah/master/contrib/buildahimage/stable/containers.conf /etc/containers/
1718

18-
# ADD https://raw.githubusercontent.com/containers/buildah/master/contrib/buildahimage/stable/containers.conf /etc/containers/
1919
RUN chgrp -R 0 /etc/containers/ && \
2020
chmod -R a+r /etc/containers/ && \
2121
chmod -R g+w /etc/containers/
22-
# echo "user.max_user_namespaces=65536" > /etc/sysctl.d/userns.conf && \
23-
# prevents errors from failing to log using systemd https://github.com/containers/podman/issues/4325#issuecomment-570650857
24-
# See https://github.com/containers/common/blob/master/docs/containers.conf.5.md for valid configurations
25-
# printf '[engine]\nevents_logger = "file"\n' >> /etc/containers/containers.conf
26-
# printf 'events_logger = "file"\n' >> /etc/containers/containers.conf
27-
28-
# Adjust storage.conf to enable Fuse storage.
29-
RUN chmod 644 /etc/containers/containers.conf; sed -i -e 's|^#mount_program|mount_program|g' -e '/additionalimage.*/a "/var/lib/shared",' -e 's|^mountopt[[:space:]]*=.*$|mountopt = "nodev,fsync=0"|g' /etc/containers/storage.conf
30-
RUN mkdir -p /var/lib/shared/overlay-images /var/lib/shared/overlay-layers /var/lib/shared/vfs-images /var/lib/shared/vfs-layers; touch /var/lib/shared/overlay-images/images.lock; touch /var/lib/shared/overlay-layers/layers.lock; touch /var/lib/shared/vfs-images/images.lock; touch /var/lib/shared/vfs-layers/layers.lock
3122

3223
# Use VFS since fuse does not work
3324
# https://github.com/containers/buildah/blob/master/vendor/github.com/containers/storage/storage.conf
3425
RUN mkdir -vp /home/${USERNAME}/.config/containers && \
3526
printf '[storage]\ndriver = "vfs"\n' > /home/${USERNAME}/.config/containers/storage.conf && \
3627
chown -Rv ${USERNAME} /home/${USERNAME}/.config/
3728

38-
RUN printf "${USERNAME}:2000:50000\n" > /etc/subuid
39-
RUN printf "${USERNAME}:2000:50000\n" > /etc/subgid
40-
4129
USER $UID

0 commit comments

Comments
 (0)