|
| 1 | +ARG USHIFT_BASE_IMAGE_NAME |
| 2 | +ARG USHIFT_BASE_IMAGE_TAG |
| 3 | +FROM $USHIFT_BASE_IMAGE_NAME:$USHIFT_BASE_IMAGE_TAG |
| 4 | + |
| 5 | +# Pull the container image dependencies into /var/lib/containers/storage-preloaded |
| 6 | +RUN --mount=type=secret,id=pullsecret,dst=/run/secrets/pull-secret.json \ |
| 7 | + images=$(jq -r '.images | .[]' "/usr/share/microshift/release/release-$(uname -m).json") ; \ |
| 8 | + for i in ${images} ; do \ |
| 9 | + podman pull \ |
| 10 | + --authfile /run/secrets/pull-secret.json \ |
| 11 | + --root /var/lib/containers/storage-preloaded \ |
| 12 | + "docker://${i}" ; \ |
| 13 | + done |
| 14 | + |
| 15 | +# Edit the container storage configuration file to include the new path |
| 16 | +RUN sed -i '/^additionalimagestores.*/a\ "/var/lib/containers/storage-preloaded",' /etc/containers/storage.conf |
| 17 | + |
| 18 | +# Apply a workaround to set the SELinux context on the new storage directory and |
| 19 | +# also restore 'NET_BIND_SERVICE' capability that is currently lost when including |
| 20 | +# images in the container. |
| 21 | +# |
| 22 | +# Note: This requires setting the additional image stores path to a read-write |
| 23 | +# location on the file system. The images will still be treated as read-only by |
| 24 | +# the container subsystem. |
| 25 | +# See https://github.com/ostreedev/ostree-rs-ext/issues/654 |
| 26 | +# |
| 27 | +# hadolint ignore=DL3059 |
| 28 | +RUN cat > /usr/bin/microshift-imagestore-config <<'EOF' |
| 29 | +#!/bin/bash |
| 30 | +set -euxo pipefail |
| 31 | +DEF_IMGPATH="$1" |
| 32 | +NEW_IMGPATH="$2" |
| 33 | +semanage fcontext -a -e "${DEF_IMGPATH}" "${NEW_IMGPATH}" |
| 34 | +restorecon -R "${NEW_IMGPATH}" |
| 35 | +find "${NEW_IMGPATH}" -type f -path "*/usr/sbin/haproxy" -exec setcap "cap_net_bind_service=+ep" {} \; |
| 36 | +EOF |
| 37 | + |
| 38 | +# hadolint ignore=DL3059 |
| 39 | +RUN cat > /etc/systemd/system/microshift-imagestore-config.service <<'EOF' |
| 40 | +[Unit] |
| 41 | +Description=Configure the image store directory for MicroShift |
| 42 | +Before=microshift.service |
| 43 | +[Service] |
| 44 | +Type=oneshot |
| 45 | +ExecStart=/usr/bin/microshift-imagestore-config /var/lib/containers/storage /var/lib/containers/storage-preloaded |
| 46 | +[Install] |
| 47 | +WantedBy=multi-user.target |
| 48 | +EOF |
| 49 | + |
| 50 | +RUN chmod 755 /usr/bin/microshift-imagestore-config && \ |
| 51 | + systemctl enable microshift-imagestore-config.service |
0 commit comments