Skip to content

Commit 1814d3d

Browse files
authored
Merge pull request #531 from BeyondEvil/subdir-with-default-context
Add subdirectory for Git context
2 parents b1aeb11 + fc5a732 commit 1814d3d

File tree

6 files changed

+13131
-4697
lines changed

6 files changed

+13131
-4697
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ By default, this action uses the [Git context](#git-context) so you don't need t
4343
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)
4444
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>`.
4545

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+
4659
Be careful because **any file mutation in the steps that precede the build step will be ignored, including processing of the `.dockerignore` file** since
4760
the context is based on the git reference. However, you can use the [Path context](#path-context) using the
4861
[`context` input](#inputs) alongside the [`actions/checkout`](https://github.com/actions/checkout/) action to remove

__tests__/context.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,24 @@ nproc=3`],
491491
'.'
492492
]
493493
],
494+
[
495+
15,
496+
'0.7.0',
497+
new Map<string, string>([
498+
['context', '{{defaultContext}}:docker'],
499+
['load', 'false'],
500+
['no-cache', 'false'],
501+
['push', 'false'],
502+
['pull', 'false'],
503+
]),
504+
[
505+
'buildx',
506+
'build',
507+
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
508+
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
509+
'https://github.com/docker/build-push-action.git#refs/heads/test-jest:docker'
510+
]
511+
],
494512
])(
495513
'[%d] given %p with %p as inputs, returns %p',
496514
async (num: number, buildxVersion: string, inputs: Map<string, any>, expected: Array<string>) => {

0 commit comments

Comments
 (0)