-
Notifications
You must be signed in to change notification settings - Fork 220
USHIFT-4025: Implement MicroShift image mode container build procedure #3749
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
Merged
openshift-merge-bot
merged 6 commits into
openshift:main
from
ggiguash:image_mode_builds
Sep 4, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c47639c
Implement MicroShift image mode container build procedure
ggiguash 2f74c82
Fix hadolint warnings
ggiguash 1dcef3e
Add phony to all Makefile targets
ggiguash 7b8dcfe
Use systemd unit file for microshift-make-rshared.service
ggiguash d7307ce
Add repobase make target and docs
ggiguash 34bcd9d
Fix clean target to delete specific images
ggiguash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ARG BASE_IMAGE_URL | ||
| ARG BASE_IMAGE_TAG | ||
| FROM ${BASE_IMAGE_URL}:${BASE_IMAGE_TAG} | ||
|
|
||
| RUN dnf upgrade -y && \ | ||
| dnf install -y firewalld microshift && \ | ||
| systemctl enable microshift && \ | ||
| dnf clean all | ||
|
|
||
| # Mandatory firewall configuration | ||
| RUN firewall-offline-cmd --zone=public --add-port=22/tcp && \ | ||
| firewall-offline-cmd --zone=trusted --add-source=10.42.0.0/16 && \ | ||
| firewall-offline-cmd --zone=trusted --add-source=169.254.169.1 | ||
|
|
||
| # Create a systemd unit to recursively make the root filesystem subtree | ||
| # shared as required by OVN images | ||
| COPY ./systemd/microshift-make-rshared.service /etc/systemd/system/microshift-make-rshared.service | ||
| RUN systemctl enable microshift-make-rshared.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ARG BASE_IMAGE_URL | ||
| ARG BASE_IMAGE_TAG | ||
| FROM ${BASE_IMAGE_URL}:${BASE_IMAGE_TAG} | ||
|
|
||
| ARG USHIFT_VER | ||
| ARG USHIFT_URL | ||
| ARG OCPDEP_URL | ||
| ARG USHIFT_REPO="microshift-${USHIFT_VER}-repository" | ||
| ARG OCPDEP_REPO="openshift-${USHIFT_VER}-dependencies" | ||
|
|
||
| RUN cat > "/etc/yum.repos.d/${USHIFT_REPO}.repo" <<EOF | ||
| [${USHIFT_REPO}] | ||
| name=MicroShift ${USHIFT_VER} Repository | ||
| baseurl=${USHIFT_URL} | ||
| gpgcheck=0 | ||
| enabled=1 | ||
| EOF | ||
|
|
||
| # hadolint ignore=DL3059 | ||
| RUN cat > "/etc/yum.repos.d/${OCPDEP_REPO}.repo" <<EOF | ||
| [${OCPDEP_REPO}] | ||
| name=OpenShift ${USHIFT_VER} Dependencies | ||
| baseurl=${OCPDEP_URL} | ||
| gpgcheck=0 | ||
| enabled=1 | ||
| EOF | ||
|
|
||
| RUN dnf upgrade -y && \ | ||
| dnf install -y firewalld microshift && \ | ||
| systemctl enable microshift && \ | ||
| dnf clean all | ||
|
|
||
| # Mandatory firewall configuration | ||
| RUN firewall-offline-cmd --zone=public --add-port=22/tcp && \ | ||
| firewall-offline-cmd --zone=trusted --add-source=10.42.0.0/16 && \ | ||
| firewall-offline-cmd --zone=trusted --add-source=169.254.169.1 | ||
|
|
||
| # Create a systemd unit to recursively make the root filesystem subtree | ||
| # shared as required by OVN images | ||
| COPY ./systemd/microshift-make-rshared.service /etc/systemd/system/microshift-make-rshared.service | ||
| RUN systemctl enable microshift-make-rshared.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ARG BASE_IMAGE_URL | ||
| ARG BASE_IMAGE_TAG | ||
| FROM ${BASE_IMAGE_URL}:${BASE_IMAGE_TAG} | ||
|
|
||
| ARG USHIFT_VER | ||
| RUN dnf config-manager \ | ||
| --set-enabled "rhocp-${USHIFT_VER}-for-rhel-9-$(uname -m)-rpms" \ | ||
| --set-enabled "fast-datapath-for-rhel-9-$(uname -m)-rpms" && \ | ||
| dnf upgrade -y && \ | ||
| dnf install -y firewalld microshift && \ | ||
| systemctl enable microshift && \ | ||
| dnf clean all | ||
|
|
||
| # Mandatory firewall configuration | ||
| RUN firewall-offline-cmd --zone=public --add-port=22/tcp && \ | ||
| firewall-offline-cmd --zone=trusted --add-source=10.42.0.0/16 && \ | ||
| firewall-offline-cmd --zone=trusted --add-source=169.254.169.1 | ||
|
|
||
| # Create a systemd unit to recursively make the root filesystem subtree | ||
| # shared as required by OVN images | ||
| COPY ./systemd/microshift-make-rshared.service /etc/systemd/system/microshift-make-rshared.service | ||
| RUN systemctl enable microshift-make-rshared.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| # | ||
| # The following variables can be overriden from the command line | ||
| # using NAME=value make arguments | ||
| # | ||
| PULL_SECRET ?= $(HOME)/.pull-secret.json | ||
| BASE_IMAGE_URL ?= registry.redhat.io/rhel9/rhel-bootc | ||
| BASE_IMAGE_TAG ?= 9.4 | ||
|
|
||
| # | ||
| # Define the main targets | ||
| # | ||
| .PHONY: all | ||
| all: | ||
| @echo "make [rhocp | repourl | repobase | <build_ver> | run | clean]" | ||
| @echo " rhocp: build a MicroShift bootc image using 'rhocp' repository packages" | ||
| @echo " with versions specified as 'USHIFT_VER=value'" | ||
| @echo " repourl: build a MicroShift bootc image using custom repository URLs" | ||
| @echo " specified as 'USHIFT_URL=value' and 'OCPDEP_URL=value'" | ||
| @echo " repobase: build a MicroShift bootc image using preconfigured repositories" | ||
| @echo " from the base image specified as 'BASE_IMAGE_URL=value' and" | ||
| @echo " 'BASE_IMAGE_TAG=value'. The produced image version should also" | ||
| @echo " be provided as 'IMAGE_VER=value' in this case." | ||
| @echo " <build_ver>: build a MicroShift bootc image of a specific version from the" | ||
| @echo " available predefined configurations listed below" | ||
| @echo " run: run the 'localhost/microshift-\$${IMAGE_VER}' bootc image version" | ||
| @echo " specified as 'IMAGE_VER=value'" | ||
| @echo " stop: stop all running 'microshift-*' containers" | ||
| @echo " clean: delete all 'localhost/microshift-*' container images" | ||
| @echo "" | ||
| @echo "Available build versions:" | ||
| @$(MAKE) -qp | awk -F':' '/^4.[^\t]*:([^=]|$$)/ {print " " $$1}' | sort -u | ||
|
|
||
| .PHONY: rhocp | ||
| rhocp: | ||
| ifndef USHIFT_VER | ||
| $(error Run 'make rhocp USHIFT_VER=value') | ||
| endif | ||
| IMAGE_VER=$$(sudo dnf repoquery microshift \ | ||
| --quiet \ | ||
| --queryformat '%{version}' \ | ||
| --repo "rhocp-${USHIFT_VER}-for-rhel-9-$$(uname -m)-rpms" \ | ||
| --latest-limit 1) ; \ | ||
| IMAGE_NAME="microshift-$${IMAGE_VER}" ; \ | ||
| sudo podman build \ | ||
| --no-cache \ | ||
| --authfile "${PULL_SECRET}" \ | ||
| --build-arg BASE_IMAGE_URL=${BASE_IMAGE_URL} \ | ||
| --build-arg BASE_IMAGE_TAG=${BASE_IMAGE_TAG} \ | ||
| --build-arg USHIFT_VER=$${USHIFT_VER} \ | ||
| -t "$${IMAGE_NAME}" \ | ||
| -f Containerfile.rhocp | ||
|
|
||
| .PHONY: repourl | ||
| repourl: | ||
| ifndef USHIFT_URL | ||
| $(error Run 'make repourl USHIFT_URL=value OCPDEP_URL=value') | ||
| endif | ||
| ifndef OCPDEP_URL | ||
| $(error Run 'make repourl USHIFT_URL=value OCPDEP_URL=value') | ||
| endif | ||
| IMAGE_VER=$$(sudo dnf repoquery microshift \ | ||
| --quiet \ | ||
| --queryformat '%{version}' \ | ||
| --disablerepo '*' \ | ||
| --repofrompath "this,${USHIFT_URL}" \ | ||
| --latest-limit 1 | sed 's/~/-/g') ; \ | ||
| IMAGE_NAME="microshift-$${IMAGE_VER}" ; \ | ||
| sudo podman build \ | ||
| --no-cache \ | ||
| --authfile "${PULL_SECRET}" \ | ||
| --build-arg BASE_IMAGE_URL=${BASE_IMAGE_URL} \ | ||
| --build-arg BASE_IMAGE_TAG=${BASE_IMAGE_TAG} \ | ||
| --build-arg USHIFT_VER=$${IMAGE_VER} \ | ||
| --build-arg USHIFT_URL=$${USHIFT_URL} \ | ||
| --build-arg OCPDEP_URL=$${OCPDEP_URL} \ | ||
| -t "$${IMAGE_NAME}" \ | ||
| -f Containerfile.repourl | ||
|
|
||
| .PHONY: repobase | ||
| repobase: | ||
| ifndef BASE_IMAGE_URL | ||
| $(error Run 'make repobase BASE_IMAGE_URL=value BASE_IMAGE_TAG=value IMAGE_VER=value') | ||
| endif | ||
| ifndef BASE_IMAGE_TAG | ||
| $(error Run 'make repobase BASE_IMAGE_URL=value BASE_IMAGE_TAG=value IMAGE_VER=value') | ||
| endif | ||
| ifndef IMAGE_VER | ||
| $(error Run 'make repobase BASE_IMAGE_URL=value BASE_IMAGE_TAG=value IMAGE_VER=value') | ||
| endif | ||
| IMAGE_NAME="microshift-$${IMAGE_VER}" ; \ | ||
| sudo podman build \ | ||
| --no-cache \ | ||
| --authfile "${PULL_SECRET}" \ | ||
| --build-arg BASE_IMAGE_URL=${BASE_IMAGE_URL} \ | ||
| --build-arg BASE_IMAGE_TAG=${BASE_IMAGE_TAG} \ | ||
| -t "$${IMAGE_NAME}" \ | ||
| -f Containerfile.repobase | ||
|
|
||
| .PHONY: run | ||
| run: | ||
| ifndef IMAGE_VER | ||
| $(error Run 'make run IMAGE_VER=value') | ||
| endif | ||
| IMAGE_NAME="microshift-${IMAGE_VER}" ; \ | ||
| sudo modprobe openvswitch ; \ | ||
| CONT_ID=$$(sudo podman run --rm -d --privileged \ | ||
| -v "${PULL_SECRET}":/etc/crio/openshift-pull-secret:ro \ | ||
| -v /var/lib/containers/storage:/var/lib/containers/storage \ | ||
| --replace \ | ||
| --name "$${IMAGE_NAME}" \ | ||
| "localhost/$${IMAGE_NAME}") ; \ | ||
| echo "sudo podman exec -it $${CONT_ID} bash" | ||
|
|
||
| .PHONY: stop | ||
| stop: | ||
| CONT_IDS=$$(sudo podman ps --format "{{.Names}}" | grep '^microshift-' || true) ; \ | ||
| if [ -n "$${CONT_IDS}" ] ; then sudo podman stop $${CONT_IDS} ; fi | ||
|
|
||
| .PHONY: clean | ||
| clean: | ||
| IMAGES=$$(sudo podman images --format "{{.Repository}}" | grep ^localhost/microshift- || true) ; \ | ||
| if [ -n "$${IMAGES}" ] ; then sudo podman rmi -f $${IMAGES} ; fi | ||
|
|
||
| # | ||
| # Predefined container image builds | ||
| # | ||
| .PHONY: 4.16-el94 | ||
| 4.16-el94: | ||
| @$(MAKE) rhocp USHIFT_VER=4.16 | ||
|
|
||
| .PHONY: 4.17-rc-el94 | ||
| 4.17-rc-el94: | ||
| @$(MAKE) repourl \ | ||
| USHIFT_URL=https://mirror.openshift.com/pub/openshift-v4/$$(uname -m)/microshift/ocp/latest-4.17/el9/os/ \ | ||
| OCPDEP_URL=https://mirror.openshift.com/pub/openshift-v4/$$(uname -m)/dependencies/rpms/4.17-el9-beta/ | ||
|
|
||
| .PHONY: 4.18-ec-el94 | ||
| 4.18-ec-el94: | ||
| @$(MAKE) repourl \ | ||
| USHIFT_URL=https://mirror.openshift.com/pub/openshift-v4/$$(uname -m)/microshift/ocp-dev-preview/latest-4.18/el9/os/ \ | ||
| OCPDEP_URL=https://mirror.openshift.com/pub/openshift-v4/$$(uname -m)/dependencies/rpms/4.18-el9-beta/ | ||
|
|
||
| # | ||
| # ISO builds are named 'microshift-<make_target>' (the '.iso' suffix is part of | ||
| # the make target name) and stored at the ${BIB_OUTBASE} directory. | ||
| # Each build uses 'localhost/microshift-<make-target>' container image as input. | ||
| # | ||
| # BIB_IMAGE_URL ?= registry.redhat.io/rhel9/bootc-image-builder | ||
| # BIB_IMAGE_TAG ?= latest | ||
| # BIB_OUTBASE ?= $(HOME)/imagemode | ||
| # .PHONY: 4.16-el94.iso | ||
| # 4.16-el94.iso: 4.16-el94 | ||
| # IMAGE_NAME="microshift-$$(echo $@ | sed 's/\.iso$$//')" ; \ | ||
| # ISO_FNAME="microshift-$@" ; \ | ||
| # BIB_OUTDIR="${BIB_OUTBASE}/$@" ; \ | ||
| # sudo podman pull \ | ||
| # --authfile "${PULL_SECRET}" \ | ||
| # "${BIB_IMAGE_URL}:${BIB_IMAGE_TAG}" && \ | ||
| # sudo mkdir -p "$${BIB_OUTDIR}" && \ | ||
| # sudo podman run \ | ||
| # --rm -i --privileged \ | ||
| # --pull=never \ | ||
| # --security-opt "label=type:unconfined_t" \ | ||
| # -v "$${BIB_OUTDIR}:/output" \ | ||
| # -v "/var/lib/containers/storage:/var/lib/containers/storage" \ | ||
| # "${BIB_IMAGE_URL}:${BIB_IMAGE_TAG}" \ | ||
| # --type anaconda-iso \ | ||
| # --local \ | ||
| # "localhost/$${IMAGE_NAME_URL}" && \ | ||
| # sudo mv -f "$${BIB_OUTDIR}/bootiso/install.iso" "${BIB_OUTBASE}/$${ISO_FNAME}" | ||
ggiguash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.