Skip to content

Commit f26d1f2

Browse files
authored
Merge pull request #193 from crazy-max/git-context-optout
default to git context
2 parents 1677316 + 3ba2682 commit f26d1f2

File tree

6 files changed

+103
-53
lines changed

6 files changed

+103
-53
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
name: Build and push
7070
uses: ./
7171
with:
72+
source: .
7273
builder: ${{ steps.buildx.outputs.name }}
7374
files: |
7475
./test/config.hcl
@@ -87,6 +88,7 @@ jobs:
8788
continue-on-error: true
8889
uses: ./
8990
with:
91+
source: .
9092
files: |
9193
./test/config.hcl
9294
set: |
@@ -108,6 +110,7 @@ jobs:
108110
continue-on-error: true
109111
uses: ./
110112
with:
113+
source: .
111114
files: |
112115
./test/config.hcl
113116
-
@@ -144,10 +147,11 @@ jobs:
144147
name: Build
145148
uses: ./
146149
with:
150+
source: .
147151
files: |
148152
./test/config.hcl
149153
150-
source:
154+
remote:
151155
runs-on: ubuntu-latest
152156
steps:
153157
-
@@ -188,6 +192,7 @@ jobs:
188192
uses: ./
189193
with:
190194
workdir: ./test/go
195+
source: .
191196
targets: binary
192197
provenance: ${{ matrix.attrs }}
193198
set: |
@@ -229,6 +234,7 @@ jobs:
229234
uses: ./
230235
with:
231236
workdir: ./test/go
237+
source: .
232238
targets: ${{ matrix.target }}
233239
sbom: true
234240
set: |
@@ -275,6 +281,7 @@ jobs:
275281
uses: ./
276282
with:
277283
workdir: ./test/go
284+
source: .
278285
set: |
279286
*.platform=linux/amd64
280287
*.output=type=image,"name=localhost:5000/name/app:v1.0.0,localhost:5000/name/app:latest",push=true
@@ -304,6 +311,7 @@ jobs:
304311
uses: ./
305312
with:
306313
workdir: ./test/group
314+
source: .
307315
push: true
308316
set: |
309317
t1.tags=localhost:5000/name/app:t1
@@ -324,6 +332,7 @@ jobs:
324332
name: Build
325333
uses: ./
326334
with:
335+
source: .
327336
files: |
328337
./test/config.hcl
329338
@@ -361,6 +370,7 @@ jobs:
361370
name: Build
362371
uses: ./
363372
with:
373+
source: .
364374
files: |
365375
./test/config.hcl
366376
targets: app-proxy
@@ -396,6 +406,7 @@ jobs:
396406
name: Build
397407
uses: ./
398408
with:
409+
source: .
399410
files: |
400411
./test/config.hcl
401412
@@ -415,8 +426,6 @@ jobs:
415426
-
416427
name: Build
417428
uses: ./
418-
with:
419-
source: "{{defaultContext}}"
420429

421430
git-context-and-local:
422431
runs-on: ubuntu-latest
@@ -439,7 +448,6 @@ jobs:
439448
name: Build
440449
uses: ./
441450
with:
442-
source: "{{defaultContext}}"
443451
files: |
444452
cwd://${{ steps.meta.outputs.bake-file }}
445453
@@ -466,6 +474,7 @@ jobs:
466474
uses: ./
467475
with:
468476
workdir: ./test/go
477+
source: .
469478
set: |
470479
*.output=type=image,name=localhost:5000/name/app:latest,push=true
471480
*.output=type=docker,name=app:local
@@ -509,6 +518,7 @@ jobs:
509518
uses: ./
510519
with:
511520
workdir: ./test/go
521+
source: .
512522
targets: image
513523
load: true
514524
push: true
@@ -563,6 +573,7 @@ jobs:
563573
name: Build
564574
uses: ./
565575
with:
576+
source: .
566577
files: |
567578
./test/config.hcl
568579
targets: app
@@ -666,6 +677,7 @@ jobs:
666677
uses: ./
667678
with:
668679
workdir: ./test
680+
source: .
669681
files: |
670682
./lint.hcl
671683
@@ -687,6 +699,7 @@ jobs:
687699
uses: ./
688700
with:
689701
workdir: ./test
702+
source: .
690703
files: |
691704
./lint.hcl
692705
env:

README.md

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ as a high-level build command.
1414
___
1515

