|
1 | | -name: Docker Publish |
| 1 | +# .github/workflows/docker-publish.yml |
| 2 | +name: Docker Build and Publish |
2 | 3 |
|
3 | 4 | on: |
4 | 5 | push: |
5 | | - branches: ["main"] |
6 | | - # Publish semver tags as releases. |
7 | | - tags: ["v*.*.*"] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - develop |
| 9 | + - "feature/**" |
| 10 | + - "hotfix/**" |
| 11 | + tags: |
| 12 | + - "v*.*.*" |
| 13 | + pull_request: |
| 14 | + branches: |
| 15 | + - main |
| 16 | + - develop |
8 | 17 |
|
9 | 18 | env: |
10 | | - # Use docker.io for Docker Hub if empty |
11 | 19 | REGISTRY: ghcr.io |
12 | | - # github.repository as <account>/<repo> |
13 | 20 | IMAGE_NAME: ${{ github.repository }} |
14 | 21 |
|
15 | 22 | jobs: |
16 | | - build: |
| 23 | + lint: |
| 24 | + name: Lint Dockerfile |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Lint Dockerfile |
| 31 | + |
| 32 | + with: |
| 33 | + dockerfile: Dockerfile |
| 34 | + |
| 35 | + build-and-push: |
| 36 | + name: Build and Push Docker image |
| 37 | + needs: lint |
17 | 38 | runs-on: ubuntu-latest |
18 | 39 | permissions: |
19 | 40 | contents: read |
20 | 41 | packages: write |
21 | 42 |
|
22 | 43 | steps: |
23 | | - - name: Checkout repository |
24 | | - uses: actions/checkout@v3 |
| 44 | + - name: Checkout code |
| 45 | + uses: actions/checkout@v4 |
25 | 46 |
|
26 | | - # Install the cosign tool except on PR |
27 | | - |
28 | | - # Set up BuildKit Docker container builder to be able to build |
29 | | - # multi-platform images and export cache |
30 | | - # https://github.com/docker/setup-buildx-action |
31 | 47 | - name: Set up Docker Buildx |
32 | | - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 48 | + uses: docker/setup-buildx-action@v3 |
33 | 49 |
|
34 | | - # Login against a Docker registry except on PR |
35 | | - # https://github.com/docker/login-action |
36 | | - - name: Log into registry ${{ env.REGISTRY }} |
37 | | - if: github.event_name != 'pull_request' |
38 | | - uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 50 | + - name: Log in to GitHub Container Registry |
| 51 | + uses: docker/login-action@v3 |
39 | 52 | with: |
40 | 53 | registry: ${{ env.REGISTRY }} |
41 | 54 | username: ${{ github.actor }} |
42 | 55 | password: ${{ secrets.GITHUB_TOKEN }} |
43 | 56 |
|
44 | | - # Extract metadata (tags, labels) for Docker |
45 | | - # https://github.com/docker/metadata-action |
46 | | - - name: Extract Docker metadata |
| 57 | + - name: Extract metadata for Docker |
47 | 58 | id: meta |
48 | | - uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 |
| 59 | + uses: docker/metadata-action@v5 |
49 | 60 | with: |
50 | 61 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 62 | + tags: | |
| 63 | + type=sha,format=long |
| 64 | + type=ref,event=branch |
| 65 | + type=ref,event=pr |
| 66 | + type=semver,pattern={{version}} |
| 67 | + type=semver,pattern={{major}}.{{minor}} |
| 68 | + type=raw,value=latest,enable={{is_default_branch}} |
| 69 | + type=raw,value=dev,enable=${{ github.ref == 'refs/heads/develop' }} |
51 | 70 |
|
52 | | - # Build and push Docker image with Buildx (don't push on PR) |
53 | | - # https://github.com/docker/build-push-action |
54 | 71 | - name: Build and push Docker image |
55 | | - id: build-and-push |
56 | | - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 |
| 72 | + uses: docker/build-push-action@v5 |
57 | 73 | with: |
58 | 74 | context: . |
59 | | - platforms: linux/amd64,linux/arm64 |
60 | 75 | push: ${{ github.event_name != 'pull_request' }} |
61 | 76 | tags: ${{ steps.meta.outputs.tags }} |
62 | 77 | labels: ${{ steps.meta.outputs.labels }} |
63 | 78 | cache-from: type=gha |
64 | 79 | cache-to: type=gha,mode=max |
| 80 | + |
| 81 | + - name: Print image tags |
| 82 | + if: github.event_name != 'pull_request' |
| 83 | + run: | |
| 84 | + echo "Published tags:" |
| 85 | + echo "${{ steps.meta.outputs.tags }}" | tr ' ' '\n' |
0 commit comments