|
10 | 10 | permissions: |
11 | 11 | contents: read |
12 | 12 | packages: write |
| 13 | + id-token: write |
13 | 14 |
|
14 | 15 | jobs: |
15 | 16 | snapshot: |
@@ -67,67 +68,17 @@ jobs: |
67 | 68 | registry: ghcr.io |
68 | 69 | username: ${{ github.actor }} |
69 | 70 | password: ${{ secrets.GITHUB_TOKEN }} |
70 | | - |
| 71 | + |
71 | 72 | - name: Extract and Publish Docker Manifests |
72 | | - shell: bash |
73 | 73 | if: ${{ !env.ACT && (github.ref_name == 'main' && github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} |
74 | 74 | env: |
75 | 75 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
76 | 76 | 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') |
83 | 78 |
|
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' ' ') |
133 | 81 |
|
| 82 | + echo $DOCKER_IMAGES | xargs -d ' ' -I{} -n1 sh -c "docker push {}" |
| 83 | + docker manifest create $GITHUB_REPOSITORY/nrdot-collector-builder:$VERSION $(echo $DOCKER_IMAGES) |
| 84 | + docker manifest push $GITHUB_REPOSITORY/nrdot-collector-builder:$VERSION |
0 commit comments