|
| 1 | +name: Publish Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published, edited] |
| 6 | + |
| 7 | +env: |
| 8 | + dockerhub_user: kloeckneri |
| 9 | + manufacturer: kloeckner-i |
| 10 | + product_name: db-auth-gateway |
| 11 | + go_version: "1.18" |
| 12 | + go_os: linux |
| 13 | + main_go_path: ./cmd |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - go_arch: "amd64" |
| 22 | + docker_arch: "amd64" |
| 23 | + - go_arch: "arm64" |
| 24 | + docker_arch: "arm64/v8" |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Setup go |
| 30 | + uses: actions/setup-go@v2 |
| 31 | + with: |
| 32 | + go-version: ${{ env.go_version }} |
| 33 | + |
| 34 | + - name: Compile Binary |
| 35 | + env: |
| 36 | + GOOS: ${{ env.go_os }} |
| 37 | + GOARCH: ${{ matrix.go_arch }} |
| 38 | + CGO_ENABLED: "0" |
| 39 | + run: | |
| 40 | + go build -tags build -o ${{ env.product_name }} ${{ env.main_go_path }} |
| 41 | +
|
| 42 | + - name: Set up Docker Buildx |
| 43 | + uses: docker/setup-buildx-action@v2 |
| 44 | + |
| 45 | + - name: Login to GitHub Container Registry |
| 46 | + uses: docker/login-action@v1 |
| 47 | + with: |
| 48 | + registry: ghcr.io |
| 49 | + username: ${{ github.actor }} |
| 50 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Login to Dockerhub |
| 53 | + uses: docker/login-action@v1 |
| 54 | + with: |
| 55 | + username: ${{ env.dockerhub_user }} |
| 56 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Set action link variable |
| 59 | + run: echo "LINK=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV |
| 60 | + |
| 61 | + - name: Build and export |
| 62 | + uses: docker/build-push-action@v3 |
| 63 | + with: |
| 64 | + push: true |
| 65 | + context: . |
| 66 | + file: Dockerfile-ci |
| 67 | + platforms: ${{ env.go_os }}/${{ matrix.docker_arch }} |
| 68 | + tags: | |
| 69 | + ${{ env.dockerhub_user }}/${{ env.product_name }}:latest-${{ matrix.go_arch }} |
| 70 | + ${{ env.dockerhub_user }}/${{ env.product_name }}:${{ github.event.release.tag_name }}-${{ matrix.go_arch }} |
| 71 | + ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:latest-${{ matrix.go_arch }} |
| 72 | + ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:${{ github.event.release.tag_name }}-${{ matrix.go_arch }} |
| 73 | + labels: | |
| 74 | + action_link=${{ env.LINK }} |
| 75 | + actor=${{ github.actor }} |
| 76 | + sha=${{ github.sha }} |
| 77 | + ref=${{ github.ref }} |
| 78 | +
|
| 79 | + push_to_ghcr: |
| 80 | + runs-on: ubuntu-latest |
| 81 | + needs: build |
| 82 | + steps: |
| 83 | + - name: Set up Docker Buildx |
| 84 | + uses: docker/setup-buildx-action@v2 |
| 85 | + |
| 86 | + - name: Login to GitHub Container Registry |
| 87 | + uses: docker/login-action@v2 |
| 88 | + with: |
| 89 | + registry: ghcr.io |
| 90 | + username: ${{ github.actor }} |
| 91 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + |
| 93 | + - name: Create a docker manifest for a versioned container |
| 94 | + run: | |
| 95 | + docker manifest create ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:${{ github.event.release.tag_name }} \ |
| 96 | + --amend ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:${{ github.event.release.tag_name }}-amd64 \ |
| 97 | + --amend ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:${{ github.event.release.tag_name }}-arm64 |
| 98 | +
|
| 99 | + - name: Create a manifest for the latest container |
| 100 | + run: | |
| 101 | + docker manifest create ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:latest \ |
| 102 | + --amend ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:latest-amd64 \ |
| 103 | + --amend ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:latest-arm64 |
| 104 | +
|
| 105 | + - name: Push the manifest |
| 106 | + run: | |
| 107 | + docker manifest push ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:${{ github.event.release.tag_name }} |
| 108 | + docker manifest push ghcr.io/${{ env.manufacturer }}/${{ env.product_name }}:latest |
| 109 | +
|
| 110 | + push_to_dockerhub: |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: build |
| 113 | + steps: |
| 114 | + - name: Set up Docker Buildx |
| 115 | + uses: docker/setup-buildx-action@v2 |
| 116 | + |
| 117 | + - name: Login to GitHub Container Registry |
| 118 | + uses: docker/login-action@v2 |
| 119 | + with: |
| 120 | + username: ${{ env.dockerhub_user }} |
| 121 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 122 | + |
| 123 | + - name: Create a docker manifest for a versioned container |
| 124 | + run: | |
| 125 | + docker manifest create ${{ env.dockerhub_user }}/${{ env.product_name }}:${{ github.event.release.tag_name }} \ |
| 126 | + --amend ${{ env.dockerhub_user }}/${{ env.product_name }}:${{ github.event.release.tag_name }}-amd64 \ |
| 127 | + --amend ${{ env.dockerhub_user }}/${{ env.product_name }}:${{ github.event.release.tag_name }}-arm64 |
| 128 | +
|
| 129 | + - name: Create a manifest for the latest container |
| 130 | + run: | |
| 131 | + docker manifest create ${{ env.dockerhub_user }}/${{ env.product_name }}:latest \ |
| 132 | + --amend ${{ env.dockerhub_user }}/${{ env.product_name }}:latest-amd64 \ |
| 133 | + --amend ${{ env.dockerhub_user }}/${{ env.product_name }}:latest-arm64 |
| 134 | +
|
| 135 | + - name: Push the manifest |
| 136 | + run: | |
| 137 | + docker manifest push ${{ env.dockerhub_user }}/${{ env.product_name }}:${{ github.event.release.tag_name }} |
| 138 | + docker manifest push ${{ env.dockerhub_user }}/${{ env.product_name }}:latest |
| 139 | +
|
0 commit comments