Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ else
OKD_RELEASE_IMAGE ?= $(OKD_RELEASE_IMAGE_X86_64)
endif

BUILDER_IMAGE := microshift-okd-builder
BUILDER_IMAGE ?= microshift-okd-builder
USHIFT_IMAGE := microshift-okd
SRPM_IMAGE := microshift-okd-srpm
LVM_DISK := /var/lib/microshift-okd/lvmdisk.image
VG_NAME := myvg1

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
include $(PROJECT_DIR)/src/copr/copr.mk

#
# Define the main targets
#
Expand Down Expand Up @@ -113,8 +116,8 @@ rpm-to-deb:

.PHONY: image
image:
@if ! sudo podman image exists microshift-okd-builder ; then \
echo "ERROR: Run 'make rpm' to build the MicroShift RPMs" ; \
@if ! sudo podman image exists "${BUILDER_IMAGE}" ; then \
echo "ERROR: Run 'make rpm' or 'make rpm-copr' to build the MicroShift RPMs" ; \
exit 1 ; \
fi

Expand All @@ -126,6 +129,7 @@ image:
--label okd.version="${OKD_VERSION_TAG}" \
--build-arg BOOTC_IMAGE_URL="${BOOTC_IMAGE_URL}" \
--build-arg BOOTC_IMAGE_TAG="${BOOTC_IMAGE_TAG}" \
--build-arg RPM_BUILDER_IMAGE="${BUILDER_IMAGE}" \
--env WITH_KINDNET="${WITH_KINDNET}" \
--env WITH_TOPOLVM="${WITH_TOPOLVM}" \
--env WITH_OLM="${WITH_OLM}" \
Expand Down
3 changes: 2 additions & 1 deletion packaging/microshift-runner.Containerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Optionally allow for the base image override
ARG BOOTC_IMAGE_URL=quay.io/centos-bootc/centos-bootc
ARG BOOTC_IMAGE_TAG=stream9
ARG RPM_BUILDER_IMAGE=microshift-okd-builder

FROM localhost/microshift-okd-builder:latest AS builder
FROM localhost/${RPM_BUILDER_IMAGE}:latest AS builder
FROM ${BOOTC_IMAGE_URL}:${BOOTC_IMAGE_TAG}

ARG REPO_CONFIG_SCRIPT=/tmp/create_repos.sh
Expand Down
23 changes: 23 additions & 0 deletions packaging/rpms-copr.Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM quay.io/fedora/fedora:42

RUN dnf install -y \
--setopt=install_weak_deps=False \
copr-cli createrepo rpm2cpio cpio && \
dnf clean all

ARG COPR_BUILD_ID=
ARG BUILDER_RPM_REPO_PATH=/home/microshift/microshift/_output/rpmbuild/RPMS
Comment on lines +8 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate COPR_BUILD_ID is provided.

COPR_BUILD_ID is required but has an empty default. The script should fail early if not provided.

Add validation after the ARG declarations:

 ARG COPR_BUILD_ID=
 ARG BUILDER_RPM_REPO_PATH=/home/microshift/microshift/_output/rpmbuild/RPMS
 
+RUN if [ -z "${COPR_BUILD_ID}" ]; then \
+        echo "ERROR: COPR_BUILD_ID build argument is required" >&2; \
+        exit 1; \
+    fi
+
 # hadolint ignore=DL3003,DL4006,SC3040

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packaging/rpms-copr.Containerfile around lines 8 to 9, ARG COPR_BUILD_ID is
declared with an empty default but is required; add a validation immediately
after the ARG declarations that checks if COPR_BUILD_ID is empty and, if so,
prints a clear error message and exits non‑zero to fail the build early (e.g.,
test the variable and call exit 1). Ensure the validation runs during image
build so the Docker/Cool variant fails fast when COPR_BUILD_ID is not provided.


