Skip to content

Commit

Permalink
[.github] simplify parallelism (#1133)
Browse files Browse the repository at this point in the history
* [.github] simplify parallelism

xargs to the rescue.

* [.github] share env vars with upload_image.sh when called by xargs
  • Loading branch information
kylos101 committed Jul 16, 2023
1 parent 58ba18b commit 01c5526
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 41 deletions.
47 changes: 6 additions & 41 deletions .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,48 +146,13 @@ jobs:
TIMESTAMP_TAG: ${{env.TIMESTAMP_TAG}}
SKOPEO_SYNC_FILES: ${{env.SKOPEO_SYNC_FILES}}
run: |
set -e
upload_image() {
local IMAGE_TAG=$1
set -euo pipefail
echo "Uploading $IMAGE_TAG at $(date -u +'%Y-%m-%d %H:%M:%S')"
# upload timestamped image
(sudo -E skopeo copy --format=oci --dest-oci-accept-uncompressed-layers --retry-times=2 \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-base-images:${IMAGE_TAG}" \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-${IMAGE_TAG}:${TIMESTAMP_TAG}" &)
# upload latest image
(sudo -E skopeo copy --format=oci --dest-oci-accept-uncompressed-layers --retry-times=2 \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-base-images:${IMAGE_TAG}" \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-${IMAGE_TAG}:latest" &)
wait
}
MAX_PARALLEL=10
declare -a UPLOAD_PIDS=()
IMAGE_TAGS=$(yq -r '.sync.images."workspace-base-images"|join(" ")' .github/sync-containers.yml)
for image_tag in "${IMAGE_TAGS[@]}"; do
upload_image "$image_tag" &
UPLOAD_PIDS+=($!)
if [ ${#UPLOAD_PIDS[@]} -eq $MAX_PARALLEL ]; then
# Wait for the first background process in the array
wait "${UPLOAD_PIDS[0]}"
status=$?
if [ $status -ne 0 ]; then
echo "Upload job failed with exit code $status"
exit 1
fi
# Remove the first element from the array
UPLOAD_PIDS=("${UPLOAD_PIDS[@]:1}")
fi
done
IFS=' ' read -r -a IMAGE_TAGS < <(yq '.sync.images."workspace-base-images"|join(" ")' .github/sync-containers.yml)
UPLOADS=$(printf "./.github/workflows/push-main/upload_image.sh %s\n" "${IMAGE_TAGS[@]}")
echo "${UPLOADS}" | xargs -I CMD -P 10 -n 1 \
env SKOPEO_AUTH_DIR="${SKOPEO_AUTH_DIR}" GAR_IMAGE_REGISTRY="${GAR_IMAGE_REGISTRY}" TIMESTAMP_TAG="${TIMESTAMP_TAG}" SKOPEO_SYNC_FILES="${SKOPEO_SYNC_FILES}" \
bash -c CMD --
- name: ✍🏽 Login to Docker Hub using skopeo
env:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/push-main/upload_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -eu

IMAGE_TAG=$1

echo "Uploading ${IMAGE_TAG} at $(date -u +'%Y-%m-%d %H:%M:%S')"

# upload timestamped image
echo sudo -E skopeo copy --format=oci --dest-oci-accept-uncompressed-layers --retry-times=2 \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-base-images:${IMAGE_TAG}" \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-${IMAGE_TAG}:${TIMESTAMP_TAG}"

# upload latest image
echo sudo -E skopeo copy --format=oci --dest-oci-accept-uncompressed-layers --retry-times=2 \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-base-images:${IMAGE_TAG}" \
"docker://${GAR_IMAGE_REGISTRY}/gitpod-artifacts/docker-dev/workspace-${IMAGE_TAG}:latest"

0 comments on commit 01c5526

Please sign in to comment.