Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion .github/workflows/ci-snapshot-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0 # required for tag metadata
sparse-checkout: cmd/nrdot-collector-builder

- name: Setup Go
uses: actions/setup-go@v5
Expand Down Expand Up @@ -51,11 +52,82 @@ jobs:
- name: Publish alpha with GoReleaser
id: goreleaser
uses: goreleaser/goreleaser-action@v6
if: ${{ !env.ACT && github.ref_name == 'main' && github.event_name == 'push' }}
with:
distribution: goreleaser
version: "~> v2"
args: --snapshot --clean
workdir: cmd/nrdot-collector-builder
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Login to GitHub Container Registry for manifests
uses: docker/login-action@v3
if: ${{ !env.ACT }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract and Publish Docker Manifests
shell: bash
if: ${{ !env.ACT && (github.ref_name == 'main' && github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Extract Docker image names and digests
DOCKER_IMAGES=$(echo '${{ steps.goreleaser.outputs.artifacts }}' | jq -r '.[] | select(.type=="Docker Image")')

# Create temporary files to store grouped data
mkdir -p ${{ runner.temp }}/manifest_groups
rm -f ${{ runner.temp }}/manifest_groups/*

# Convert to an array of objects for iteration
echo "$DOCKER_IMAGES" | jq -c '.' | while read -r image_object; do
# Extract image name and architecture
name=$(echo "$image_object" | jq -r '.name')
goarch=$(echo "$image_object" | jq -r '.goarch')

# Extract the base name and tag
base_name=$(echo "$name" | cut -d ':' -f 1)
tag=$(echo "$name" | cut -d ':' -f 2)

# Extract base tag (without architecture suffix)
base_tag=$(echo "$tag" | cut -d '-' -f 1)

echo "Processing image: $name (arch: $goarch)"
echo " Base name: $base_name"
echo " Base tag: $base_tag"

# Use files to store the grouped data
# Create a file named after the base_tag and append the image name to it
echo "$name" >> "${{ runner.temp }}/manifest_groups/$base_tag"
done

# Now create manifests for each group
echo "Creating Docker manifests..."
for group_file in ${{ runner.temp }}/manifest_groups/*; do
# Extract base_tag from filename
base_tag=$(basename "$group_file")

# Read all images for this tag
images=$(cat "$group_file" | tr '\n' ' ')

# Get base name from the first image
first_image=$(echo "$images" | awk '{print $1}')
base_name=$(echo "$first_image" | cut -d ':' -f 1)

# Create manifest name (base name + base tag without arch)
manifest_name="${base_name}:${base_tag}"

echo "Creating manifest: $manifest_name"
echo " With images: $images"

# Create and push the manifest
# Uncomment these lines when you're ready to execute them
docker manifest create "$manifest_name" $images
docker manifest push "$manifest_name"
done

# Clean up temporary files
rm -rf ${{ runner.temp }}/manifest_groups

Loading