|
| 1 | +name: Build CLI Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + tag_name: |
| 7 | + description: "Tag name for Docker images" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + is_prerelease: |
| 11 | + description: "Whether this is a prerelease" |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build CLI Docker Image (${{ matrix.platform.name }}) |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + attestations: write |
| 23 | + id-token: write |
| 24 | + timeout-minutes: 30 |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + platform: |
| 29 | + - name: linux/amd64 |
| 30 | + tag: linux-amd64 |
| 31 | + - name: linux/arm64 |
| 32 | + tag: linux-arm64 |
| 33 | + concurrency: |
| 34 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.platform.name }} |
| 35 | + cancel-in-progress: true |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout Repository |
| 39 | + uses: actions/checkout@v5 |
| 40 | + |
| 41 | + - name: Download CLI artifacts |
| 42 | + uses: actions/download-artifact@v6 |
| 43 | + with: |
| 44 | + path: dist |
| 45 | + pattern: cli-${{ matrix.platform.tag }} |
| 46 | + merge-multiple: true |
| 47 | + |
| 48 | + - name: List downloaded files |
| 49 | + run: ls -lh dist/ |
| 50 | + |
| 51 | + - name: Set up QEMU |
| 52 | + uses: docker/setup-qemu-action@v3 |
| 53 | + |
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v3 |
| 56 | + |
| 57 | + - name: Docker meta |
| 58 | + id: meta |
| 59 | + uses: docker/metadata-action@v5 |
| 60 | + with: |
| 61 | + images: | |
| 62 | + docker.io/${{ github.repository }} |
| 63 | + ghcr.io/${{ github.repository }} |
| 64 | + tags: | |
| 65 | + type=raw,value=${{ inputs.tag_name }} |
| 66 | + labels: | |
| 67 | + org.opencontainers.image.title=GitHub Actions Utils CLI |
| 68 | + org.opencontainers.image.description=MCP server for GitHub Actions utilities |
| 69 | + maintainer=techprimate GmbH <[email protected]> |
| 70 | +
|
| 71 | + - name: Login to Docker Hub |
| 72 | + uses: docker/login-action@v3 |
| 73 | + with: |
| 74 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 75 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 76 | + |
| 77 | + - name: Login to GitHub Container Registry |
| 78 | + uses: docker/login-action@v3 |
| 79 | + with: |
| 80 | + registry: ghcr.io |
| 81 | + username: ${{ github.actor }} |
| 82 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
| 84 | + - name: Build ${{ github.event_name == 'pull_request' && '(dry run)' || 'and push' }} by digest |
| 85 | + id: build |
| 86 | + uses: docker/build-push-action@v6 |
| 87 | + with: |
| 88 | + context: . |
| 89 | + file: ./Dockerfile |
| 90 | + platforms: ${{ matrix.platform.name }} |
| 91 | + tags: ${{ steps.meta.outputs.tags }} |
| 92 | + labels: ${{ steps.meta.outputs.labels }} |
| 93 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 94 | + cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache-${{ matrix.platform.tag }} |
| 95 | + cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache-${{ matrix.platform.tag }},mode=max |
| 96 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }} |
| 97 | + env: |
| 98 | + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
| 99 | + |
| 100 | + - name: Export digest |
| 101 | + if: github.event_name != 'pull_request' |
| 102 | + run: | |
| 103 | + set -e |
| 104 | + mkdir -p /tmp/digests |
| 105 | + digest="${{ steps.build.outputs.digest }}" |
| 106 | + touch "/tmp/digests/${digest#sha256:}" |
| 107 | + ls -la /tmp/digests |
| 108 | +
|
| 109 | + - name: Upload digest |
| 110 | + if: github.event_name != 'pull_request' |
| 111 | + uses: actions/upload-artifact@v5 |
| 112 | + with: |
| 113 | + name: cli-docker-digests-${{ matrix.platform.tag }} |
| 114 | + path: /tmp/digests/* |
| 115 | + if-no-files-found: error |
| 116 | + retention-days: 1 |
| 117 | + |
| 118 | + merge: |
| 119 | + name: Create Manifest List |
| 120 | + runs-on: ubuntu-latest |
| 121 | + needs: build |
| 122 | + if: github.event_name != 'pull_request' |
| 123 | + permissions: |
| 124 | + contents: read |
| 125 | + packages: write |
| 126 | + id-token: write |
| 127 | + timeout-minutes: 10 |
| 128 | + concurrency: |
| 129 | + group: ${{ github.workflow }}-${{ github.ref }}-merge |
| 130 | + cancel-in-progress: true |
| 131 | + steps: |
| 132 | + - name: Download digests |
| 133 | + uses: actions/download-artifact@v6 |
| 134 | + with: |
| 135 | + path: /tmp/digests |
| 136 | + pattern: cli-docker-digests-* |
| 137 | + merge-multiple: true |
| 138 | + |
| 139 | + - name: List digests |
| 140 | + run: ls -la /tmp/digests |
| 141 | + |
| 142 | + - name: Set up Docker Buildx |
| 143 | + uses: docker/setup-buildx-action@v3 |
| 144 | + |
| 145 | + - name: Create Docker Metadata |
| 146 | + id: meta |
| 147 | + uses: docker/metadata-action@v5 |
| 148 | + with: |
| 149 | + images: | |
| 150 | + docker.io/${{ github.repository }} |
| 151 | + ghcr.io/${{ github.repository }} |
| 152 | + tags: | |
| 153 | + type=raw,value=${{ inputs.tag_name }} |
| 154 | + type=raw,value=latest,enable=${{ inputs.is_prerelease == 'true' }} |
| 155 | + type=semver,pattern={{version}},value=${{ inputs.tag_name }},enable=${{ inputs.is_prerelease == 'false' }} |
| 156 | + type=semver,pattern={{major}}.{{minor}},value=${{ inputs.tag_name }},enable=${{ inputs.is_prerelease == 'false' }} |
| 157 | + type=semver,pattern={{major}},value=${{ inputs.tag_name }},enable=${{ inputs.is_prerelease == 'false' }} |
| 158 | +
|
| 159 | + - name: Login to Docker Hub |
| 160 | + uses: docker/login-action@v3 |
| 161 | + with: |
| 162 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 163 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 164 | + |
| 165 | + - name: Login to GitHub Container Registry |
| 166 | + uses: docker/login-action@v3 |
| 167 | + with: |
| 168 | + registry: ghcr.io |
| 169 | + username: ${{ github.actor }} |
| 170 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 171 | + |
| 172 | + - name: Create manifest list and push |
| 173 | + working-directory: /tmp/digests |
| 174 | + run: | |
| 175 | + # Extract all tags |
| 176 | + image_tags=$(printf '%s' "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr '.tags | map("-t " + .) | join(" ")') |
| 177 | + echo "Creating manifest list with tags: $image_tags" |
| 178 | +
|
| 179 | + # Extract unique image names (without tags) to build digest references |
| 180 | + image_names=$(printf '%s' "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr '.tags | map(split(":")[0]) | unique | join(" ")') |
| 181 | + echo "Image names: $image_names" |
| 182 | +
|
| 183 | + # Build digest references for all images |
| 184 | + digest_refs="" |
| 185 | + for image_name in $image_names; do |
| 186 | + for digest_file in *; do |
| 187 | + digest_refs="$digest_refs ${image_name}@sha256:${digest_file}" |
| 188 | + done |
| 189 | + done |
| 190 | + echo "Digest references: $digest_refs" |
| 191 | +
|
| 192 | + echo "Creating manifest using buildx..." |
| 193 | + docker buildx imagetools create $image_tags $digest_refs |
| 194 | +
|
| 195 | + # Inspect the first tag for verification |
| 196 | + first_tag=$(printf '%s' "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr '.tags[0]') |
| 197 | + docker buildx imagetools inspect "$first_tag" |
0 commit comments