Skip to content

Commit

Permalink
default to git context
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Sep 12, 2024
1 parent 76cc806 commit 309761a
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 51 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
name: Build and push
uses: ./
with:
source: .
builder: ${{ steps.buildx.outputs.name }}
files: |
./test/config.hcl
Expand All @@ -87,6 +88,7 @@ jobs:
continue-on-error: true
uses: ./
with:
source: .
files: |
./test/config.hcl
set: |
Expand All @@ -108,6 +110,7 @@ jobs:
continue-on-error: true
uses: ./
with:
source: .
files: |
./test/config.hcl
-
Expand Down Expand Up @@ -144,10 +147,11 @@ jobs:
name: Build
uses: ./
with:
source: .
files: |
./test/config.hcl
source:
remote:
runs-on: ubuntu-latest
steps:
-
Expand Down Expand Up @@ -188,6 +192,7 @@ jobs:
uses: ./
with:
workdir: ./test/go
source: .
targets: binary
provenance: ${{ matrix.attrs }}
set: |
Expand Down Expand Up @@ -229,6 +234,7 @@ jobs:
uses: ./
with:
workdir: ./test/go
source: .
targets: ${{ matrix.target }}
sbom: true
set: |
Expand Down Expand Up @@ -275,6 +281,7 @@ jobs:
uses: ./
with:
workdir: ./test/go
source: .
set: |
*.platform=linux/amd64
*.output=type=image,"name=localhost:5000/name/app:v1.0.0,localhost:5000/name/app:latest",push=true
Expand Down Expand Up @@ -304,6 +311,7 @@ jobs:
uses: ./
with:
workdir: ./test/group
source: .
push: true
set: |
t1.tags=localhost:5000/name/app:t1
Expand All @@ -324,6 +332,7 @@ jobs:
name: Build
uses: ./
with:
source: .
files: |
./test/config.hcl
Expand Down Expand Up @@ -361,6 +370,7 @@ jobs:
name: Build
uses: ./
with:
source: .
files: |
./test/config.hcl
targets: app-proxy
Expand Down Expand Up @@ -396,6 +406,7 @@ jobs:
name: Build
uses: ./
with:
source: .
files: |
./test/config.hcl
Expand All @@ -415,8 +426,6 @@ jobs:
-
name: Build
uses: ./
with:
source: "{{defaultContext}}"

git-context-and-local:
runs-on: ubuntu-latest
Expand All @@ -439,7 +448,6 @@ jobs:
name: Build
uses: ./
with:
source: "{{defaultContext}}"
files: |
cwd://${{ steps.meta.outputs.bake-file }}
Expand All @@ -466,6 +474,7 @@ jobs:
uses: ./
with:
workdir: ./test/go
source: .
set: |
*.output=type=image,name=localhost:5000/name/app:latest,push=true
*.output=type=docker,name=app:local
Expand Down Expand Up @@ -509,6 +518,7 @@ jobs:
uses: ./
with:
workdir: ./test/go
source: .
targets: image
load: true
push: true
Expand Down Expand Up @@ -563,6 +573,7 @@ jobs:
name: Build
uses: ./
with:
source: .
files: |
./test/config.hcl
targets: app
Expand Down Expand Up @@ -666,6 +677,7 @@ jobs:
uses: ./
with:
workdir: ./test
source: .
files: |
./lint.hcl
Expand All @@ -687,6 +699,7 @@ jobs:
uses: ./
with:
workdir: ./test
source: .
files: |
./lint.hcl
env:
Expand Down
96 changes: 50 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ as a high-level build command.
___

* [Usage](#usage)
* [Path context](#path-context)
* [Git context](#git-context)
* [Path context](#path-context)
* [Summaries](#summaries)
* [Customizing](#customizing)
* [inputs](#inputs)
Expand All @@ -27,57 +27,22 @@ ___

## Usage

### Path context

By default, this action will use the local bake definition (`source: .`), so
you need to use the [`actions/checkout`](https://github.com/actions/checkout/)
action to check out the repository.

```yaml
name: ci

on:
push:
branches:
- 'master'

jobs:
bake:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/bake-action@v5
with:
push: true
```
### Git context

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

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)
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>`.

```yaml
name: ci

on:
push:
branches:
- 'master'

jobs:
bake:
Expand All @@ -96,15 +61,17 @@ jobs:
name: Build and push
uses: docker/bake-action@v5
with:
source: "${{ github.server_url }}/${{ github.repository }}.git#${{ github.ref }}"
push: true
set: |
*.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) alongside the [`actions/checkout`](https://github.com/actions/checkout/)
action to remove this restriction.
[Path context](#path-context) using the [`source` input](#inputs) alongside
the [`actions/checkout`](https://github.com/actions/checkout/) action to remove
this restriction.

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

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

### Path context

```yaml
name: ci
on:
push:
jobs:
bake:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/bake-action@v5
with:
source: .
push: true
set: |
*.tags=user/app:latest
```

## Summaries

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

0 comments on commit 309761a

Please sign in to comment.