|
| 1 | +name: docker-image-push |
| 2 | + |
| 3 | +# This workflow uses actions that are not certified by GitHub. |
| 4 | +# They are provided by a third-party and are governed by |
| 5 | +# separate terms of service, privacy policy, and support |
| 6 | +# documentation. |
| 7 | +on: |
| 8 | + push: |
| 9 | + tags: [ 'v*.*.*' ] |
| 10 | + |
| 11 | +env: |
| 12 | + # Use docker.io for Docker Hub if empty |
| 13 | + REGISTRY: ghcr.io |
| 14 | + # github.repository as <account>/<repo> |
| 15 | + IMAGE_NAME: adobe/kratos |
| 16 | + |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v2 |
| 29 | + |
| 30 | + - name: Set up Go |
| 31 | + uses: actions/setup-go@v2 |
| 32 | + with: |
| 33 | + go-version: 1.14 |
| 34 | + |
| 35 | + - name: Run Mage build |
| 36 | + uses: magefile/mage-action@v1 |
| 37 | + with: |
| 38 | + version: latest |
| 39 | + args: operator:build |
| 40 | + |
| 41 | + # Login against a Docker registry except on PR |
| 42 | + # https://github.com/docker/login-action |
| 43 | + - name: Log into registry ${{ env.REGISTRY }} |
| 44 | + if: github.event_name != 'pull_request' |
| 45 | + uses: docker/login-action@v1 |
| 46 | + with: |
| 47 | + registry: ${{ env.REGISTRY }} |
| 48 | + username: ${{ github.actor }} |
| 49 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + |
| 51 | + # Extract metadata (tags, labels) for Docker |
| 52 | + # https://github.com/docker/metadata-action |
| 53 | + - name: Extract Docker metadata |
| 54 | + id: meta |
| 55 | + uses: docker/metadata-action@v3 |
| 56 | + with: |
| 57 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 58 | + |
| 59 | + # Build and push Docker image with Buildx (don't push on PR) |
| 60 | + # https://github.com/docker/build-push-action |
| 61 | + - name: Build and push Docker image |
| 62 | + uses: docker/build-push-action@v2 |
| 63 | + with: |
| 64 | + context: . |
| 65 | + push: ${{ github.event_name != 'pull_request' }} |
| 66 | + tags: ${{ steps.meta.outputs.tags }} |
| 67 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments