|
1 | 1 | name: Build and Push Docker Image |
| 2 | + |
2 | 3 | on: |
3 | 4 | push: |
4 | 5 | branches: |
5 | 6 | - add-actions |
| 7 | + - main |
| 8 | + |
6 | 9 | env: |
7 | 10 | REGISTRY: ghcr.io |
8 | 11 | IMAGE_NAME: ${{ github.repository }} |
9 | 12 |
|
10 | | - |
11 | 13 | concurrency: |
12 | 14 | group: push-to-registry-${{ github.head_ref || github.run_id }} |
13 | 15 | cancel-in-progress: true |
14 | 16 |
|
15 | 17 | jobs: |
16 | 18 | push_to_registry: |
17 | | - name: Build image |
| 19 | + name: Build and Push Docker Image |
18 | 20 | runs-on: ubuntu-latest |
19 | | - strategy: |
20 | | - fail-fast: false |
21 | | - |
| 21 | + |
22 | 22 | permissions: |
23 | | - packages: write |
24 | 23 | contents: read |
| 24 | + packages: write |
| 25 | + |
25 | 26 | steps: |
26 | | - - name: Check out the repo |
| 27 | + - name: Checkout repository |
27 | 28 | uses: actions/checkout@v4 |
28 | | - - name: Docker meta |
29 | | - uses: docker/metadata-action@v5 |
30 | | - id: meta |
31 | | - |
32 | | - - name: Set up QEMU |
33 | | - uses: docker/setup-qemu-action@v3 |
| 29 | + |
34 | 30 | - name: Set up Docker Buildx |
35 | 31 | uses: docker/setup-buildx-action@v3 |
36 | | - - name: Cache Docker layers |
37 | | - uses: actions/cache@v4 |
38 | | - with: |
39 | | - path: /tmp/.buildx-cache |
40 | | - key: ${{ matrix.container }}-buildx-${{ github.sha }} |
41 | | - restore-keys: | |
42 | | - ${{ matrix.container }}-buildx- |
43 | | - - name: Log in to GitHub Container Registry |
| 32 | + |
| 33 | + - name: Log in to Container Registry |
44 | 34 | uses: docker/login-action@v3 |
45 | 35 | with: |
46 | | - registry: ghcr.io |
| 36 | + registry: ${{ env.REGISTRY }} |
47 | 37 | username: ${{ github.actor }} |
48 | 38 | password: ${{ secrets.GITHUB_TOKEN }} |
49 | | - - name: Build container image |
50 | | - uses: docker/build-push-action@v6 |
| 39 | + |
| 40 | + - name: Extract metadata |
| 41 | + id: meta |
| 42 | + uses: docker/metadata-action@v5 |
51 | 43 | with: |
52 | | - push: false |
53 | | - context: .docker |
54 | | - platforms: linux/amd64,linux/arm64 |
55 | | - file: .docker/app/Dockerfile |
56 | | - tags: ${{ steps.meta.outputs.tags }} |
57 | | - |
58 | | - - name: Push container image |
| 44 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 45 | + tags: | |
| 46 | + type=ref,event=branch |
| 47 | + type=sha,prefix=sha- |
| 48 | + type=raw,value=latest,enable={{is_default_branch}} |
| 49 | + |
| 50 | + - name: Build and push Docker image |
59 | 51 | uses: docker/build-push-action@v6 |
60 | 52 | with: |
61 | | - push: true |
62 | 53 | context: .docker |
63 | | - platforms: linux/amd64,linux/arm64 |
64 | 54 | file: .docker/app/Dockerfile |
| 55 | + platforms: linux/amd64,linux/arm64 |
| 56 | + push: true |
65 | 57 | tags: ${{ steps.meta.outputs.tags }} |
66 | | - cache-from: type=local,src=/tmp/.buildx-cache |
67 | | - cache-to: type=local,dest=/tmp/.buildx-cache-new |
68 | | - - name: Move cache |
69 | | - run: | |
70 | | - rm -rf /tmp/.buildx-cache |
71 | | - mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 58 | + labels: ${{ steps.meta.outputs.labels }} |
| 59 | + cache-from: type=gha |
| 60 | + cache-to: type=gha,mode=max |
0 commit comments