Skip to content

Commit

Permalink
Don't pull and save all the images every build
Browse files Browse the repository at this point in the history
We only need to pull and save images when building tags, if building an untagged dev release, just inspect to make sure the images all exist

Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Jul 16, 2024
1 parent 444d532 commit 42e21a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
27 changes: 16 additions & 11 deletions scripts/build-images
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ source ./scripts/version.sh

./scripts/build-image-runtime

awk '{print $1}' << EOF > build/images-core.txt
${REGISTRY}/${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}
EOF
echo ${REGISTRY}/${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION} > build/images-core.txt

# If not building a release, only inspect the images to ensure they exist, instead of pulling
if [[ RKE2_PATCH == dev.* ]]; then
IMAGE_COMMAND="sh -c 'docker manifest inspect \$0 >/dev/null && echo \$0'"
else
IMAGE_COMMAND="docker image pull"
fi

xargs -n1 -t docker image pull --quiet << EOF >> build/images-core.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF >> build/images-core.txt
${REGISTRY}/rancher/hardened-kubernetes:${KUBERNETES_IMAGE_TAG}
${REGISTRY}/rancher/hardened-coredns:v1.11.1-build20240305
${REGISTRY}/rancher/hardened-cluster-autoscaler:v1.8.10-build20240124
Expand All @@ -29,13 +34,13 @@ xargs -n1 -t docker image pull --quiet << EOF >> build/images-core.txt
${REGISTRY}/rancher/mirrored-sig-storage-snapshot-validation-webhook:v6.2.2
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-canal.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF > build/images-canal.txt
${REGISTRY}/rancher/hardened-calico:v3.28.0-build20240625
${REGISTRY}/rancher/hardened-flannel:v0.25.4-build20240610
EOF

if [ "${GOARCH}" != "s390x" ]; then
xargs -n1 -t docker image pull --quiet << EOF > build/images-cilium.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF > build/images-cilium.txt
${REGISTRY}/rancher/mirrored-cilium-certgen:v0.1.12
${REGISTRY}/rancher/mirrored-cilium-cilium:v1.15.5
${REGISTRY}/rancher/mirrored-cilium-cilium-envoy:v1.28.3-31ec52ec5f2e4d28a8e19a0bfb872fa48cf7a515
Expand All @@ -49,7 +54,7 @@ xargs -n1 -t docker image pull --quiet << EOF > build/images-cilium.txt
${REGISTRY}/rancher/hardened-cni-plugins:v1.4.1-build20240325
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-calico.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF > build/images-calico.txt
${REGISTRY}/rancher/mirrored-calico-operator:v1.32.7
${REGISTRY}/rancher/mirrored-calico-ctl:v3.27.3
${REGISTRY}/rancher/mirrored-calico-kube-controllers:v3.27.3
Expand All @@ -63,7 +68,7 @@ xargs -n1 -t docker image pull --quiet << EOF > build/images-calico.txt
EOF

if [ "${GOARCH}" != "arm64" ]; then
xargs -n1 -t docker image pull --quiet << EOF > build/images-vsphere.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF > build/images-vsphere.txt
${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-cpi-release-manager:v1.28.0
${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-csi-release-driver:v3.1.2
${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-csi-release-syncer:v3.1.2
Expand All @@ -76,7 +81,7 @@ xargs -n1 -t docker image pull --quiet << EOF > build/images-vsphere.txt
EOF
fi

xargs -n1 -t docker image pull --quiet << EOF > build/images-multus.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF > build/images-multus.txt
${REGISTRY}/rancher/hardened-multus-cni:v4.0.2-build20240612
${REGISTRY}/rancher/hardened-cni-plugins:v1.4.1-build20240430
${REGISTRY}/rancher/hardened-node-feature-discovery:v0.15.4-build20240513
Expand All @@ -91,7 +96,7 @@ xargs -n1 -t docker image pull --quiet << EOF > build/images-multus.txt
${REGISTRY}/rancher/mirrored-library-busybox:1.36.1
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-harvester.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF > build/images-harvester.txt
${REGISTRY}/rancher/harvester-cloud-provider:v0.2.1
${REGISTRY}/rancher/mirrored-kube-vip-kube-vip-iptables:v0.6.0
${REGISTRY}/rancher/harvester-csi-driver:v0.1.6
Expand All @@ -101,7 +106,7 @@ xargs -n1 -t docker image pull --quiet << EOF > build/images-harvester.txt
${REGISTRY}/rancher/mirrored-longhornio-csi-attacher:v3.2.1
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-flannel.txt
xargs -n1 -t $IMAGE_COMMAND --quiet << EOF > build/images-flannel.txt
${REGISTRY}/rancher/hardened-flannel:v0.25.4-build20240610
${REGISTRY}/rancher/hardened-cni-plugins:v1.4.1-build20240430
EOF
Expand Down
9 changes: 5 additions & 4 deletions scripts/build-windows-images
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ fi

mkdir -p build

WINDOWS_IMAGES=(${REGISTRY}/${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}-windows-amd64 rancher/mirrored-pause:${PAUSE_VERSION}-windows-1809-amd64 rancher/mirrored-pause:${PAUSE_VERSION}-windows-ltsc2022-amd64)
for IMAGE in "${WINDOWS_IMAGES[@]}"; do
echo "${IMAGE}" >> build/windows-images.txt
done
cat << EOF > build/windows-images.txt
${REGISTRY}/${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}-windows-amd64
${REGISTRY}/rancher/mirrored-pause:${PAUSE_VERSION}-windows-1809-amd64
${REGISTRY}/rancher/mirrored-pause:${PAUSE_VERSION}-windows-ltsc2022-amd64
EOF
9 changes: 8 additions & 1 deletion scripts/package-images
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ source ./scripts/version.sh

mkdir -p dist/artifacts

# If not building a release, only save the core image tarball
if [[ RKE2_PATCH == dev.* ]]; then
IMAGE_LISTS=(build/images-core.txt)
else
IMAGE_LISTS=(build/images*.txt)
fi

# We reorder the tar file so that the metadata files are at the start of the archive, which should make loading
# the runtime image faster. By default `docker image save` puts these at the end of the archive, which means the entire
# tarball needs to be read even if you're just loading a single image.
for FILE in build/images*.txt; do
for FILE in "${IMAGE_LISTS[@]}" do
BASE=$(basename ${FILE} .txt)
DEST=build/images/${PROG}-${BASE}.tar
docker image save --output ${DEST}.tmp $(<${FILE})
Expand Down

0 comments on commit 42e21a7

Please sign in to comment.