mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
14 hours ago 29a7662d10dede94fd8c022fafc082693dc44e13
Retry Alpine package operations and reuse repository indexes (#1347)

## Summary

- Allow up to three attempts for `apk update`, `apk add`, and `apk
upgrade`, with 5- and 15-second delays. Propagate the final failure to
the build.
- Fetch each Alpine repository index once on a healthy build, reuse the
indexes during package installation and upgrades, and remove them in the
same image layer.

The `linux/386` Alpine build in #1341 failed after a transient DNS error
while fetching `APKINDEX`. Build and Release both use this Dockerfile.

## Verification

- Built the CI image from a local server ZIP for all six target
platforms and observed one successful index refresh per platform.
- On `linux/386`, injected HTTP 503 responses for an index and the
OpenJDK 11 package. Both operations recovered, and the package retry
reused the indexes.
- Verified that persistent failures preserve the last exit status, and
built the `linux/amd64` image from the released OpenDJ 5.2.0 ZIP.
1 files modified
17 ■■■■■ changed files
opendj-packages/opendj-docker/Dockerfile-alpine 17 ●●●●● patch | view | raw | blame | history
opendj-packages/opendj-docker/Dockerfile-alpine
@@ -65,16 +65,27 @@
# The headless JRE: the server and the command-line tools do not draw, and the full JRE only
# adds what AWT needs to - X11, ALSA, freetype with brotli, the image codecs - along with their
# CVEs. The GUI tools (control-panel) are run outside the container, against its admin port.
RUN apk add --update --no-cache --virtual builddeps curl unzip \
 && apk upgrade --update --no-cache \
# Keep the repository indexes for this layer so add and upgrade can reuse them.
RUN apk_retry() { \
        for delay in 5 15; do \
            if apk "$@"; then return 0; fi; \
            echo "apk $* failed, retrying in ${delay}s" >&2; \
            sleep "$delay" || return; \
        done; \
        apk "$@"; \
    } \
 && apk_retry update \
 && apk_retry add --virtual builddeps curl unzip \
 && apk_retry upgrade \
 && if [ "$TARGETARCH" = "386" ]; then JDK=openjdk11-jre-headless; else JDK=openjdk25-jre-headless; fi \
 && apk add bash coreutils "$JDK" \
 && apk_retry add bash coreutils "$JDK" \
 && if [ -z "$VERSION" ] ; then VERSION="$(curl -i -o - --silent https://api.github.com/repos/OpenIdentityPlatform/OpenDJ/releases/latest | grep -m1 "\"name\"" | cut -d\" -f4)"; fi \
 && if [ ! -f "$OPENDJ_DIST_FILENAME" ]; then echo file exists && curl -L https://github.com/OpenIdentityPlatform/OpenDJ/releases/download/$VERSION/opendj-$VERSION.zip --output $OPENDJ_DIST_FILENAME; fi \
 && unzip $OPENDJ_DIST_FILENAME \
 && apk del builddeps \
 && apk del curl \
 && apk del unzip \
 && rm -f /var/cache/apk/* \
 && rm -r $OPENDJ_DIST_FILENAME \
 && addgroup -S $OPENDJ_USER \
 && adduser -S -u 1001 -G $OPENDJ_USER $OPENDJ_USER \