1616
* [Usage](#usage)
17-
* [Path context](#path-context)
1817
* [Git context](#git-context)
18+
* [Path context](#path-context)
1919
* [Summaries](#summaries)
2020
* [Customizing](#customizing)
2121
* [inputs](#inputs)
@@ -27,57 +27,22 @@ ___
2727

2828
## Usage
2929

30-
### Path context
31-
32-
By default, this action will use the local bake definition (`source: .`), so
33-
you need to use the [`actions/checkout`](https://github.com/actions/checkout/)
34-
action to check out the repository.
35-
36-
```yaml
37-
name: ci
38-
39-
on:
40-
push:
41-
branches:
42-
- 'master'
43-
44-
jobs:
45-
bake:
46-
runs-on: ubuntu-latest
47-
steps:
48-
-
49-
name: Checkout
50-
uses: actions/checkout@v4
51-
-
52-
name: Login to DockerHub
53-
uses: docker/login-action@v3
54-
with:
55-
username: ${{ vars.DOCKERHUB_USERNAME }}
56-
password: ${{ secrets.DOCKERHUB_TOKEN }}
57-
-
58-
name: Set up Docker Buildx
59-
uses: docker/setup-buildx-action@v3
60-
-
61-
name: Build and push
62-
uses: docker/bake-action@v5
63-
with:
64-
push: true
65-
```
66-
6730
### Git context
6831

69-
Git context can be provided using the [`source` input](#inputs). This means
70-
that you don't need to use the [`actions/checkout`](https://github.com/actions/checkout/)
32+
Since `v6` this action uses the [Git context](https://docs.docker.com/build/bake/remote-definition/)
33+
to build from a remote bake definition by default like the [build-push-action](https://github.com/docker/build-push-action)
34+
does. This means that you don't need to use the [`actions/checkout`](https://github.com/actions/checkout/)
7135
action to check out the repository as [BuildKit](https://docs.docker.com/build/buildkit/)
7236
will do this directly.
7337

38+
The git reference will be based on the [event that triggered your workflow](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows)
39+
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>`.
40+
7441
```yaml
7542
name: ci
7643

7744
on:
7845
push:
79-
branches:
80-
- 'master'
8146

8247
jobs:
8348
bake:
@@ -96,15 +61,17 @@ jobs:
9661
name: Build and push
9762
uses: docker/bake-action@v5
9863
with:
99-
source: "${{ github.server_url }}/${{ github.repository }}.git#${{ github.ref }}"
10064
push: true
65+
set: |
66+
*.tags=user/app:latest
10167
```
10268
10369
Be careful because **any file mutation in the steps that precede the build step
10470
will be ignored, including processing of the `.dockerignore` file** since
10571
the context is based on the Git reference. However, you can use the
106-
[Path context](#path-context) alongside the [`actions/checkout`](https://github.com/actions/checkout/)
107-
action to remove this restriction.
72+
[Path context](#path-context) using the [`source` input](#inputs) alongside
73+
the [`actions/checkout`](https://github.com/actions/checkout/) action to remove
74+
this restriction.
10875

10976
Default Git context can also be provided using the [Handlebars template](https://handlebarsjs.com/guide/)
11077
expression `{{defaultContext}}`. Here we can use it to provide a subdirectory
@@ -117,6 +84,8 @@ to the default Git context:
11784
with:
11885
source: "{{defaultContext}}:mysubdir"
11986
push: true
87+
set: |
88+
*.tags=user/app:latest
12089
```
12190

12291
Building from the current repository automatically uses the `GITHUB_TOKEN`
@@ -133,12 +102,47 @@ another private repository for remote definitions, you can set the
133102
name: Build and push
134103
uses: docker/bake-action@v5
135104
with:
136-
source: "${{ github.server_url }}/${{ github.repository }}.git#${{ github.ref }}"
137105
push: true
106+
set: |
107+
*.tags=user/app:latest
138108
env:
139109
BUILDX_BAKE_GIT_AUTH_TOKEN: ${{ secrets.MYTOKEN }}
140110
```
141111

112+
### Path context
113+
114+
```yaml
115+
name: ci
116+
117+
on:
118+
push:
119+
120+
jobs:
121+
bake:
122+
runs-on: ubuntu-latest
123+
steps:
124+
-
125+
name: Checkout
126+
uses: actions/checkout@v4
127+
-
128+
name: Login to DockerHub
129+
uses: docker/login-action@v3
130+
with:
131+
username: ${{ vars.DOCKERHUB_USERNAME }}
132+
password: ${{ secrets.DOCKERHUB_TOKEN }}
133+
-
134+
name: Set up Docker Buildx
135+
uses: docker/setup-buildx-action@v3
136+
-
137+
name: Build and push
138+
uses: docker/bake-action@v5
139+
with:
140+
source: .
141+
push: true
142+
set: |
143+
*.tags=user/app:latest
144+
```
145+
142146
## Summaries
143147

144148
This action generates a [job summary](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/)

0 commit comments

Comments
 (0)