Skip to content

Commit d8b0ca6

Browse files
authored
Merge pull request #552 from crazy-max/readme
Fix git context subdir example and improve README
2 parents 8c76bb7 + da76737 commit d8b0ca6

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

.github/build-push-action.png

-10.6 KB
Loading

README.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,7 @@ ___
3838

3939
## Usage
4040

41-
By default, this action uses the [Git context](#git-context) so you don't need to use the
42-
[`actions/checkout`](https://github.com/actions/checkout/) action to checkout the repository because this will be
43-
done directly by buildkit. The git reference will be based on the [event that triggered your workflow](https://docs.github.com/en/actions/reference/events-that-trigger-workflows)
44-
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>`.
45-
46-
You can provide a subdirectory to the [Git context](#git-context) by using the following [Handlebars template](https://handlebarsjs.com/guide/) expression `{{defaultContext}}`:
47-
48-
```yaml
49-
-
50-
name: Build and push
51-
id: docker_build
52-
uses: docker/build-push-action@v2
53-
with:
54-
context: {{defaultContext}}:docker
55-
push: true
56-
tags: user/app:latest
57-
```
58-
59-
Be careful because **any file mutation in the steps that precede the build step will be ignored, including processing of the `.dockerignore` file** since
60-
the context is based on the git reference. However, you can use the [Path context](#path-context) using the
61-
[`context` input](#inputs) alongside the [`actions/checkout`](https://github.com/actions/checkout/) action to remove
62-
this restriction.
63-
64-
In the examples below we are using 3 other actions:
41+
In the examples below we are also using 3 other actions:
6542

6643
* [`setup-buildx`](https://github.com/docker/setup-buildx-action) action will create and boot a builder using by
6744
default the `docker-container` [builder driver](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#driver).
@@ -72,6 +49,13 @@ to add emulation support with QEMU to be able to build against more platforms.
7249

7350
### Git context
7451

52+
By default, this action uses the [Git context](#git-context) so you don't need
53+
to use the [`actions/checkout`](https://github.com/actions/checkout/) action to
54+
check out the repository because this will be done directly by [BuildKit](https://github.com/moby/buildkit).
55+
56+
The git reference will be based on the [event that triggered your workflow](https://docs.github.com/en/actions/reference/events-that-trigger-workflows)
57+
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>`.
58+
7559
```yaml
7660
name: ci
7761

@@ -98,21 +82,42 @@ jobs:
9882
password: ${{ secrets.DOCKERHUB_TOKEN }}
9983
-
10084
name: Build and push
101-
id: docker_build
10285
uses: docker/build-push-action@v2
10386
with:
10487
push: true
10588
tags: user/app:latest
10689
```
10790
91+
Be careful because **any file mutation in the steps that precede the build step
92+
will be ignored, including processing of the `.dockerignore` file** since
93+
the context is based on the Git reference. However, you can use the
94+
[Path context](#path-context) using the [`context` input](#inputs) alongside
95+
the [`actions/checkout`](https://github.com/actions/checkout/) action to remove
96+
this restriction.
97+
98+
Default Git context can also be provided using the [Handlebars template](https://handlebarsjs.com/guide/)
99+
expression `{{defaultContext}}`. Here we can use it to provide a subdirectory
100+
to the default Git context:
101+
102+
```yaml
103+
-
104+
name: Build and push
105+
uses: docker/build-push-action@v2
106+
with:
107+
context: "{{defaultContext}}:mysubdir"
108+
push: true
109+
tags: user/app:latest
110+
```
111+
> :warning: Subdirectory for Git context is not yet available for the buildx [`docker` driver](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#driver).
112+
108113
Building from the current repository automatically uses the [GitHub Token](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token)
109-
so it does not need to be passed. If you want to authenticate against another private repository, you have to use
110-
a [secret](docs/advanced/secrets.md) named `GIT_AUTH_TOKEN` to be able to authenticate against it with buildx:
114+
so it does not need to be passed. If you want to authenticate against another
115+
private repository, you have to use a [secret](docs/advanced/secrets.md) named
116+
`GIT_AUTH_TOKEN` to be able to authenticate against it with buildx:
111117

112118
```yaml
113119
-
114120
name: Build and push
115-
id: docker_build
116121
uses: docker/build-push-action@v2
117122
with:
118123
push: true
@@ -217,7 +222,7 @@ Following inputs can be used as `step.with` keys
217222
| `tags` | List/CSV | List of tags |
218223
| `target` | String | Sets the target stage to build |
219224
| `ulimit`¹ | List | [Ulimit](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#-set-ulimits---ulimit) options (e.g., `nofile=1024:1024`) |
220-
| `github-token` | String | GitHub Token used to authenticate against a repository for Git context (default `${{ github.token }}`) |
225+
| `github-token` | String | GitHub Token used to authenticate against a repository for [Git context](#git-context) (default `${{ github.token }}`) |
221226

222227
> ¹ `cgroup-parent`, `shm-size` and `ulimit` are only available using `moby/buildkit:master`
223228
> as builder image atm:

docs/advanced/tags-labels.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Handle tags and labels
22

3-
If you come from [`v1`](https://github.com/docker/build-push-action/tree/releases/v1#readme) and want an
4-
"automatic" tag management and [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
3+
If you want an "automatic" tag management and [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
54
for labels, you can do it in a dedicated step. The following workflow will use the [Docker metadata action](https://github.com/docker/metadata-action)
65
to handle tags and labels based on GitHub actions events and Git metadata.
76

@@ -10,7 +9,7 @@ name: ci
109

1110
on:
1211
schedule:
13-
- cron: '0 10 * * *' # everyday at 10am
12+
- cron: '0 10 * * *'
1413
push:
1514
branches:
1615
- '**'

0 commit comments

Comments
 (0)