# hadolint ignore=DL3003,DL4006,SC3040
RUN <<EOT bash
set -xeuo pipefail
copr download-build --rpms --chroot "epel-9-$(uname -m)" --dest /tmp/rpms ${COPR_BUILD_ID}
mkdir -p /home/microshift/microshift
cd /tmp/rpms/"epel-9-$(uname -m)"/
rpm2cpio microshift-*.src.rpm | cpio -idmv
tar xf microshift-*.tar.gz -C /home/microshift/microshift --strip-components=1
mkdir -p ${BUILDER_RPM_REPO_PATH}
mv /tmp/rpms/"epel-9-$(uname -m)"/*.rpm ${BUILDER_RPM_REPO_PATH}/
createrepo -v ${BUILDER_RPM_REPO_PATH}
rm -rf /tmp/rpms
EOT
3 changes: 3 additions & 0 deletions src/copr/copr-cli.Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM quay.io/fedora/fedora:42

RUN dnf install -y copr-cli && dnf clean all
104 changes: 104 additions & 0 deletions src/copr/copr.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
COPR_CONFIG ?= $(HOME)/.config/copr
COPR_REPO_NAME ?= "@microshift-io/microshift"
COPR_BUILD_ID ?= $$(cat "${SRPM_WORKDIR}/build.txt")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate SRPM_WORKDIR before reading build.txt.

COPR_BUILD_ID reads from ${SRPM_WORKDIR}/build.txt but SRPM_WORKDIR may not be set or the file may not exist. Targets using COPR_BUILD_ID should validate this.

Add validation to targets that use COPR_BUILD_ID:

 .PHONY: rpm-copr
 rpm-copr:
+	@if [ -z "${SRPM_WORKDIR}" ]; then \
+		echo "ERROR: SRPM_WORKDIR is not set" ; \
+		exit 1 ; \
+	fi
+	@if [ ! -f "${SRPM_WORKDIR}/build.txt" ]; then \
+		echo "ERROR: ${SRPM_WORKDIR}/build.txt not found. Run 'make copr-create-build' first" ; \
+		exit 1 ; \
+	fi
 	@echo "Building MicroShift RPM image using COPR"

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/copr/copr.mk around line 3, COPR_BUILD_ID is unconditionally defined by
reading "${SRPM_WORKDIR}/build.txt" which can fail if SRPM_WORKDIR is unset or
the file doesn't exist; update the Makefile so targets that use COPR_BUILD_ID
first validate SRPM_WORKDIR is set and that "${SRPM_WORKDIR}/build.txt" exists
before attempting to read it, and emit a clear make error (or skip/handle
gracefully) if validation fails; implement this by moving the file-read into a
recipe or guarded shell expression used by those targets (or by making
COPR_BUILD_ID empty by default and having targets perform a check using test -n
and test -f and failing with @echo and exit 1 when missing).


COPR_SECRET_NAME := copr-cfg
COPR_BUILDER_IMAGE := rpm-copr-builder
COPR_CLI_IMAGE := localhost/copr-cli:latest


.PHONY: copr-help
copr-help:
@echo "make <rpm-copr | copr-delete-build | copr-regenerate-repos | copr-create-build | copr-watch-build>"
@echo " rpm-copr: build the MicroShift RPMs using COPR"
@echo " copr-delete-build: delete the COPR build"
@echo " copr-regenerate-repos: regenerate the COPR RPM repository"
@echo " copr-create-build: create the COPR RPM build"
@echo " copr-watch-build: watch the COPR build"
@echo " copr-cfg-ensure-podman-secret: ensure the COPR secret is available and is up to date"
@echo " copr-cli: build the COPR CLI container"
@echo ""
@echo "Variables:"
@echo " COPR_BUILD_ID: COPR build ID (default: read from \$$SRPM_WORKDIR/build.txt)"
@echo " COPR_REPO_NAME: COPR repository name (default: ${COPR_REPO_NAME})"
@echo " COPR_CONFIG: COPR configuration file - from https://copr.fedorainfracloud.org/api/ (default: ${COPR_CONFIG})"
@echo ""
@echo "Recommended flow:"
@echo " 1. mkdir -p /tmp/microshift-srpm-copr"
@echo " 2. make srpm SRPM_WORKDIR=/tmp/microshift-srpm-copr"
@echo " 3. make copr-create-build COPR_REPO_NAME=USER/PROJECT SRPM_WORKDIR=/tmp/microshift-srpm-copr"
@echo " 4. make copr-watch-build SRPM_WORKDIR=/tmp/microshift-srpm-copr"
@echo " 5. make rpm-copr SRPM_WORKDIR=/tmp/microshift-srpm-copr"
@echo " 6. make image BUILDER_IMAGE=rpm-copr-builder"
@echo ""

.PHONY: rpm-copr
rpm-copr:
@echo "Building MicroShift RPM image using COPR"
sudo podman build \
--tag "${COPR_BUILDER_IMAGE}" \
--build-arg COPR_BUILD_ID="${COPR_BUILD_ID}" \
--file packaging/rpms-copr.Containerfile .

@echo "Extracting the MicroShift RPMs"
outdir="$${RPM_OUTDIR:-$$(mktemp -d /tmp/microshift-rpms-XXXXXX)}" && \
mntdir="$$(sudo podman image mount "${COPR_BUILDER_IMAGE}")" && \
sudo cp -r "$${mntdir}/home/microshift/microshift/_output/rpmbuild/RPMS/." "$${outdir}" && \
sudo podman image umount "${COPR_BUILDER_IMAGE}" && \
echo "" && \
echo "Build completed successfully" && \
echo "RPMs are available in '$${outdir}'"

.PHONY: copr-cfg-ensure-podman-secret
copr-cfg-ensure-podman-secret:
@echo "Ensuring the COPR secret is available and is up to date"
if sudo podman secret exists "${COPR_SECRET_NAME}"; then \
sudo podman secret rm "${COPR_SECRET_NAME}" ; \
fi ; \
sudo podman secret create "${COPR_SECRET_NAME}" "${COPR_CONFIG}"

.PHONY: copr-cli
copr-cli:
@echo "Building the COPR CLI container"
sudo podman build \
--tag "${COPR_CLI_IMAGE}" \
--file src/copr/copr-cli.Containerfile .

.PHONY: copr-delete-build
copr-delete-build: copr-cfg-ensure-podman-secret copr-cli
@echo "Deleting the COPR build ${COPR_BUILD_ID}"
sudo podman run \
--rm \
--secret ${COPR_SECRET_NAME} \
"${COPR_CLI_IMAGE}" \
bash -c "copr-cli --config /run/secrets/copr-cfg delete-build ${COPR_BUILD_ID}"

.PHONY: copr-regenerate-repos
copr-regenerate-repos: copr-cfg-ensure-podman-secret copr-cli
@echo "Regenerating the COPR repository"
sudo podman run \
--rm \
--secret ${COPR_SECRET_NAME} \
"${COPR_CLI_IMAGE}" \
bash -c "copr-cli --config /run/secrets/copr-cfg regenerate-repos ${COPR_REPO_NAME}"

.PHONY: copr-create-build
copr-create-build: copr-cfg-ensure-podman-secret copr-cli
@echo "Creating the COPR build"
sudo podman run \
--rm \
--secret ${COPR_SECRET_NAME} \
--env COPR_REPO_NAME="${COPR_REPO_NAME}" \
--volume "${SRPM_WORKDIR}:/srpms:Z" \
--volume "./src/copr/create-build.sh:/create-build.sh:Z" \
"${COPR_CLI_IMAGE}" \
bash -c "bash -x /create-build.sh"

Comment on lines +85 to +96
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate SRPM_WORKDIR in copr-create-build.

The target mounts ${SRPM_WORKDIR} but doesn't validate it's set or that the directory exists.

Add validation at the start of the target:

 .PHONY: copr-create-build
 copr-create-build: copr-cfg-ensure-podman-secret copr-cli
+	@if [ -z "${SRPM_WORKDIR}" ]; then \
+		echo "ERROR: SRPM_WORKDIR is not set" ; \
+		exit 1 ; \
+	fi
+	@if [ ! -d "${SRPM_WORKDIR}" ]; then \
+		echo "ERROR: ${SRPM_WORKDIR} directory not found" ; \
+		exit 1 ; \
+	fi
 	@echo "Creating the COPR build"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.PHONY: copr-create-build
copr-create-build: copr-cfg-ensure-podman-secret copr-cli
@echo "Creating the COPR build"
sudo podman run \
--rm \
--secret ${COPR_SECRET_NAME} \
--env COPR_REPO_NAME="${COPR_REPO_NAME}" \
--volume "${SRPM_WORKDIR}:/srpms:Z" \
--volume "./src/copr/create-build.sh:/create-build.sh:Z" \
"${COPR_CLI_IMAGE}" \
bash -c "bash -x /create-build.sh"
.PHONY: copr-create-build
copr-create-build: copr-cfg-ensure-podman-secret copr-cli
@if [ -z "${SRPM_WORKDIR}" ]; then \
echo "ERROR: SRPM_WORKDIR is not set" ; \
exit 1 ; \
fi
@if [ ! -d "${SRPM_WORKDIR}" ]; then \
echo "ERROR: ${SRPM_WORKDIR} directory not found" ; \
exit 1 ; \
fi
@echo "Creating the COPR build"
sudo podman run \
--rm \
--secret ${COPR_SECRET_NAME} \
--env COPR_REPO_NAME="${COPR_REPO_NAME}" \
--volume "${SRPM_WORKDIR}:/srpms:Z" \
--volume "./src/copr/create-build.sh:/create-build.sh:Z" \
"${COPR_CLI_IMAGE}" \
bash -c "bash -x /create-build.sh"
🤖 Prompt for AI Agents
In src/copr/copr.mk around lines 85 to 96, the copr-create-build target mounts
${SRPM_WORKDIR} but does not validate that SRPM_WORKDIR is set or that the
directory exists; add a validation at the start of the target that (1) verifies
the SRPM_WORKDIR variable is non-empty and (2) verifies the path exists and is a
directory, and if either check fails, print a clear error to stderr and exit the
recipe with a non-zero status so the make target aborts before running podman.
Use simple shell checks (e.g., [ -n "${SRPM_WORKDIR}" ] and [ -d
"${SRPM_WORKDIR}" ]) and ensure the error message references the variable name
and the failing condition.

.PHONY: copr-watch-build
copr-watch-build: copr-cli
@echo "Watching the COPR build"
sudo podman run \
--rm \
--volume "${SRPM_WORKDIR}:/srpms:Z" \
"${COPR_CLI_IMAGE}" \
bash -c "copr-cli watch-build \$$(cat /srpms/build.txt)"
Comment on lines +97 to +104
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate SRPM_WORKDIR in copr-watch-build.

The target reads ${SRPM_WORKDIR}/build.txt but doesn't validate the directory or file exists.

Add validation:

 .PHONY: copr-watch-build
 copr-watch-build: copr-cli
+	@if [ -z "${SRPM_WORKDIR}" ]; then \
+		echo "ERROR: SRPM_WORKDIR is not set" ; \
+		exit 1 ; \
+	fi
+	@if [ ! -f "${SRPM_WORKDIR}/build.txt" ]; then \
+		echo "ERROR: ${SRPM_WORKDIR}/build.txt not found. Run 'make copr-create-build' first" ; \
+		exit 1 ; \
+	fi
 	@echo "Watching the COPR build"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.PHONY: copr-watch-build
copr-watch-build: copr-cli
@echo "Watching the COPR build"
sudo podman run \
--rm \
--volume "${SRPM_WORKDIR}:/srpms:Z" \
"${COPR_CLI_IMAGE}" \
bash -c "copr-cli watch-build \$$(cat /srpms/build.txt)"
.PHONY: copr-watch-build
copr-watch-build: copr-cli
@if [ -z "${SRPM_WORKDIR}" ]; then \
echo "ERROR: SRPM_WORKDIR is not set" ; \
exit 1 ; \
fi
@if [ ! -f "${SRPM_WORKDIR}/build.txt" ]; then \
echo "ERROR: ${SRPM_WORKDIR}/build.txt not found. Run 'make copr-create-build' first" ; \
exit 1 ; \
fi
@echo "Watching the COPR build"
sudo podman run \
--rm \
--volume "${SRPM_WORKDIR}:/srpms:Z" \
"${COPR_CLI_IMAGE}" \
bash -c "copr-cli watch-build \$$(cat /srpms/build.txt)"
🤖 Prompt for AI Agents
In src/copr/copr.mk around lines 97 to 104, the copr-watch-build target uses
${SRPM_WORKDIR}/build.txt without validating that SRPM_WORKDIR exists or that
build.txt is present; add a check before running podman that SRPM_WORKDIR is a
directory and that "${SRPM_WORKDIR}/build.txt" is a readable file, printing a
clear error and exiting with non‑zero status if either check fails, then proceed
to run the podman command only when both checks pass.

11 changes: 11 additions & 0 deletions src/copr/create-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail

out="$(copr-cli --config /run/secrets/copr-cfg build --nowait "${COPR_REPO_NAME}" /srpms/microshift*.src.rpm)"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Handle glob expansion failure.

If no SRPM files match microshift*.src.rpm, the command will fail with an unclear error.

Apply this diff to validate the SRPM exists:

+if ! ls /srpms/microshift*.src.rpm 1> /dev/null 2>&1; then
+    echo "ERROR: No SRPM files found matching /srpms/microshift*.src.rpm"
+    exit 1
+fi
+
 out="$(copr-cli --config /run/secrets/copr-cfg build --nowait "${COPR_REPO_NAME}" /srpms/microshift*.src.rpm)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
out="$(copr-cli --config /run/secrets/copr-cfg build --nowait "${COPR_REPO_NAME}" /srpms/microshift*.src.rpm)"
if ! ls /srpms/microshift*.src.rpm 1> /dev/null 2>&1; then
echo "ERROR: No SRPM files found matching /srpms/microshift*.src.rpm"
exit 1
fi
out="$(copr-cli --config /run/secrets/copr-cfg build --nowait "${COPR_REPO_NAME}" /srpms/microshift*.src.rpm)"
🤖 Prompt for AI Agents
In src/copr/create-build.sh around line 4, the copr-cli command assumes the glob
/srpms/microshift*.src.rpm expands to at least one file; if it doesn't the
command fails with an unclear error. Before invoking copr-cli, test whether any
files match that glob (e.g., capture the glob expansion into a variable or
array, check its length), and if none are found print a clear error and exit
non‑zero; otherwise pass the expanded file path(s) to copr-cli (properly
quoted/iterated to handle spaces) so the command only runs when SRPM(s) actually
exist.

echo "${out}"
build=$(echo "${out}" | grep "Created builds" | cut -d: -f2 | xargs)
if [[ -z "${build}" ]]; then
echo "ERROR: Failed to extract build ID from copr-cli output"
exit 1
fi
echo "${build}" > /srpms/build.txt
Loading