|
| 1 | +name: Build docker container |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: [ created, edited ] |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + tag: |
| 8 | + description: 'tag' |
| 9 | + required: true |
| 10 | + default: 'latest' |
| 11 | + type: string |
| 12 | +jobs: |
| 13 | + var: |
| 14 | + name: Set variables |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + platform: "linux" |
| 18 | + image: "ghcr.io/${{ github.repository }}" |
| 19 | + tag: ${{ steps.var.outputs.tag }} |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + - name: Set variables |
| 26 | + id: var |
| 27 | + run: | |
| 28 | + if [ "${{ github.event_name }}" != "release" ] && [ "${{ inputs.tag }}" != "latest" ]; then |
| 29 | + TAG="${{ inputs.tag }}" && echo "tag=${TAG#v}" >> $GITHUB_OUTPUT |
| 30 | + else |
| 31 | + TAG="$(git describe --tags)" && echo "tag=${TAG#v}" >> $GITHUB_OUTPUT |
| 32 | + fi |
| 33 | + build: |
| 34 | + name: Build |
| 35 | + needs: var |
| 36 | + strategy: |
| 37 | + matrix: |
| 38 | + arch: [ amd64, arm64 ] |
| 39 | + runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || matrix.arch }} |
| 40 | + steps: |
| 41 | + - name: Install git |
| 42 | + run: | |
| 43 | + sudo apt -y update |
| 44 | + sudo apt -y install build-essential git |
| 45 | + git config --global advice.detachedHead false |
| 46 | + - name: Checkout |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + - name: Login |
| 51 | + uses: docker/login-action@v3 |
| 52 | + with: |
| 53 | + registry: ghcr.io |
| 54 | + username: ${{ github.repository_owner }} |
| 55 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + - name: Build |
| 57 | + run: | |
| 58 | + git checkout v${{ needs.var.outputs.tag }} |
| 59 | + make docker |
| 60 | + - name: Push |
| 61 | + run: | |
| 62 | + docker image tag \ |
| 63 | + go-client-${{ needs.var.outputs.platform }}-${{ matrix.arch }}:${{ needs.var.outputs.tag }} \ |
| 64 | + ${{ needs.var.outputs.image }}-${{ matrix.arch }}:${{ needs.var.outputs.tag }} |
| 65 | + docker push ${{ needs.var.outputs.image }}-${{ matrix.arch }}:${{ needs.var.outputs.tag }} |
| 66 | + manifest: |
| 67 | + name: Manifest |
| 68 | + needs: |
| 69 | + - var |
| 70 | + - build |
| 71 | + strategy: |
| 72 | + matrix: |
| 73 | + include: |
| 74 | + - tag: ${{ needs.var.outputs.tag }} |
| 75 | + - tag: latest |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + - name: Login |
| 79 | + uses: docker/login-action@v3 |
| 80 | + with: |
| 81 | + registry: ghcr.io |
| 82 | + username: ${{ github.repository_owner }} |
| 83 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + - name: Create Manifest |
| 85 | + run: | |
| 86 | + docker manifest create ${{ needs.var.outputs.image }}:${{ matrix.tag }} \ |
| 87 | + --amend ${{ needs.var.outputs.image }}-amd64:${{ needs.var.outputs.tag }} \ |
| 88 | + --amend ${{ needs.var.outputs.image }}-arm64:${{ needs.var.outputs.tag }} |
| 89 | + docker manifest annotate --arch arm64 \ |
| 90 | + ${{ needs.var.outputs.image }}:${{ matrix.tag }} \ |
| 91 | + ${{ needs.var.outputs.image }}-arm64:${{ needs.var.outputs.tag }} |
| 92 | + docker manifest annotate --arch amd64 \ |
| 93 | + ${{ needs.var.outputs.image }}:${{ matrix.tag }} \ |
| 94 | + ${{ needs.var.outputs.image }}-amd64:${{ needs.var.outputs.tag }} |
| 95 | + docker manifest push ${{ needs.var.outputs.image }}:${{ matrix.tag }} |
0 commit comments