Skip to content

Commit 3ed9e2d

Browse files
committed
chore: Ensure snapshots are pushed to registry (#310)
1 parent 2ab2937 commit 3ed9e2d

File tree

1 file changed

+8
-57
lines changed

1 file changed

+8
-57
lines changed

.github/workflows/ci-snapshot-cli.yaml

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
permissions:
1111
contents: read
1212
packages: write
13+
id-token: write
1314

1415
jobs:
1516
snapshot:
@@ -67,67 +68,17 @@ jobs:
6768
registry: ghcr.io
6869
username: ${{ github.actor }}
6970
password: ${{ secrets.GITHUB_TOKEN }}
70-
71+
7172
- name: Extract and Publish Docker Manifests
72-
shell: bash
7373
if: ${{ !env.ACT && (github.ref_name == 'main' && github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
7474
env:
7575
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7676
run: |
77-
# Extract Docker image names and digests
78-
DOCKER_IMAGES=$(echo '${{ steps.goreleaser.outputs.artifacts }}' | jq -r '.[] | select(.type=="Docker Image")')
79-
80-
# Create temporary files to store grouped data
81-
mkdir -p ${{ runner.temp }}/manifest_groups
82-
rm -f ${{ runner.temp }}/manifest_groups/*
77+
VERSION=$(echo '${{ steps.goreleaser.outputs.metadata }}' | jq -r '.version')
8378
84-
# Convert to an array of objects for iteration
85-
echo "$DOCKER_IMAGES" | jq -c '.' | while read -r image_object; do
86-
# Extract image name and architecture
87-
name=$(echo "$image_object" | jq -r '.name')
88-
goarch=$(echo "$image_object" | jq -r '.goarch')
89-
90-
# Extract the base name and tag
91-
base_name=$(echo "$name" | cut -d ':' -f 1)
92-
tag=$(echo "$name" | cut -d ':' -f 2)
93-
94-
# Extract base tag (without architecture suffix)
95-
base_tag=$(echo "$tag" | cut -d '-' -f 1)
96-
97-
echo "Processing image: $name (arch: $goarch)"
98-
echo " Base name: $base_name"
99-
echo " Base tag: $base_tag"
100-
101-
# Use files to store the grouped data
102-
# Create a file named after the base_tag and append the image name to it
103-
echo "$name" >> "${{ runner.temp }}/manifest_groups/$base_tag"
104-
done
105-
106-
# Now create manifests for each group
107-
echo "Creating Docker manifests..."
108-
for group_file in ${{ runner.temp }}/manifest_groups/*; do
109-
# Extract base_tag from filename
110-
base_tag=$(basename "$group_file")
111-
112-
# Read all images for this tag
113-
images=$(cat "$group_file" | tr '\n' ' ')
114-
115-
# Get base name from the first image
116-
first_image=$(echo "$images" | awk '{print $1}')
117-
base_name=$(echo "$first_image" | cut -d ':' -f 1)
118-
119-
# Create manifest name (base name + base tag without arch)
120-
manifest_name="${base_name}:${base_tag}"
121-
122-
echo "Creating manifest: $manifest_name"
123-
echo " With images: $images"
124-
125-
# Create and push the manifest
126-
# Uncomment these lines when you're ready to execute them
127-
docker manifest create "$manifest_name" $images
128-
docker manifest push "$manifest_name"
129-
done
130-
131-
# Clean up temporary files
132-
rm -rf ${{ runner.temp }}/manifest_groups
79+
# Extract Docker image names and digests
80+
DOCKER_IMAGES=$(docker image ls --format "{{.Repository}}:{{.Tag}}" | grep "$GITHUB_REPOSITORY/nrdot-collector-builder:$VERSION" | tr '\n' ' ')
13381
82+
echo $DOCKER_IMAGES | xargs -d ' ' -I{} -n1 sh -c "docker push {}"
83+
docker manifest create $GITHUB_REPOSITORY:$VERSION $(echo $DOCKER_IMAGES)
84+
docker manifest push $GITHUB_REPOSITORY:$VERSION

0 commit comments

Comments
 (0)