Skip to content

Commit

Permalink
!! DEBUG !! Airgap on Rancher latest/devel
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Devulder <[email protected]>
  • Loading branch information
ldevulder committed Mar 6, 2024
1 parent 3835aab commit 71b60d6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/sub_airgap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ jobs:
uses: actions/checkout@v4

- name: Authenticate to GCP
id: authenticate
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.credentials }}

- name: Setup gcloud
id: setup_gcloud
uses: google-github-actions/setup-gcloud@v2

- name: Download QCOW2 VM image
id: download_qcow2
run: |
QCOW2_FILE=rancher-image.qcow2
gcloud storage cp gs://elemental-airgap-image/${QCOW2_FILE} ${HOME}/${QCOW2_FILE}
Expand Down
86 changes: 51 additions & 35 deletions tests/scripts/build-airgap
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function RunSkopeoCmdWithRetry() {
# Wait for a maximum of 1 minute
for ((i=0; i<60; i++)); do
# If skopeo command is OK then we simply return (exit the function)
skopeo $* && return
skopeo $* > /dev/null && return

# Wait a little
sleep 5
Expand Down Expand Up @@ -66,7 +66,7 @@ K8S_DOWNSTREAM_VERSION=${TMP_VER/v}
mkdir -p ${OPT_RANCHER}/{k3s_${K8S_UPSTREAM_VERSION},k3s_${K8S_DOWNSTREAM_VERSION},helm} ${OPT_RANCHER}/images/{cert,rancher,registry,elemental}

# Install packages
sudo zypper --no-refresh -n in skopeo yq
# sudo zypper --no-refresh -n in skopeo yq

# Add rancher manager in /etc/hosts
sudo sh -c 'echo "192.168.122.102 rancher-manager.test" >> /etc/hosts'
Expand Down Expand Up @@ -114,38 +114,40 @@ bash ${ELEMENTAL_AIRGAP_SCRIPT} -d -r localhost:5000 -sa ${ELEMENTAL_VERSION}
cd ${OPT_RANCHER}/images/

# Rancher image list
IMAGES_FILE_TMP=/tmp/rancher-images
IMAGES_FILE_UNSORTED=/tmp/rancher-images_unsorted
# IMAGES_FILE_TMP=/tmp/rancher-images
# IMAGES_FILE_UNSORTED=/tmp/rancher-images_unsorted
RANCHER_IMAGES_FILE=rancher/rancher-images.txt
curl -sL https://github.com/rancher/rancher/releases/download/v${RANCHER_MANAGER_VERSION%.*}/rancher-images.txt -o ${IMAGES_FILE_TMP}
# curl -sL https://github.com/rancher/rancher/releases/download/v${RANCHER_MANAGER_VERSION%.*}/rancher-images.txt -o ${IMAGES_FILE_TMP}
curl -sL https://github.com/rancher/rancher/releases/download/v${RANCHER_MANAGER_VERSION%.*}/rancher-images.txt -o ${RANCHER_IMAGES_FILE}

# Shorten rancher list with a sort
# Fix library tags
sed -i -e '0,/busybox/s/busybox/library\/busybox/' -e 's/registry/library\/registry/g' ${IMAGES_FILE_TMP}

# We need to keep the following images
IMAGES_LIST="mirrored-cluster-api-controller mirrored-pause mirrored-coredns-coredns mirrored-library-traefik"
for i in ${IMAGES_LIST}; do
IMAGES+="$(grep $i ${IMAGES_FILE_TMP})\n"
done

# Remove things that are not needed and overlapped
sed -i -E '/neuvector|minio|gke|aks|eks|sriov|harvester|mirrored|longhorn|thanos|tekton|istio|multus|hyper|jenkins|windows/d' ${IMAGES_FILE_TMP}
echo -e ${IMAGES} >> ${IMAGES_FILE_TMP}

# Get latest version
for i in $(awk -F: '{print $1}' ${IMAGES_FILE_TMP}); do
grep -w $i ${IMAGES_FILE_TMP} | sort -Vr | head -1 >> ${IMAGES_FILE_UNSORTED}
done

# Except for rancher/kubectl
grep 'rancher/kubectl' ${IMAGES_FILE_TMP} >> ${IMAGES_FILE_UNSORTED}
for k8s_ver in ${K8S_UPSTREAM_VERSION} ${K8S_DOWNSTREAM_VERSION}; do
grep "rancher/system-agent-installer-k3s:v${k8s_ver}" ${IMAGES_FILE_TMP} >> ${IMAGES_FILE_UNSORTED}
done

# Final sort
sort -u ${IMAGES_FILE_UNSORTED} > ${RANCHER_IMAGES_FILE}
# sed -i -e '0,/busybox/s/busybox/library\/busybox/' -e 's/registry/library\/registry/g' ${IMAGES_FILE_TMP}
# sed -i -e '0,/busybox/s/busybox/library\/busybox/' -e 's/registry/library\/registry/g' ${RANCHER_IMAGES_FILE}

# # We need to keep the following images
# IMAGES_LIST="mirrored-cluster-api-controller mirrored-pause mirrored-coredns-coredns mirrored-library-traefik"
# for i in ${IMAGES_LIST}; do
# IMAGES+="$(grep $i ${IMAGES_FILE_TMP})\n"
# done
#
# # Remove things that are not needed and overlapped
# sed -i -E '/neuvector|minio|gke|aks|eks|sriov|harvester|mirrored|longhorn|thanos|tekton|istio|multus|hyper|jenkins|windows/d' ${IMAGES_FILE_TMP}
# echo -e ${IMAGES} >> ${IMAGES_FILE_TMP}
#
# # Get latest version
# for i in $(awk -F: '{print $1}' ${IMAGES_FILE_TMP}); do
# grep -w ${i} ${IMAGES_FILE_TMP} | sort -Vr | head -1 >> ${IMAGES_FILE_UNSORTED}
# done
#
# # Except for rancher/kubectl
# grep 'rancher/kubectl' ${IMAGES_FILE_TMP} >> ${IMAGES_FILE_UNSORTED}
# for k8s_ver in ${K8S_UPSTREAM_VERSION} ${K8S_DOWNSTREAM_VERSION}; do
# grep "rancher/system-agent-installer-k3s:v${k8s_ver}" ${IMAGES_FILE_TMP} >> ${IMAGES_FILE_UNSORTED}
# done
#
# # Final sort
# sort -u ${IMAGES_FILE_UNSORTED} > ${RANCHER_IMAGES_FILE}

# Cert-manager image list
CERT_IMAGES_FILE=cert/cert-manager-images.txt
Expand All @@ -169,7 +171,7 @@ grep 'registry.opensuse.*sle-micro-iso' ${OPT_RANCHER}/helm/elemental-images.txt
# Skopeo - cert-manager
for i in $(< ${CERT_IMAGES_FILE}); do
VAR=$(awk -F/ '{print $3}' <<< ${i})
RunSkopeoCmdWithRetry copy docker://${i} docker-archive:cert/${VAR//:/_}.tar:${VAR} > /dev/null 2>&1
RunSkopeoCmdWithRetry copy docker://${i} docker-archive:cert/${VAR//:/_}.tar:${VAR} &
done

# Skopeo - Elemental
Expand All @@ -179,18 +181,32 @@ for i in $(< ${ELEMENTAL_IMAGES_FILE}); do
|| VALUE=\$8

VAR=$(awk -F/ "{print ${VALUE}}" <<< ${i})
RunSkopeoCmdWithRetry copy docker://${i} docker-archive:elemental/${VAR//:/_}.tar:${VAR} > /dev/null 2>&1
RunSkopeoCmdWithRetry copy docker://${i} docker-archive:elemental/${VAR//:/_}.tar:${VAR} &
done

# Skopeo - Rancher
loop=0
for i in $(< ${RANCHER_IMAGES_FILE}); do
VAR=$(awk -F/ '{print $2}' <<< ${i})
RunSkopeoCmdWithRetry copy docker://${i} docker-archive:rancher/${VAR//:/_}.tar:${VAR} > /dev/null 2>&1
RunSkopeoCmdWithRetry copy docker://${i} docker-archive:rancher/${VAR//:/_}.tar:${VAR} &

# Wait for skopeo jobs to finish if we already have too much jobs in parallel
# This is to avoid the "too many requests to registry" error!
if (( ++loop > 50 )); then
echo "Wait for sync..."
wait

# Reset loop counter
loop=0
fi
done

# Wait for *ALL* skopeo jobs to finish
wait

# Skopeo - Registry
RunSkopeoCmdWithRetry copy --additional-tag registry:latest docker://registry:latest docker-archive:registry/registry.tar > /dev/null 2>&1
RunSkopeoCmdWithRetry copy --additional-tag registry:latest docker://registry:latest docker-archive:registry/registry.tar

# Compress all the things
cd ${OPT_RANCHER}
tar -I zstd -vcf ${OPT_RANCHER%/*}/airgap_rancher.zst $(ls 2>/dev/null) > /dev/null 2>&1
tar -I pzstd -vcf ${OPT_RANCHER%/*}/airgap_rancher.zst $(ls 2>/dev/null)

0 comments on commit 71b60d6

Please sign in to comment.