Skip to content

Commit 846b22d

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

File tree

2 files changed

+117
-18
lines changed

2 files changed

+117
-18
lines changed

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,31 @@ runs:
4545
with:
4646
token: ${{ inputs.token }}
4747

48-
- name: Build OKD images
48+
- name: Build OKD images and push to staging
4949
shell: bash
5050
run: |
5151
set -euo pipefail
5252
5353
cd ${GITHUB_WORKSPACE}/
54-
TARGET_REGISTRY="${{ inputs.target-registry }}" ./src/okd/build_images.sh \
54+
# Build images locally and push to staging registry for testing
55+
./src/okd/build_images.sh \
56+
build \
5557
"${{ inputs.okd-version-tag }}" \
5658
"${{ inputs.ushift-branch }}" \
5759
"${{ inputs.target-arch }}"
5860
59-
- name: Build MicroShift RPMs
61+
- name: Build MicroShift RPMs using staging OKD images
6062
shell: bash
6163
run: |
6264
# See https://github.com/microshift-io/microshift/blob/main/docs/build.md
6365
# for more information about the build process.
6466
65-
# Run the RPM build process.
67+
# Run the RPM build process using images from staging registry
6668
cd ${GITHUB_WORKSPACE}/
6769
make rpm \
6870
USHIFT_BRANCH="${{ inputs.ushift-branch }}" \
6971
OKD_VERSION_TAG="${{ inputs.okd-version-tag }}" \
70-
OKD_RELEASE_IMAGE="${{ inputs.target-registry }}/okd-release-${{ steps.detect-cpu-arch.outputs.go_arch }}" \
72+
OKD_RELEASE_IMAGE="ghcr.io/microshift-io/okd-staging/okd-release-${{ steps.detect-cpu-arch.outputs.go_arch }}" \
7173
RPM_OUTDIR=/mnt/rpms
7274
7375
- name: Build MicroShift bootc container image
@@ -97,6 +99,30 @@ runs:
9799
make run-healthy
98100
make stop
99101
102+
- name: Push OKD images to production registry
103+
if: success()
104+
shell: bash
105+
run: |
106+
set -euo pipefail
107+
108+
cd ${GITHUB_WORKSPACE}/
109+
# Only push to production if all tests passed
110+
# This ensures we don't publish broken OKD images to production
111+
./src/okd/build_images.sh \
112+
push \
113+
"${{ inputs.okd-version-tag }}" \
114+
"${{ inputs.ushift-branch }}" \
115+
"${{ inputs.target-arch }}"
116+
117+
- name: Cleanup staging registry on failure
118+
if: failure()
119+
shell: bash
120+
continue-on-error: true
121+
run: |
122+
echo "Build or tests failed - staging images were not promoted to production"
123+
echo "Staging registry may contain untested images for version ${{ inputs.okd-version-tag }}"
124+
echo "These will be overwritten on the next build attempt"
125+
100126
# Uncomment this to enable tmate-debug on failure
101127
# - name: Pause and open tmate debug session
102128
# if: failure()

src/okd/build_images.sh

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ 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") <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
322327
fi
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
330341
case "${TARGET_ARCH}" in
@@ -340,6 +351,17 @@ case "${TARGET_ARCH}" in
340351
;;
341352
esac
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
344366
declare -A images
345367
declare -A images_sha
@@ -362,10 +384,61 @@ images=(
362384

363385
# Check the prerequisites
364386
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
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

Comments
 (0)