10
10
paths :
11
11
- ' Dockerfile*'
12
12
- ' pyproject.toml'
13
- - ' poetry .lock'
13
+ - ' * .lock'
14
14
- ' requirements.txt'
15
15
- ' **.py'
16
16
- ' **.sh'
17
17
- ' .dockerignore'
18
18
- ' .env.example'
19
19
- ' .github/workflows/**'
20
20
workflow_dispatch :
21
- # workflow_run:
22
- # workflows: ["Run pytest"]
23
- # types:
24
- # - completed
25
21
26
22
env :
27
- REGISTRY_URL : ${{ vars.REGISTRY_URL }}
28
- REGISTRY_USER : ${{ vars.REGISTRY_USER }}
23
+ REGISTRY_URL : ${{ vars.REGISTRY_URL || 'ghcr.io' }}
24
+ REGISTRY_USER : ${{ vars.REGISTRY_USER || github.repository_owner }}
25
+ REGISTRY_PASS : ${{ (vars.REGISTRY_URL == 'ghcr.io' || !vars.REGISTRY_URL) && secrets.GITHUB_TOKEN || secrets.REGISTRY_PASS }}
26
+ IMAGE_NAME : ${{ vars.IMAGE || github.event.repository.name }}
29
27
30
28
jobs :
31
29
push_to_registry :
36
34
matrix :
37
35
dockerfile : [Dockerfile]
38
36
concurrency :
39
- # group: ${{ github.workflow }}-${{ matrix.dockerfile }}-${{ github.event.workflow_run.head_branch || github.ref }}
40
37
group : ${{ github.workflow }}-${{ matrix.dockerfile }}-${{ github.head_ref || github.ref }}
41
38
cancel-in-progress : true
42
39
permissions :
48
45
- name : Checkout code
49
46
uses : actions/checkout@v4
50
47
51
- - name : Set password by container registry
52
- run : |
53
- case "${{ env.REGISTRY_URL }}" in
54
- "ghcr.io")
55
- echo "REGISTRY_PASS=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
56
- ;;
57
- *)
58
- if [ -n "${{ secrets.REGISTRY_PASS }}" ]; then
59
- echo "REGISTRY_PASS=${{ secrets.REGISTRY_PASS }}" >> $GITHUB_ENV
60
- else
61
- echo "REGISTRY_PASS secret is not set and registry is not recognized. Exiting..."
62
- exit 1
63
- fi
64
- ;;
65
- esac
66
-
67
48
- name : Log into container registry
68
49
if : github.event_name != 'pull_request'
69
50
uses : docker/login-action@v3
@@ -72,23 +53,12 @@ jobs:
72
53
username : ${{ env.REGISTRY_USER }}
73
54
password : ${{ env.REGISTRY_PASS }}
74
55
75
- - name : Set image name
76
- id : image_name
77
- run : |
78
- if [ -n "${{ env.IMAGE }}" ]; then
79
- IMAGE="${{ env.IMAGE }}"
80
- else
81
- IMAGE=$(grep "LABEL org.opencontainers.image.title" Dockerfile | cut -d'"' -f2)
82
- fi
83
- echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
84
- echo "IMAGE=$IMAGE" >> $GITHUB_ENV
85
-
86
56
- name : Docker meta
87
57
id : meta
88
58
uses : docker/metadata-action@v5
89
59
with :
90
60
images : |
91
- ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}
61
+ ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ env.IMAGE_NAME }}
92
62
tags : |
93
63
type=schedule
94
64
type=ref,event=branch
98
68
type=semver,pattern={{major}}
99
69
type=sha
100
70
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch || 'main') }}
71
+ bake-target : docker-metadata-action
101
72
102
73
- name : Setup QEMU
103
74
uses : docker/setup-qemu-action@v3
@@ -106,12 +77,15 @@ jobs:
106
77
uses : docker/setup-buildx-action@v3
107
78
108
79
- name : Build and push
109
- uses : docker/build-push -action@v6
80
+ uses : docker/bake -action@v6
110
81
with :
111
- context : .
112
- file : ./${{ matrix.dockerfile }}
82
+ source : " {{defaultContext}}"
83
+ files : |
84
+ ./docker-bake.hcl
85
+ cwd://${{ steps.meta.outputs.bake-file }}
86
+ targets : build
113
87
push : ${{ github.event_name != 'pull_request' }}
114
- tags : ${{ steps.meta.outputs.tags }}
115
- labels : ${{ steps.meta.outputs.labels }}
116
- cache-from : type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache
117
- cache-to : type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache ,mode=max
88
+ set : |
89
+ *.tags= ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ env.IMAGE_NAME }}:latest
90
+ *. cache-from= type=gha
91
+ *. cache-to= type=gha ,mode=max
0 commit comments