Skip to content

Commit

Permalink
Merge pull request #531 from BeyondEvil/subdir-with-default-context
Browse files Browse the repository at this point in the history
Add subdirectory for Git context
  • Loading branch information
crazy-max committed Jan 12, 2022
2 parents b1aeb11 + fc5a732 commit 1814d3d
Show file tree
Hide file tree
Showing 6 changed files with 13,131 additions and 4,697 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -43,6 +43,19 @@ By default, this action uses the [Git context](#git-context) so you don't need t
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)
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>`.

You can provide a subdirectory to the [Git context](#git-context) by using the following [Handlebars template](https://handlebarsjs.com/guide/) expression `{{defaultContext}}`:

```yaml
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: {{defaultContext}}:docker
push: true
tags: user/app:latest
```

Be careful because **any file mutation in the steps that precede the build step will be ignored, including processing of the `.dockerignore` file** since
the context is based on the git reference. However, you can use the [Path context](#path-context) using the
[`context` input](#inputs) alongside the [`actions/checkout`](https://github.com/actions/checkout/) action to remove
Expand Down
18 changes: 18 additions & 0 deletions __tests__/context.test.ts
Expand Up @@ -491,6 +491,24 @@ nproc=3`],
'.'
]
],
[
15,
'0.7.0',
new Map<string, string>([
['context', '{{defaultContext}}:docker'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'buildx',
'build',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
'https://github.com/docker/build-push-action.git#refs/heads/test-jest:docker'
]
],
])(
'[%d] given %p with %p as inputs, returns %p',
async (num: number, buildxVersion: string, inputs: Map<string, any>, expected: Array<string>) => {
Expand Down

0 comments on commit 1814d3d

Please sign in to comment.