@@ -11,10 +11,13 @@ 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 " ) <okd-version> <ocp-branch> <target-arch> [push] "
1515 echo " okd-version: The version of OKD to build (see https://amd64.origin.releases.ci.openshift.org/)"
1616 echo " ocp-branch: The branch of OCP to build (e.g. release-4.19)"
1717 echo " target-arch: The architecture of the target images (amd64 or arm64)"
18+ echo " push: Optional - if specified as 'push', will push previously built images"
19+ echo " "
20+ echo " Default behavior: Build images locally without pushing"
1821 exit 1
1922}
2023
@@ -317,15 +320,29 @@ create_new_okd_release() {
317320#
318321# Main
319322#
320- if [[ $# -ne 3 ]]; then
323+ if [[ $# -lt 3 ]] || [[ $# -gt 4 ]]; then
321324 usage
322325fi
323326
324327OKD_VERSION=" $1 "
325328OCP_BRANCH=" $2 "
326329TARGET_ARCH=" $3 "
330+
331+ # Check if 4th parameter exists (safe with set -u)
332+ if [[ $# -eq 4 ]]; then
333+ MODE=" $4 "
334+ else
335+ MODE=" " # Default: build only
336+ fi
337+
327338OKD_RELEASE_IMAGE=" ${TARGET_REGISTRY} /okd-release-${TARGET_ARCH} :${OKD_VERSION} "
328339
340+ # Validate mode if provided
341+ if [[ -n " ${MODE} " ]] && [[ " ${MODE} " != " push" ]]; then
342+ echo " ERROR: Invalid mode '${MODE} '. Only 'push' is supported"
343+ usage
344+ fi
345+
329346# Determine the alternate architecture
330347case " ${TARGET_ARCH} " in
331348 " amd64" )
@@ -362,10 +379,42 @@ images=(
362379
363380# Check the prerequisites
364381check_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
382+
383+ # Execute based on mode
384+ if [[ -z " ${MODE} " ]]; then
385+ # Default: Build only (no push)
386+ # Note: Not checking if release image exists in registry since we're building
387+ # locally for testing. The push phase will handle the final release.
388+ create_images
389+ echo " "
390+ echo " Build completed successfully"
391+ echo " Images are available locally and ready for testing."
392+ echo " To push these images after testing, run:"
393+ echo " $0 ${OKD_VERSION} ${OCP_BRANCH} ${TARGET_ARCH} push"
394+
395+ else
396+ # Push mode: Push previously built images
397+ # Note: Assumes podman login was already done externally (e.g., by CI/CD workflow)
398+
399+ # Verify all local images exist and populate images_sha array
400+ for key in " ${! images[@]} " ; do
401+ if [ " ${TARGET_ARCH} " != " arm64" ] && [ " ${key} " = " haproxy-router" ] ; then
402+ continue
403+ fi
404+
405+ # Check if local image exists
406+ if ! podman image exists " ${images[$key]} " ; then
407+ echo " ERROR: Local image ${images[$key]} not found."
408+ echo " Run build first: $0 ${OKD_VERSION} ${OCP_BRANCH} ${TARGET_ARCH} "
409+ exit 1
410+ fi
411+
412+ # Populate images_sha array with local image reference
413+ images_sha[" ${key} " ]=" ${images[$key]} "
414+ done
415+
416+ push_image_manifests
417+ create_new_okd_release
418+ echo " Push completed successfully"
419+ echo " OKD release image published to: ${OKD_RELEASE_IMAGE} "
420+ fi
0 commit comments