Skip to content

OCPBUGS-55386: Update oc-mirror to use -v2 #1752

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
merged 1 commit into from
May 16, 2025
Merged
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
6 changes: 3 additions & 3 deletions agent/05_agent_configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ function get_mirror_info {
# output ImageDigestSources, while prior to that it was ImageContentSources
sed -n -E '/imageContentSources|imageDigestSources/,/^ *$/p' ${MIRROR_LOG_FILE} | tail -n+2 > ${tmpmirrorinfo}
else
results_dir=$(grep ICSP ${WORKING_DIR}/.oc-mirror.log | grep -o 'oc-mirror[^;]*')
sed -ne '/repository/,/---/p' ${WORKING_DIR}/${results_dir}/imageContentSourcePolicy.yaml > ${tmpmirrorinfo}
sed -i '/repositoryDigestMirrors/d;/---/d' ${tmpmirrorinfo}
# Get the mirror config from the idms file generated by oc-mirror
idms_file=${WORKING_DIR}/working-dir/cluster-resources/idms-oc-mirror.yaml
sed -ne '/imageDigestMirrors:$/,/^status:/{/imageDigestMirrors:$/d;/^status:/d;p;}' $idms_file | sed 's/ //' > ${tmpmirrorinfo}
fi

if [[ ${AGENT_USE_ZTP_MANIFESTS} == true ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ platform:
baremetal:
apiVIPs:
{% set a_vips = api_vips.split(',') %}
{% for api_vip in a_vips %}
- {{ api_vip }}
{% endfor %}
- {{ a_vips[0] }}
ingressVIPs:
{% set i_vips = ingress_vips.split(',') %}
{% for ingress_vip in i_vips %}
Expand Down Expand Up @@ -133,4 +131,4 @@ proxy:
{% if no_proxy %}
noProxy: "{{ no_proxy }}"
{% endif %}
{% endif %}
{% endif %}
6 changes: 0 additions & 6 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,6 @@ if [[ "${MIRROR_IMAGES,,}" != "false" ]] && [[ "${MIRROR_IMAGES,,}" == "true" ||
if [[ "${MIRROR_COMMAND}" == "oc-mirror" ]]; then
# Use the string that is generated by the output of oc-mirror
export LOCAL_IMAGE_URL_SUFFIX="openshift/release-images"

# set up the channel using the most recent candidate release
pushd ${WORKING_DIR}
release_candidate=`oc-mirror list releases --channel=candidate-${OPENSHIFT_RELEASE_STREAM} | tail -1`
popd
export OPENSHIFT_RELEASE_TAG="${release_candidate}-$(uname -m)"
fi

# We're going to be using a locally modified release image
Expand Down
6 changes: 0 additions & 6 deletions config_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,6 @@ set -x
# Default: oc-adm
#export MIRROR_COMMAND=oc-adm

# OC_MIRROR_TO_FILE -
# When MIRROR_IMAGES is true and MIRROR_COMMAND is oc-mirror, if this is set it
# will cause the mirror to be generated in a 2-step process. First the contents of
# the mirror is stored in a tarfile and then the tarfile is published to the registry
# Default is unset

# When the MIRROR_COMMAND is set to 'oc-mirror' the auths for the mirror will be added
# to DOCKER_CONFIG_FILE or an UNAUTHORIZED error will result.
# An example entry in this file is:
Expand Down
85 changes: 15 additions & 70 deletions oc_mirror.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,93 +49,39 @@ function setup_quay_mirror_registry() {
popd
}

function create_registry_imageset() {

imageset=$1

cat > "${imageset}" << EOF
apiVersion: mirror.openshift.io/v1alpha2
kind: ImageSetConfiguration
archiveSize: 4
storageConfig:
registry:
imageURL: ${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT}/origin:latest
skipTLS: true
mirror:
platform:
architectures:
- "amd64"
channels:
- name: candidate-${OPENSHIFT_RELEASE_STREAM}
type: ocp
additionalImages:
- name: registry.redhat.io/ubi8/ubi:latest
EOF

}

function create_file_imageset() {

imageset=$1

latest_release=$(oc-mirror list releases --channel candidate-${OPENSHIFT_RELEASE_STREAM}| tail -n1)

# Note that the archiveSize defines the maximum size, in GiB, of each file within the image set.
# This must be large enough to include all images in one file for the publish.
cat > "${imageset}" << EOF
apiVersion: mirror.openshift.io/v1alpha2
kind: ImageSetConfiguration
archiveSize: 16
storageConfig:
local:
path: metadata
apiVersion: mirror.openshift.io/v2alpha1
mirror:
platform:
architectures:
- "amd64"
channels:
- name: candidate-${OPENSHIFT_RELEASE_STREAM}
minVersion: $latest_release
maxVersion: $latest_release
type: ocp
graph: true
release: $OPENSHIFT_RELEASE_IMAGE
additionalImages:
- name: registry.redhat.io/ubi8/ubi:latest
EOF

}

# Mirror the upstream channel directly to the local registry
function mirror_to_mirror_publish() {

# Create imageset containing the local URL and the OCP release to mirror
tmpimageset=$(mktemp --tmpdir "imageset--XXXXXXXXXX")
_tmpfiles="$_tmpfiles $tmpimageset"

create_registry_imageset $tmpimageset

pushd ${WORKING_DIR}
oc mirror --dest-skip-tls --config ${tmpimageset} docker://${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT}
popd
}

# Use the oc-mirror command to generate a tar file of the release image
function mirror_to_file() {

config=${1}

pushd ${WORKING_DIR}
oc_mirror_dir=$(mktemp --tmpdir -d "oc-mirror-files--XXXXXXXXXX")
_tmpfiles="$_tmpfiles $oc_mirror_dir"
oc-mirror --config ${config} file://${oc_mirror_dir} --ignore-history
archive_file="$(ls ${oc_mirror_dir}/mirror_seq*)"
oc-mirror --v2 --config ${config} file://${WORKING_DIR}
popd

}

function publish_image() {

config=${1}

pushd ${WORKING_DIR}
oc-mirror --from $archive_file docker://${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT} --dest-skip-tls --skip-metadata-check
oc-mirror --v2 --config ${config} --from file://${WORKING_DIR} docker://${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT}
popd

}
Expand All @@ -146,16 +92,15 @@ function setup_oc_mirror() {

update_docker_config

if [ -z "${OC_MIRROR_TO_FILE}" ]; then
mirror_to_mirror_publish
else
tmpimageset=$(mktemp --tmpdir "imageset--XXXXXXXXXX")
_tmpfiles="$_tmpfiles $tmpimageset"
tmpimageset=$(mktemp --tmpdir "imageset--XXXXXXXXXX")
_tmpfiles="$_tmpfiles $tmpimageset"

create_file_imageset $tmpimageset
create_file_imageset $tmpimageset

mirror_to_file $tmpimageset
mirror_to_file $tmpimageset

publish_image
fi
publish_image $tmpimageset

# remove interim file
rm ${WORKING_DIR}/mirror_*.tar
}
8 changes: 2 additions & 6 deletions oc_mirror_cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ if [[ -f "/usr/local/bin/oc-mirror" ]]; then
sudo rm "/usr/local/bin/oc-mirror"
fi

if [ -f "${WORKING_DIR}/.oc-mirror.log" ]; then
rm "${WORKING_DIR}/.oc-mirror.log"
fi

if [ -d "${WORKING_DIR}/oc-mirror-workspace" ]; then
rm -rf "${WORKING_DIR}/oc-mirror-workspace"
if [ -d "${WORKING_DIR}/working-dir" ]; then
rm -rf "${WORKING_DIR}/working-dir"
fi

if [ -d "${WORKING_DIR}/quay-install" ]; then
Expand Down