After setting up the Harbor registry, configure Harbor for collecting and publishing images for VMware Telco Cloud Automation.
Procedure
- Copy the following shell script and paste it to a text editor. Save the file as publish-images.sh.
Note: The following script has been updated for VMware Telco Cloud Automation version 1.9.5.1. To use this script, ensure that you upgrade your VMware Telco Cloud Automation to version 1.9.5.1 or later.
==== publish-images.sh ==== #!/usr/bin/env bash # Copyright 2021 The TCA CaaS Contributors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -euo pipefail AIRGAP_BOM_DIR=${HOME}/airgap echodual() { echo "$@" 1>&2 echo "#" "$@" } if [ -z "$TCA_CUSTOM_IMAGE_REPOSITORY" ]; then echo "TCA_CUSTOM_IMAGE_REPOSITORY variable is not defined" >&2 exit 1 fi if [[ -d "$AIRGAP_BOM_DIR" ]]; then BOM_DIR="${AIRGAP_BOM_DIR}" else echo "The airgap bom directory ${AIRGAP_BOM_DIR} is not found. Please make sure the directory created and all boms copyied into the folder." >&2 exit 2 fi if ! [ -x "$(command -v imgpkg)" ]; then echo 'Error: imgpkg is not installed.' >&2 exit 3 fi if ! [ -x "$(command -v yq)" ]; then echo 'Error: yq is not installed.' >&2 echo "${INSTALL_INSTRUCTIONS}" >&2 exit 3 fi echo "set -euo pipefail" echodual "Note that yq version must be equal to or above v4.5." echodual "Now processing " actualImageRepository="" # Iterate through BoM file to create the complete Image name # and then pull, retag and push image to custom registry. for AG_BOM_FILE in "$BOM_DIR"/*.yaml; do echodual "Processing BOM file ${AG_BOM_FILE}" # Get actual image repository from BoM file actualImageRepository=$(yq e '.imageConfig.imageRepository' "$AG_BOM_FILE") yq e '.. | select(has("images"))|.images[] | .imagePath + ":" + .tag ' "$AG_BOM_FILE" | while read -r image; do actualImage=${actualImageRepository}/${image} customImage=$TCA_CUSTOM_IMAGE_REPOSITORY/${image} docker pull $actualImage | grep -i error && echo "Hit error when pull image" || echo "Image $actualImage pulled" docker tag $actualImage $customImage docker push $customImage | grep -i error && echo "Hit error when push image" || echo "Image $actualImage pushed" echo "" done echodual "Finished processing BOM file ${AG_BOM_FILE}" echo "" done # Iterate through TKr BoM file to create the complete Image name # and then pull, retag and push image to custom registry. imgpkg pull -i ${TKG_IMAGE_REPO}/tkr-compatibility:v6 -o "tkrbom" > /dev/null 2>&1 TKR_COMPAT_BOM="tkr-compatibility.yaml" getTkrList="yq e '.managementClusterVersions[] | select(.version == \"v1.3.1-patch1\")|.supportedKubernetesVersions[]' "tkrbom/$TKR_COMPAT_BOM"" for imageTag in `eval $getTkrList |sed 's/+/_/g'`; do if [[ ${imageTag} == v* ]]; then TKR_BOM_FILE="tkr-bom-${imageTag//_/+}.yaml" echodual "Processing TKR BOM file ${TKR_BOM_FILE}" actualTKRImage=${actualImageRepository}/tkr-bom:${imageTag} customTKRImage=${TCA_CUSTOM_IMAGE_REPOSITORY}/tkr-bom:${imageTag} echo "" docker pull $actualTKRImage docker tag $actualTKRImage $customTKRImage docker push $customTKRImage imgpkg pull --image ${actualImageRepository}/tkr-bom:${imageTag} --output "tmp" > /dev/null 2>&1 yq e '.. | select(has("images"))|.images[] | .imagePath + ":" + .tag ' "tmp/$TKR_BOM_FILE" | while read -r image; do actualImage=${actualImageRepository}/${image} customImage=$TCA_CUSTOM_IMAGE_REPOSITORY/${image} docker pull $actualImage | grep -i error && echo "Hit error when pull image" || echo "Image $actualImage pulled" docker tag $actualImage $customImage docker push $customImage | grep -i error && echo "Hit error when pull image" || echo "Image $customImage pushed" echo "" done rm -rf tmp echodual "Finished processing TKR BOM file ${TKR_BOM_FILE}" echo "" fi done list=$(imgpkg tag list -i ${actualImageRepository}/tkr-compatibility) for imageTag in ${list}; do if [[ ${imageTag} == v* ]]; then echodual "Processing TKR compatibility image" actualImage=${actualImageRepository}/tkr-compatibility:${imageTag} customImage=$TCA_CUSTOM_IMAGE_REPOSITORY/tkr-compatibility:${imageTag} echo "" docker pull $actualImageRepository/tkr-compatibility:$imageTag | grep -i error && echo "Hit error when pull image" || echo "Image $actualImage pulled" docker tag $actualImage $customImage docker push $customImage | grep -i error && echo "Hit error when pull image" || echo "Image $customImage pushed" echo "" echodual "Finished processing TKR compatibility image" fi done ==== end-of-script ====
- Create a folder named airgap under the /root directory.
- Download all the BOM files from the VMware Customer Connect site www.my.vmware.com and place them into the airgap folder.
- To synchronize images into the air-gapped repository, run the following script:
chmod +x publish-images.sh export TKG_IMAGE_REPO="projects.registry.vmware.com/tkg" export TCA_CUSTOM_IMAGE_REPOSITORY="<replace-with-custom-FQDN>:8043/registry" docker login ${TCA_CUSTOM_IMAGE_REPOSITORY} ./publish-images.sh