@@ -4,14 +4,25 @@ set -euo pipefail
44export LC_ALL=C.UTF-8
55export LANG=C.UTF-8
66
7- TARGET_REGISTRY=${TARGET_REGISTRY:- ghcr.io/ microshift-io/ okd}
7+ # Production registry - must be provided via TARGET_REGISTRY environment variable
8+ # or defaults to the upstream registry if not specified
9+ PRODUCTION_REGISTRY=" ${TARGET_REGISTRY:- ghcr.io/ microshift-io/ okd} "
10+ # Automatically derive staging registry by appending '/okd-staging' subpath
11+ STAGING_REGISTRY=" $( dirname " ${PRODUCTION_REGISTRY} " ) /okd-staging"
812PULL_SECRET=${PULL_SECRET:- ~/ .pull-secret.json}
913
1014WORKDIR=$( mktemp -d /tmp/okd-build-images-XXXXXX)
1115trap ' cd ; rm -rf "${WORKDIR}"' EXIT
1216
1317usage () {
14- echo " Usage: $( basename " $0 " ) <okd-version> <ocp-branch> <target-arch>"
18+ echo " Usage: $( basename " $0 " ) <mode> <okd-version> <ocp-branch> <target-arch>"
19+ echo " mode: Operation mode - 'staging', 'production', or 'cleanup'"
20+ echo " 'staging' - Build OKD images locally and push to staging registry"
21+ echo " (${STAGING_REGISTRY} )"
22+ echo " 'production' - Push previously built images to production registry"
23+ echo " (${PRODUCTION_REGISTRY} )"
24+ echo " 'cleanup' - Delete images from staging registry"
25+ echo " (${STAGING_REGISTRY} )"
1526 echo " okd-version: The version of OKD to build (see https://amd64.origin.releases.ci.openshift.org/)"
1627 echo " ocp-branch: The branch of OCP to build (e.g. release-4.19)"
1728 echo " target-arch: The architecture of the target images (amd64 or arm64)"
@@ -320,17 +331,118 @@ create_new_okd_release() {
320331 # "ovn-kubernetes-microshift=${images_sha[ovn-kubernetes-microshift]}" \
321332}
322333
334+ # Build OKD images locally and populate images_sha array
335+ build_okd_images () {
336+ echo " Building OKD images locally..."
337+ create_images
338+
339+ for key in " ${! images[@]} " ; do
340+ # Skip haproxy-router for non-ARM64 architectures (see TODO at line 99)
341+ # haproxy28 package implementation for amd64 is not yet available
342+ if [ " ${TARGET_ARCH} " != " arm64" ] && [ " ${key} " = " haproxy-router" ] ; then
343+ continue
344+ fi
345+ images_sha[" ${key} " ]=" ${images[$key]} "
346+ done
347+
348+ echo " Build completed successfully"
349+ }
350+
351+ # Push images and manifests to registry, then create OKD release
352+ push_okd_images () {
353+ echo " Pushing images to registry: ${TARGET_REGISTRY} "
354+ push_image_manifests
355+ create_new_okd_release
356+ echo " Push completed successfully"
357+ echo " OKD release image published to: ${OKD_RELEASE_IMAGE} "
358+ }
359+
360+ # Retag staging images to production names
361+ retag_staging_to_production () {
362+ echo " Re-tagging staging images to production names..."
363+
364+ for key in " ${! images[@]} " ; do
365+ # Skip haproxy-router for non-ARM64 architectures (see TODO at line 99)
366+ # haproxy28 package implementation for amd64 is not yet available
367+ if [ " ${TARGET_ARCH} " != " arm64" ] && [ " ${key} " = " haproxy-router" ] ; then
368+ continue
369+ fi
370+
371+ local staging_image=" ${images[$key]/ ${PRODUCTION_REGISTRY} / ${STAGING_REGISTRY} } "
372+ local production_image=" ${images[$key]} "
373+
374+ if ! podman image exists " ${staging_image} " ; then
375+ echo " ERROR: Local staging image ${staging_image} not found."
376+ echo " Run staging build first: $0 staging ${OKD_VERSION} ${OCP_BRANCH} ${TARGET_ARCH} "
377+ exit 1
378+ fi
379+
380+ echo " Re-tagging ${staging_image} to ${production_image} "
381+ podman tag " ${staging_image} " " ${production_image} "
382+ images_sha[" ${key} " ]=" ${production_image} "
383+ done
384+ }
385+
386+ # Staging mode: build images locally and push to staging registry
387+ push_staging () {
388+ check_podman_login
389+ check_release_image_exists
390+ build_okd_images
391+ push_okd_images
392+ echo " "
393+ echo " Images built and pushed to staging registry: ${STAGING_REGISTRY} "
394+ echo " OKD release image available at: ${OKD_RELEASE_IMAGE} "
395+ echo " After successful testing, push to production with:"
396+ echo " $0 production ${OKD_VERSION} ${OCP_BRANCH} ${TARGET_ARCH} "
397+ }
398+
399+ # Production mode: retag staging images and push to production registry
400+ push_production () {
401+ check_podman_login
402+ check_release_image_exists
403+ retag_staging_to_production
404+ push_okd_images
405+ }
406+
407+ # Cleanup mode: delete images from staging registry
408+ cleanup_staging () {
409+ check_podman_login
410+ echo " Cleaning up staging registry images for version ${OKD_VERSION} ..."
411+
412+ for key in " ${! images[@]} " ; do
413+ # Skip haproxy-router for non-ARM64 architectures (see TODO at line 99)
414+ if [ " ${TARGET_ARCH} " != " arm64" ] && [ " ${key} " = " haproxy-router" ] ; then
415+ continue
416+ fi
417+
418+ echo " Deleting: ${images[$key]} "
419+ skopeo delete " docker://${images[$key]} " || true
420+ done
421+
422+ # Delete the OKD release image
423+ echo " Deleting: ${OKD_RELEASE_IMAGE} "
424+ skopeo delete " docker://${OKD_RELEASE_IMAGE} " || true
425+
426+ echo " Staging registry cleanup completed"
427+ }
428+
323429#
324430# Main
325431#
326- if [[ $# -ne 3 ]]; then
432+ if [[ $# -ne 4 ]]; then
327433 usage
328434fi
329435
330- OKD_VERSION=" $1 "
331- OCP_BRANCH=" $2 "
332- TARGET_ARCH=" $3 "
333- OKD_RELEASE_IMAGE=" ${TARGET_REGISTRY} /okd-release-${TARGET_ARCH} :${OKD_VERSION} "
436+ MODE=" $1 "
437+ OKD_VERSION=" $2 "
438+ OCP_BRANCH=" $3 "
439+ TARGET_ARCH=" $4 "
440+
441+ # Validate mode
442+ if [[ " ${MODE} " != " staging" ]] && [[ " ${MODE} " != " production" ]] && [[ " ${MODE} " != " cleanup" ]]; then
443+ echo " ERROR: Invalid mode '${MODE} '. Must be 'staging', 'production', or 'cleanup'"
444+ usage
445+ fi
334446
335447# Determine the alternate architecture
336448case " ${TARGET_ARCH} " in
@@ -346,6 +458,15 @@ case "${TARGET_ARCH}" in
346458 ;;
347459esac
348460
461+ # Set target registry based on mode
462+ if [[ " ${MODE} " == " staging" ]] || [[ " ${MODE} " == " cleanup" ]]; then
463+ TARGET_REGISTRY=" ${STAGING_REGISTRY} "
464+ elif [[ " ${MODE} " == " production" ]]; then
465+ TARGET_REGISTRY=" ${PRODUCTION_REGISTRY} "
466+ fi
467+
468+ OKD_RELEASE_IMAGE=" ${TARGET_REGISTRY} /okd-release-${TARGET_ARCH} :${OKD_VERSION} "
469+
349470# Populate associative arrays with image names and tags
350471declare -A images
351472declare -A images_sha
@@ -368,10 +489,11 @@ images=(
368489
369490# Check the prerequisites
370491check_prereqs
371- check_podman_login
372- check_release_image_exists
373- # Create and push images
374- create_images
375- push_image_manifests
376- # Create a new OKD release
377- create_new_okd_release
492+ # Execute based on mode
493+ if [[ " ${MODE} " == " staging" ]]; then
494+ push_staging
495+ elif [[ " ${MODE} " == " production" ]]; then
496+ push_production
497+ elif [[ " ${MODE} " == " cleanup" ]]; then
498+ cleanup_staging
499+ fi
0 commit comments