|
| 1 | +--- |
| 2 | +name: Build Linux Images |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + dry_run: |
| 8 | + description: 'Dry run: build images but do not push to Docker Hub or create manifest lists' |
| 9 | + type: boolean |
| 10 | + default: true |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +env: |
| 16 | + SRCML_BAKE_REGISTRY: "" |
| 17 | + |
| 18 | +jobs: |
| 19 | + bake: |
| 20 | + name: bake-${{ matrix.arch }} |
| 21 | + if: ${{ github.repository == 'srcML/srcML' }} |
| 22 | + environment: build |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - arch: amd64 |
| 28 | + runner: ubuntu-24.04 |
| 29 | + - arch: arm64 |
| 30 | + runner: ubuntu-24.04-arm |
| 31 | + runs-on: ${{ matrix.runner }} |
| 32 | + steps: |
| 33 | + - name: Checkout Repository |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Set up Docker Buildx |
| 37 | + uses: docker/setup-buildx-action@v3 |
| 38 | + |
| 39 | + - name: Log in to Docker Hub |
| 40 | + if: ${{ !inputs.dry_run }} |
| 41 | + uses: docker/login-action@v3 |
| 42 | + with: |
| 43 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 44 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Bake images for ${{ matrix.arch }}${{ inputs.dry_run && ' (dry run)' || '' }} |
| 47 | + run: | |
| 48 | + if [[ "${{ inputs.dry_run }}" == "true" ]]; then |
| 49 | + docker buildx bake \ |
| 50 | + --set "*.output=type=cacheonly" \ |
| 51 | + --metadata-file metadata-${{ matrix.arch }}.json |
| 52 | + else |
| 53 | + docker buildx bake \ |
| 54 | + --set "*.output=type=image,push-by-digest=true,name-canonical=true,push=true" \ |
| 55 | + --metadata-file metadata-${{ matrix.arch }}.json |
| 56 | + fi |
| 57 | + env: |
| 58 | + SRCML_BAKE_ARCHITECTURE: linux/${{ matrix.arch }} |
| 59 | + |
| 60 | + - name: Upload bake metadata |
| 61 | + uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: bake-metadata-${{ matrix.arch }} |
| 64 | + path: metadata-${{ matrix.arch }}.json |
| 65 | + if-no-files-found: error |
| 66 | + |
| 67 | + merge: |
| 68 | + name: merge-manifests |
| 69 | + needs: bake |
| 70 | + if: ${{ !inputs.dry_run && github.repository == 'srcML/srcML' }} |
| 71 | + environment: build |
| 72 | + runs-on: ubuntu-24.04 |
| 73 | + steps: |
| 74 | + - name: Checkout Repository |
| 75 | + uses: actions/checkout@v4 |
| 76 | + |
| 77 | + - name: Set up Docker Buildx |
| 78 | + uses: docker/setup-buildx-action@v3 |
| 79 | + |
| 80 | + - name: Log in to Docker Hub |
| 81 | + uses: docker/login-action@v3 |
| 82 | + with: |
| 83 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 84 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 85 | + |
| 86 | + - name: Download all bake metadata |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + pattern: bake-metadata-* |
| 90 | + merge-multiple: true |
| 91 | + |
| 92 | + - name: Create multi-arch manifest lists |
| 93 | + run: | |
| 94 | + docker buildx bake --print > bake-plan.json |
| 95 | + jq -r ' |
| 96 | + .target | to_entries[] | |
| 97 | + .key as $target | |
| 98 | + .value.tags[] | |
| 99 | + . as $tag | |
| 100 | + split(":")[0] as $repo | |
| 101 | + "\($tag) \($repo) \($target)" |
| 102 | + ' bake-plan.json | while read -r tag repo target; do |
| 103 | + amd64_digest=$(jq -r --arg t "$target" '.[$t]."containerimage.digest" // empty' metadata-amd64.json) |
| 104 | + arm64_digest=$(jq -r --arg t "$target" '.[$t]."containerimage.digest" // empty' metadata-arm64.json) |
| 105 | + if [[ -z "$amd64_digest" || -z "$arm64_digest" ]]; then |
| 106 | + echo "Missing digest for target $target (amd64='$amd64_digest' arm64='$arm64_digest')" >&2 |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + echo "Creating manifest $tag from $repo@$amd64_digest + $repo@$arm64_digest" |
| 110 | + docker buildx imagetools create -t "$tag" \ |
| 111 | + "${repo}@${amd64_digest}" \ |
| 112 | + "${repo}@${arm64_digest}" |
| 113 | + done |
0 commit comments