|
1 | | -name: Build and Push Docker Image |
2 | 1 |
|
3 | | -on: |
4 | | - push: |
5 | | - branches: |
6 | | - - main |
7 | | - - master |
8 | | - paths-ignore: |
9 | | - - '**.md' |
10 | | - - 'docs/**' |
11 | | - - '.gitignore' |
12 | | - pull_request: |
13 | | - branches: |
14 | | - - main |
15 | | - - master |
16 | | - workflow_dispatch: |
17 | | - inputs: |
18 | | - tag: |
19 | | - description: 'Additional tag for the image' |
20 | | - required: false |
21 | | - default: '' |
22 | | - |
23 | | -env: |
24 | | - REGISTRY: ghcr.io |
25 | | - IMAGE_NAME: ${{ github.repository }} |
26 | | - |
27 | | -jobs: |
28 | | - build-and-push: |
29 | | - runs-on: ubuntu-latest |
30 | | - permissions: |
31 | | - contents: read |
32 | | - packages: write |
33 | | - |
34 | | - steps: |
35 | | - - name: Checkout repository |
36 | | - uses: actions/checkout@v4 |
37 | | - |
38 | | - - name: Set up Docker Buildx |
39 | | - uses: docker/setup-buildx-action@v3 |
40 | | - |
41 | | - - name: Log in to GitHub Container Registry |
42 | | - uses: docker/login-action@v3 |
43 | | - with: |
44 | | - registry: ${{ env.REGISTRY }} |
45 | | - username: ${{ github.actor }} |
46 | | - password: ${{ secrets.GITHUB_TOKEN }} |
47 | | - |
48 | | - - name: Extract metadata (tags, labels) |
49 | | - id: meta |
50 | | - uses: docker/metadata-action@v5 |
51 | | - with: |
52 | | - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
53 | | - tags: | |
54 | | - type=ref,event=branch |
55 | | - type=ref,event=pr |
56 | | - type=semver,pattern={{version}} |
57 | | - type=semver,pattern={{major}}.{{minor}} |
58 | | - type=raw,value=latest,enable={{is_default_branch}} |
59 | | - type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }} |
60 | | - type=sha,prefix={{branch}}- |
61 | | -
|
62 | | - - name: Build and push Docker image |
63 | | - id: build-push |
64 | | - uses: docker/build-push-action@v5 |
65 | | - with: |
66 | | - context: . |
67 | | - push: ${{ github.event_name != 'pull_request' }} |
68 | | - tags: ${{ steps.meta.outputs.tags }} |
69 | | - labels: ${{ steps.meta.outputs.labels }} |
70 | | - cache-from: type=gha |
71 | | - cache-to: type=gha,mode=max |
72 | | - platforms: linux/amd64,linux/arm64 |
73 | | - |
74 | | - - name: Image digest |
75 | | - run: echo ${{ steps.build-push.outputs.digest }} |
76 | | - |
77 | | - - name: Trigger K3s deployment update |
78 | | - if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
79 | | - run: | |
80 | | - echo "Image pushed successfully!" |
81 | | - echo "To update K3s deployment, run:" |
82 | | - echo "kubectl rollout restart deployment/<deployment-name> -n <namespace>" |
0 commit comments