@@ -11,7 +11,12 @@ WORKDIR=$(mktemp -d /tmp/okd-build-images-XXXXXX)
1111trap ' cd ; rm -rf "${WORKDIR}"' EXIT
1212
1313usage () {
14- echo " Usage: $( basename " $0 " ) <okd-version> <ocp-branch> <target-arch>"
14+ echo " Usage: $( basename " $0 " ) <mode> <okd-version> <ocp-branch> <target-arch>"
15+ echo " mode: Operation mode - 'build' or 'push'"
16+ echo " 'build' - Build OKD images locally and push to staging registry"
17+ echo " (${STAGING_REGISTRY} )"
18+ echo " 'push' - Push previously built images to production registry"
19+ echo " (${PRODUCTION_REGISTRY} )"
1520 echo " okd-version: The version of OKD to build (see https://amd64.origin.releases.ci.openshift.org/)"
1621 echo " ocp-branch: The branch of OCP to build (e.g. release-4.19)"
1722 echo " target-arch: The architecture of the target images (amd64 or arm64)"
@@ -317,14 +322,20 @@ create_new_okd_release() {
317322#
318323# Main
319324#
320- if [[ $# -ne 3 ]]; then
325+ if [[ $# -ne 4 ]]; then
321326 usage
322327fi
323328
324- OKD_VERSION=" $1 "
325- OCP_BRANCH=" $2 "
326- TARGET_ARCH=" $3 "
327- OKD_RELEASE_IMAGE=" ${TARGET_REGISTRY} /okd-release-${TARGET_ARCH} :${OKD_VERSION} "
329+ MODE=" $1 "
330+ OKD_VERSION=" $2 "
331+ OCP_BRANCH=" $3 "
332+ TARGET_ARCH=" $4 "
333+
334+ # Validate mode
335+ if [[ " ${MODE} " != " build" ]] && [[ " ${MODE} " != " push" ]]; then
336+ echo " ERROR: Invalid mode '${MODE} '. Must be 'build' or 'push'"
337+ usage
338+ fi
328339
329340# Determine the alternate architecture
330341case " ${TARGET_ARCH} " in
@@ -340,6 +351,17 @@ case "${TARGET_ARCH}" in
340351 ;;
341352esac
342353
354+ # Set registry based on mode
355+ if [[ " ${MODE} " == " build" ]]; then
356+ # For build mode, we build locally and then push to staging
357+ TARGET_REGISTRY=" ${STAGING_REGISTRY} "
358+ elif [[ " ${MODE} " == " push" ]]; then
359+ # For push mode, we push to production
360+ TARGET_REGISTRY=" ${PRODUCTION_REGISTRY} "
361+ fi
362+
363+ OKD_RELEASE_IMAGE=" ${TARGET_REGISTRY} /okd-release-${TARGET_ARCH} :${OKD_VERSION} "
364+
343365# Populate associative arrays with image names and tags
344366declare -A images
345367declare -A images_sha
@@ -362,10 +384,61 @@ images=(
362384
363385# Check the prerequisites
364386check_prereqs
365- check_podman_login
366- check_release_image_exists
367- # Create and push images
368- create_images
369- push_image_manifests
370- # Create a new OKD release
371- create_new_okd_release
387+
388+ # Execute based on mode
389+ if [[ " ${MODE} " == " build" ]]; then
390+ # Build mode: Build images locally and push to staging registry
391+ create_images
392+
393+ # Populate images_sha array from local images
394+ for key in " ${! images[@]} " ; do
395+ # Skip haproxy-router for non-ARM64 architectures (see TODO at line 93)
396+ # haproxy28 package implementation for amd64 is not yet available
397+ if [ " ${TARGET_ARCH} " != " arm64" ] && [ " ${key} " = " haproxy-router" ] ; then
398+ continue
399+ fi
400+ images_sha[" ${key} " ]=" ${images[$key]} "
401+ done
402+
403+ # Push images to staging registry
404+ push_image_manifests
405+
406+ # Create the OKD release image in staging registry
407+ create_new_okd_release
408+
409+ echo " "
410+ echo " Build completed successfully"
411+ echo " Images built and pushed to staging registry: ${STAGING_REGISTRY} "
412+ echo " OKD release image available at: ${OKD_RELEASE_IMAGE} "
413+ echo " After successful testing, push to production with:"
414+ echo " $0 push ${OKD_VERSION} ${OCP_BRANCH} ${TARGET_ARCH} "
415+
416+ elif [[ " ${MODE} " == " push" ]]; then
417+ # Push mode: Push previously built images to production registry
418+ # This should only be done after successful testing with staging images
419+ # Note: Assumes podman login was already done externally (e.g., by CI/CD workflow)
420+
421+ # Verify all local images exist and populate images_sha array
422+ for key in " ${! images[@]} " ; do
423+ # Skip haproxy-router for non-ARM64 architectures (see TODO at line 93)
424+ # haproxy28 package implementation for amd64 is not yet available
425+ if [ " ${TARGET_ARCH} " != " arm64" ] && [ " ${key} " = " haproxy-router" ] ; then
426+ continue
427+ fi
428+
429+ # Check if local image exists
430+ if ! podman image exists " ${images[$key]} " ; then
431+ echo " ERROR: Local image ${images[$key]} not found."
432+ echo " Run build first: $0 build ${OKD_VERSION} ${OCP_BRANCH} ${TARGET_ARCH} "
433+ exit 1
434+ fi
435+
436+ # Populate images_sha array with local image reference
437+ images_sha[" ${key} " ]=" ${images[$key]} "
438+ done
439+
440+ push_image_manifests
441+ create_new_okd_release
442+ echo " Push to production completed successfully"
443+ echo " OKD release image published to: ${OKD_RELEASE_IMAGE} "
444+ fi
0 commit comments