|
| 1 | +name: Codegen Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + paths: |
| 8 | + - 'codegen/**' |
| 9 | + - '.github/workflows/codegen-docker.yml' |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + REGISTRY_IMAGE: ghcr.io/meteroid-oss/openapi-codegen |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + platform: |
| 23 | + - runner: ubuntu-24.04 |
| 24 | + name: amd64 |
| 25 | + build-args: | |
| 26 | + BIOME_DL_LINK=https://github.com/biomejs/biome/releases/download/%40biomejs%2Fbiome%402.1.4/biome-linux-x64-musl |
| 27 | + BIOME_SHA256=6d6bd2213cffab0d68d741c0be466bcd21cd6f5eca1e0e5aac2a991bf9f17cf2 |
| 28 | + JAVAFMT_DL_LINK=https://repo1.maven.org/maven2/com/palantir/javaformat/palantir-java-format-native/2.75.0/palantir-java-format-native-2.75.0-nativeImage-linux-glibc_x86-64.bin |
| 29 | + JAVAFMT_SHA256=9d8c9e65cff44bb847d16b4db2ccbd6dacbe32611eaf2587748013eda931cdac |
| 30 | + - runner: ubuntu-24.04-arm |
| 31 | + name: arm64 |
| 32 | + build-args: | |
| 33 | + BIOME_DL_LINK=https://github.com/biomejs/biome/releases/download/%40biomejs%2Fbiome%402.1.4/biome-linux-arm64-musl |
| 34 | + BIOME_SHA256=ffa05ea6ec0e73072e46301a692eb9413d5b683366e86ab7243414ae944f4ec4 |
| 35 | + JAVAFMT_DL_LINK=https://repo1.maven.org/maven2/com/palantir/javaformat/palantir-java-format-native/2.75.0/palantir-java-format-native-2.75.0-nativeImage-linux-glibc_aarch64.bin |
| 36 | + JAVAFMT_SHA256=371e226632a5c455f017fe2ce2a614abe8cf81c743b4c27fb998373b790c2a3b |
| 37 | + name: Build and publish ${{ matrix.platform.name }} docker image |
| 38 | + if: github.ref == 'refs/heads/main' |
| 39 | + runs-on: "${{ matrix.platform.runner }}" |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Login to ghcr |
| 44 | + uses: docker/login-action@v3 |
| 45 | + with: |
| 46 | + registry: ghcr.io |
| 47 | + username: ${{ github.actor }} |
| 48 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Set up Docker Buildx |
| 51 | + uses: docker/setup-buildx-action@v3 |
| 52 | + |
| 53 | + - name: Build and push by digest |
| 54 | + id: build |
| 55 | + uses: docker/build-push-action@v6 |
| 56 | + with: |
| 57 | + tags: ${{ env.REGISTRY_IMAGE }} |
| 58 | + build-args: ${{ matrix.platform.build-args }} |
| 59 | + context: codegen |
| 60 | + file: codegen/Dockerfile |
| 61 | + cache-from: type=gha |
| 62 | + cache-to: type=gha,mode=max |
| 63 | + platforms: linux/${{ matrix.platform.name }} |
| 64 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 65 | + |
| 66 | + - name: Export digest |
| 67 | + run: | |
| 68 | + mkdir -p ${{ runner.temp }}/digests |
| 69 | + digest="${{ steps.build.outputs.digest }}" |
| 70 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 71 | +
|
| 72 | + - name: Upload digest |
| 73 | + uses: actions/upload-artifact@v4 |
| 74 | + with: |
| 75 | + name: digests-${{ matrix.platform.name }} |
| 76 | + path: ${{ runner.temp }}/digests/* |
| 77 | + if-no-files-found: error |
| 78 | + retention-days: 1 |
| 79 | + |
| 80 | + publish-merged-manifest: |
| 81 | + permissions: |
| 82 | + contents: read |
| 83 | + packages: write |
| 84 | + if: github.ref == 'refs/heads/main' |
| 85 | + runs-on: ubuntu-24.04 |
| 86 | + needs: |
| 87 | + - build |
| 88 | + steps: |
| 89 | + - uses: actions/checkout@v4 |
| 90 | + with: |
| 91 | + fetch-depth: 0 |
| 92 | + |
| 93 | + - name: Download digests |
| 94 | + uses: actions/download-artifact@v4 |
| 95 | + with: |
| 96 | + path: ${{ runner.temp }}/digests |
| 97 | + pattern: digests-* |
| 98 | + merge-multiple: true |
| 99 | + |
| 100 | + - name: Login to ghcr |
| 101 | + uses: docker/login-action@v3 |
| 102 | + with: |
| 103 | + registry: ghcr.io |
| 104 | + username: ${{ github.actor }} |
| 105 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + |
| 107 | + - name: Set up Docker Buildx |
| 108 | + uses: docker/setup-buildx-action@v3 |
| 109 | + |
| 110 | + - run: echo "IMAGE_TAG=$(date --utc +%Y%m%d)-$(git rev-list ${{ github.sha }} --count)" >> "$GITHUB_ENV" |
| 111 | + |
| 112 | + - name: Create manifest list and push |
| 113 | + working-directory: ${{ runner.temp }}/digests |
| 114 | + run: | |
| 115 | + docker buildx imagetools create \ |
| 116 | + -t ${{ env.REGISTRY_IMAGE }}:latest \ |
| 117 | + -t ${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }} \ |
| 118 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 119 | +
|
| 120 | + - name: Inspect image |
| 121 | + run: | |
| 122 | + docker buildx imagetools inspect "${{ env.REGISTRY_IMAGE }}:latest" |
0 commit comments