-
Notifications
You must be signed in to change notification settings - Fork 13
Building RPMs using COPR #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| # 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 | ||
| 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 |
| 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") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate SRPM_WORKDIR before reading build.txt.
Add validation to targets that use .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"
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate SRPM_WORKDIR in copr-create-build. The target mounts 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate SRPM_WORKDIR in copr-watch-build. The target reads 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)" | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle glob expansion failure. If no SRPM files match 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| 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 | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate COPR_BUILD_ID is provided.
COPR_BUILD_IDis required but has an empty default. The script should fail early if not provided.Add validation after the ARG declarations:
🤖 Prompt for AI Agents