1name: Build and Push API
2
3on:
4 push:
5 workflow_dispatch:
6
7env:
8 REGISTRY: ghcr.io
9 IMAGE_NAME: ${{ github.repository }}/api
10
11jobs:
12 build-and-push:
13 runs-on: ubuntu-latest
14 permissions:
15 contents: read
16 packages: write
17
18 steps:
19 - name: Checkout repository
20 uses: actions/checkout@v4
21
22 - name: Log in to the Container registry
23 uses: docker/login-action@v3
24 with:
25 registry: ${{ env.REGISTRY }}
26 username: ${{ github.actor }}
27 password: ${{ secrets.GITHUB_TOKEN }}
28
29 - name: Extract metadata (tags, labels) for Docker
30 id: meta
31 uses: docker/metadata-action@v5
32 with:
33 images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34 tags: |
35 type=ref,event=branch
36 type=ref,event=pr
37 type=semver,pattern={{version}}
38 type=semver,pattern={{major}}.{{minor}}
39 type=semver,pattern={{major}}
40 type=sha,prefix={{branch}}-
41
42 - name: Set up Docker Buildx
43 uses: docker/setup-buildx-action@v3
44
45 - name: Build and push Docker image
46 uses: docker/build-push-action@v5
47 with:
48 context: .
49 file: ./cmd/api/Dockerfile
50 push: true
51 tags: ${{ steps.meta.outputs.tags }}
52 labels: ${{ steps.meta.outputs.labels }}
53 cache-from: type=gha
54 cache-to: type=gha,mode=max