Skip to content

Commit 61e7990

Browse files
author
Kasturi Narra
committed
Separate OKD build and push phases
1 parent 89d9917 commit 61e7990

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

.github/actions/build-okd/action.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ runs:
5151
set -euo pipefail
5252
5353
cd ${GITHUB_WORKSPACE}/
54+
# Build images locally without pushing to registry
55+
# This allows testing before publishing
5456
TARGET_REGISTRY="${{ inputs.target-registry }}" ./src/okd/build_images.sh \
5557
"${{ inputs.okd-version-tag }}" \
5658
"${{ inputs.ushift-branch }}" \
@@ -97,6 +99,21 @@ runs:
9799
make run-healthy
98100
make stop
99101
102+
- name: Push OKD images to registry
103+
if: success()
104+
shell: bash
105+
run: |
106+
set -euo pipefail
107+
108+
cd ${GITHUB_WORKSPACE}/
109+
# Only push if all previous steps succeeded
110+
# This ensures we don't publish broken OKD images
111+
TARGET_REGISTRY="${{ inputs.target-registry }}" ./src/okd/build_images.sh \
112+
"${{ inputs.okd-version-tag }}" \
113+
"${{ inputs.ushift-branch }}" \
114+
"${{ inputs.target-arch }}" \
115+
push
116+
100117
# Uncomment this to enable tmate-debug on failure
101118
# - name: Pause and open tmate debug session
102119
# if: failure()

src/okd/build_images.sh

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ WORKDIR=$(mktemp -d /tmp/okd-build-images-XXXXXX)
1111
trap 'cd ; rm -rf "${WORKDIR}"' EXIT
1212

1313
usage() {
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
322325
fi
323326

324327
OKD_VERSION="$1"
325328
OCP_BRANCH="$2"
326329
TARGET_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+
327338
OKD_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
330347
case "${TARGET_ARCH}" in
331348
"amd64")
@@ -362,10 +379,42 @@ images=(
362379

363380
# Check the prerequisites
364381
check_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

Comments
 (0)