Skip to content

Commit

Permalink
Merge pull request #300 from crazy-max/cache-binary
Browse files Browse the repository at this point in the history
cache-binary input to enable/disable caching binary to GHA cache backend
  • Loading branch information
crazy-max committed Feb 23, 2024
2 parents 5243153 + f19477a commit 0d103c3
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,22 @@ jobs:
uses: docker/build-push-action@master
with:
context: .

cacheBinary:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cache:
- true
- false
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: ./
with:
version: v0.11.2
cache-binary: ${{ matrix.cache }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The following inputs can be used as `step.with` keys:
| `config`¹ | String | | [BuildKit config file](https://docs.docker.com/engine/reference/commandline/buildx_create/#config) |
| `config-inline`¹ | String | | Same as `config` but inline |
| `append` | YAML | | [Append additional nodes](docs/advanced/append-nodes.md) to the builder |
| `cache-binary` | Bool | `true` | Cache buildx binary to GitHub Actions cache backend |
| `cleanup` | Bool | `true` | Cleanup temp files and remove builder at the end of a job |
> * ¹ `config` and `config-inline` are mutually exclusive
Expand Down
9 changes: 9 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('getCreateArgs', () => {
new Map<string, string>([
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand All @@ -49,6 +50,7 @@ describe('getCreateArgs', () => {
['driver', 'docker'],
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand All @@ -66,6 +68,7 @@ describe('getCreateArgs', () => {
['install', 'false'],
['use', 'false'],
['driver-opts', 'image=moby/buildkit:master\nnetwork=host'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand All @@ -85,6 +88,7 @@ describe('getCreateArgs', () => {
['endpoint', 'tls://foo:1234'],
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand All @@ -104,6 +108,7 @@ describe('getCreateArgs', () => {
['endpoint', 'tls://foo:1234'],
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand All @@ -122,6 +127,7 @@ describe('getCreateArgs', () => {
['install', 'false'],
['use', 'false'],
['driver-opts', `"env.no_proxy=localhost,127.0.0.1,.mydomain"`],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand All @@ -139,6 +145,7 @@ describe('getCreateArgs', () => {
['install', 'false'],
['use', 'false'],
['platforms', 'linux/amd64\n"linux/arm64,linux/arm/v7"'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand All @@ -156,6 +163,7 @@ describe('getCreateArgs', () => {
['install', 'false'],
['use', 'false'],
['driver', 'unknown'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
[
Expand Down Expand Up @@ -199,6 +207,7 @@ describe('getAppendArgs', () => {
new Map<string, string>([
['install', 'false'],
['use', 'true'],
['cache-binary', 'true'],
['cleanup', 'true'],
]),
{
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ inputs:
append:
description: 'Append additional nodes to the builder'
required: false
cache-binary:
description: 'Cache buildx binary to GitHub Actions cache backend'
default: 'true'
required: false
cleanup:
description: 'Cleanup temp files and remove builder at the end of a job'
default: 'true'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Inputs {
config: string;
configInline: string;
append: string;
cacheBinary: boolean;
cleanup: boolean;
}

Expand All @@ -37,6 +38,7 @@ export async function getInputs(): Promise<Inputs> {
config: core.getInput('config'),
configInline: core.getInput('config-inline'),
append: core.getInput('append'),
cacheBinary: core.getBooleanInput('cache-binary'),
cleanup: core.getBooleanInput('cleanup')
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ actionsToolkit.run(
throw new Error(`Cannot build from source without the Docker CLI`);
}
await core.group(`Build buildx from source`, async () => {
toolPath = await toolkit.buildxInstall.build(inputs.version);
toolPath = await toolkit.buildxInstall.build(inputs.version, !inputs.cacheBinary);
});
} else if (!(await toolkit.buildx.isAvailable()) || inputs.version) {
await core.group(`Download buildx from GitHub Releases`, async () => {
toolPath = await toolkit.buildxInstall.download(inputs.version || 'latest');
toolPath = await toolkit.buildxInstall.download(inputs.version || 'latest', !inputs.cacheBinary);
});
}
if (toolPath) {
Expand Down

0 comments on commit 0d103c3

Please sign in to comment.