|
| 1 | +name: docker build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "**" |
| 7 | + tags: |
| 8 | + - "**" |
| 9 | + pull_request_target: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + packages: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + docker: |
| 17 | + name: Publish Docker image |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v2 |
| 22 | + - name: Docker meta |
| 23 | + id: docker_meta |
| 24 | + |
| 25 | + with: |
| 26 | + images: ghcr.io/${{ github.repository }} |
| 27 | + flavor: | |
| 28 | + latest=false |
| 29 | + tags: | |
| 30 | + type=ref,event=pr |
| 31 | + type=ref,event=branch |
| 32 | + type=sha,prefix=,format=long,event=branch |
| 33 | + type=ref,event=tag |
| 34 | + type=sha,prefix=,format=long,event=tag |
| 35 | + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} |
| 36 | + - name: Set up Docker Buildx |
| 37 | + uses: docker/setup-buildx-action@v1 |
| 38 | + - name: Login to GitHub Container Registry |
| 39 | + uses: docker/login-action@v1 |
| 40 | + with: |
| 41 | + registry: ghcr.io |
| 42 | + username: ${{ github.repository_owner }} |
| 43 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + - name: Cache Docker layers |
| 45 | + |
| 46 | + with: |
| 47 | + path: /tmp/.buildx-cache |
| 48 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 49 | + restore-keys: | |
| 50 | + ${{ runner.os }}-buildx- |
| 51 | + - name: Build and push |
| 52 | + uses: docker/build-push-action@v2 |
| 53 | + with: |
| 54 | + context: . |
| 55 | + push: true |
| 56 | + tags: ${{ steps.docker_meta.outputs.tags }} |
| 57 | + labels: ${{ steps.docker_meta.outputs.labels }} |
| 58 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 59 | + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max |
0 commit comments