|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "**" |
| 7 | + paths: |
| 8 | + - "Dockerfile" |
| 9 | + - "go.mod" |
| 10 | + - "go.sum" |
| 11 | + - "**/*.go" |
| 12 | + - "!cmd/folder-precreator/**" |
| 13 | + - ".github/workflows/build.yml" |
| 14 | + tags: |
| 15 | + - "*" |
| 16 | + pull_request: |
| 17 | + paths: |
| 18 | + - "Dockerfile" |
| 19 | + - "go.mod" |
| 20 | + - "go.sum" |
| 21 | + - "**/*.go" |
| 22 | + - "!cmd/folder-precreator/**" |
| 23 | + - ".github/workflows/build.yml" |
| 24 | + |
| 25 | +env: |
| 26 | + REGISTRY: europe-west4-docker.pkg.dev/artifact-registry-5n/dapla-lab-docker/dapla |
| 27 | + IMAGE: labid |
| 28 | + TAG: ${{ github.ref_name }}-${{ github.sha }} |
| 29 | + |
| 30 | +jobs: |
| 31 | + docker: |
| 32 | + permissions: |
| 33 | + contents: "read" |
| 34 | + id-token: "write" |
| 35 | + runs-on: ubuntu-latest |
| 36 | + env: |
| 37 | + PLATFORMS: linux/amd64 |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v3 |
| 40 | + - id: "auth" |
| 41 | + name: "Authenticate to Google Cloud" |
| 42 | + uses: "google-github-actions/auth@v1.1.1" |
| 43 | + with: |
| 44 | + workload_identity_provider: "projects/848539402404/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions" |
| 45 | + service_account: "gh-actions-dapla-lab@artifact-registry-5n.iam.gserviceaccount.com" |
| 46 | + token_format: "access_token" |
| 47 | + - name: Set up QEMU |
| 48 | + uses: docker/setup-qemu-action@v2 |
| 49 | + - name: Set up Docker Buildx |
| 50 | + id: buildx |
| 51 | + uses: docker/setup-buildx-action@v2 |
| 52 | + - name: Login to registry |
| 53 | + uses: docker/login-action@v2 |
| 54 | + with: |
| 55 | + registry: ${{ env.REGISTRY }} |
| 56 | + username: "oauth2accesstoken" |
| 57 | + password: "${{ steps.auth.outputs.access_token }}" |
| 58 | + - name: Docker meta |
| 59 | + id: metadata |
| 60 | + uses: docker/metadata-action@v4 |
| 61 | + with: |
| 62 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE }} |
| 63 | + # Docker tags based on the following events/attributes |
| 64 | + tags: | |
| 65 | + type=schedule |
| 66 | + type=ref,event=branch |
| 67 | + type=ref,event=pr |
| 68 | + type=semver,pattern=v{{version}} |
| 69 | + type=semver,pattern=v{{major}}.{{minor}} |
| 70 | + type=semver,pattern=v{{major}} |
| 71 | + type=sha |
| 72 | + type=raw,value=${{ env.TAG }}, enable=true |
| 73 | + - name: Build and push |
| 74 | + uses: docker/build-push-action@v4 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + platforms: ${{ env.PLATFORMS }} |
| 78 | + file: Dockerfile |
| 79 | + push: ${{ github.event_name != 'pull_request' }} |
| 80 | + tags: | |
| 81 | + ${{ steps.metadata.outputs.tags }} |
| 82 | + labels: ${{ steps.metadata.outputs.labels }} |
| 83 | + - name: Image digest |
| 84 | + run: echo ${{ steps.docker_build.outputs.digest }} |
0 commit comments