#!/bin/sh # Imported source is compiled entirely inside a run-owned Docker builder. # Only .next/standalone and the untouched upstream Dockerfile enter the # temporary local image build context. No source tree write or registry push. set -eu : "${GITHUB_RUN_ID:?Missing numeric disposable Gitea run ID}" case "$GITHUB_RUN_ID" in *[!0-9]*|'') echo LOGIN_CI_INVALID_RUN_ID >&2; exit 1;; esac builder="zitplane-login-$GITHUB_RUN_ID-builder" image="zitplane-login-ci:$GITHUB_RUN_ID" context="/tmp/zitplane-login-build-$GITHUB_RUN_ID" label="zitplane.login.run=$GITHUB_RUN_ID" docker info --format '{{.Driver}}' >/dev/null if docker container inspect "$builder" >/dev/null 2>&1 || docker image inspect "$image" >/dev/null 2>&1 || [ -e "$context" ] || [ -e auth/ui/v2/apps/login/.env ] || [ -e auth/ui/v2/apps/login/.env.prod ]; then echo ZITPLANE_CUSTOM_LOGIN_PREEXISTING_STATE_REFUSED >&2 exit 1 fi test -r auth/ui/v2/apps/login/Dockerfile test -r auth/ui/v2/pnpm-lock.yaml test -r tests/ci/oidc_e2e/cleanup.sh # P05-OIDC-10 is opt-in: the previously accepted Run #99/default build mode # is not changed. The frozen input lock is read only in this new workflow. case "${ZITPLANE_PROVENANCE_CI:-0}" in 0|1) ;; *) echo ZITPLANE_P10_INVALID_PROVENANCE_MODE >&2; exit 1 ;; esac if [ "${ZITPLANE_PROVENANCE_CI:-0}" = 1 ]; then python3 tests/ci/login_image/provenance.py --preflight builder_ref="$(python3 tests/ci/login_image/provenance.py --field builder_ref)" else builder_ref=node:22-bookworm fi echo ZITPLANE_CUSTOM_LOGIN_ISOLATED_BUILD_PREFLIGHT_PASS if [ "${ZITPLANE_PROVENANCE_CI:-0}" = 1 ]; then docker create --platform linux/amd64 --name "$builder" --label "$label" "$builder_ref" sleep 3600 >/dev/null else docker create --name "$builder" --label "$label" "$builder_ref" sleep 3600 >/dev/null fi docker start "$builder" >/dev/null docker exec "$builder" mkdir -p /work docker cp auth/ui/v2 "$builder:/work/v2" docker exec -w /work/v2 "$builder" sh -ec ' corepack enable corepack prepare pnpm@10.30.3 --activate pnpm install --frozen-lockfile echo ZITPLANE_CUSTOM_LOGIN_FROZEN_INSTALL_PASS : > apps/login/.env export NEXT_PUBLIC_BASE_PATH=/ui/v2/login export NX_NO_CLOUD=true NX_DAEMON=false CI=true pnpm exec nx run @zitadel/login:build --skip-nx-cache rm -f apps/login/.env test -f apps/login/.next/standalone/apps/login/server.js test -f apps/login/.next/standalone/entrypoint.sh test -f apps/login/.next/standalone/healthcheck.mjs echo ZITPLANE_CUSTOM_LOGIN_STANDALONE_BUILD_PASS ' mkdir -m 700 -p "$context/.next" touch "$context/.zitplane-owned-$GITHUB_RUN_ID" docker cp "$builder:/work/v2/apps/login/.next/standalone" "$context/.next/standalone" # The immutable upstream Git entrypoint is 100644. The upstream Dockerfile # directly execs /app/entrypoint.sh as nextjs. Repair only this disposable # COPY input, never the tracked source, original Dockerfile or checkout. entry="$context/.next/standalone/entrypoint.sh" if [ -L "$entry" ] || [ ! -f "$entry" ]; then echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_NOT_REGULAR >&2 exit 1 fi if [ "$(head -c 2 "$entry")" != '#!' ]; then echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_INVALID_SHEBANG >&2 exit 1 fi mode="$(stat -c '%a' "$entry")" owner="$(stat -c '%u:%g' "$entry")" case "$mode:$owner" in *[!0-9:]*|'') echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_STAT_INVALID >&2; exit 1;; esac echo "ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_COPY_MODE=$mode OWNER=$owner" case "$mode" in 644) [ ! -x "$entry" ] || { echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_UNEXPECTED_EXECUTION_MODE >&2; exit 1; } chmod 0755 "$entry" echo ZITPLANE_CUSTOM_LOGIN_TEMP_ENTRYPOINT_MODE_FIXED_PASS ;; 755) [ -x "$entry" ] || { echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_NOT_EXECUTABLE >&2; exit 1; } echo ZITPLANE_CUSTOM_LOGIN_TEMP_ENTRYPOINT_ALREADY_EXECUTABLE_PASS ;; *) echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_UNEXPECTED_MODE >&2 exit 1 ;; esac [ ! -L "$entry" ] && [ -f "$entry" ] && [ -x "$entry" ] && [ "$(stat -c '%a' "$entry")" = 755 ] || { echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_COPY_EXECUTABILITY_BLOCKED >&2 exit 1 } echo ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_COPY_EXECUTABLE_PASS cp auth/ui/v2/apps/login/Dockerfile "$context/Dockerfile" if [ "${ZITPLANE_PROVENANCE_CI:-0}" = 1 ]; then python3 tests/ci/login_image/provenance.py --pin-dockerfile "$context/Dockerfile" source_revision="$(git rev-parse HEAD)" source_tree="$(git rev-parse HEAD:auth/ui/v2)" builder_index="$(python3 tests/ci/login_image/provenance.py --field builder_index)" runtime_index="$(python3 tests/ci/login_image/provenance.py --field runtime_index)" docker build --pull --platform linux/amd64 --label "$label" \ --label "org.opencontainers.image.revision=$source_revision" \ --label "zitplane.login.source_tree=$source_tree" \ --label "zitplane.login.builder_digest=$builder_index" \ --label "zitplane.login.runtime_digest=$runtime_index" \ -t "$image" -f "$context/Dockerfile" "$context" else docker build --pull --label "$label" -t "$image" -f "$context/Dockerfile" "$context" fi # Probe the final image under its original USER nextjs, with no network, # credentials, host volumes or entrypoint execution; print no file contents. docker run --rm --network none --entrypoint /bin/sh "$image" -ec ' entry=/app/entrypoint.sh [ ! -L "$entry" ] && [ -f "$entry" ] && [ -x "$entry" ] && [ "$(stat -c "%a" "$entry")" = 755 ] && [ "$(head -c 2 "$entry")" = "#!" ] ' || { echo ZITPLANE_CUSTOM_LOGIN_BUILT_IMAGE_ENTRYPOINT_BLOCKED >&2 exit 1 } echo ZITPLANE_CUSTOM_LOGIN_BUILT_IMAGE_ENTRYPOINT_EXECUTABLE_PASS actual_label="$(docker image inspect --format '{{ index .Config.Labels "zitplane.login.run" }}' "$image")" image_id="$(docker image inspect --format '{{.Id}}' "$image")" if [ "$actual_label" != "$GITHUB_RUN_ID" ]; then echo ZITPLANE_CUSTOM_LOGIN_IMAGE_OWNERSHIP_MISMATCH >&2 exit 1 fi case "$image_id" in sha256:*) ;; *) echo ZITPLANE_CUSTOM_LOGIN_IMAGE_ID_MISSING >&2; exit 1;; esac echo ZITPLANE_CUSTOM_LOGIN_LOCAL_IMAGE_BUILT_PASS # Record only a digest/ID and sanitized ownership metadata (never credentials). echo "ZITPLANE_CUSTOM_LOGIN_IMAGE_ID=$image_id" if [ "${ZITPLANE_PROVENANCE_CI:-0}" = 1 ]; then python3 tests/ci/login_image/provenance.py --verify-image echo ZITPLANE_P10_LOCAL_DISPOSABLE_IMAGE_PROVENANCE_PASS fi