Skip to content

Commit 0d103c3

Browse files
authored
Merge pull request #300 from crazy-max/cache-binary
cache-binary input to enable/disable caching binary to GHA cache backend
2 parents 5243153 + f19477a commit 0d103c3

File tree

8 files changed

+39
-4
lines changed

8 files changed

+39
-4
lines changed

.github/workflows/ci.yml

+19
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,22 @@ jobs:
563563
uses: docker/build-push-action@master
564564
with:
565565
context: .
566+
567+
cacheBinary:
568+
runs-on: ubuntu-latest
569+
strategy:
570+
fail-fast: false
571+
matrix:
572+
cache:
573+
- true
574+
- false
575+
steps:
576+
-
577+
name: Checkout
578+
uses: actions/checkout@v4
579+
-
580+
name: Set up Docker Buildx
581+
uses: ./
582+
with:
583+
version: v0.11.2
584+
cache-binary: ${{ matrix.cache }}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ The following inputs can be used as `step.with` keys:
9898
| `config`¹ | String | | [BuildKit config file](https://docs.docker.com/engine/reference/commandline/buildx_create/#config) |
9999
| `config-inline`¹ | String | | Same as `config` but inline |
100100
| `append` | YAML | | [Append additional nodes](docs/advanced/append-nodes.md) to the builder |
101+
| `cache-binary` | Bool | `true` | Cache buildx binary to GitHub Actions cache backend |
101102
| `cleanup` | Bool | `true` | Cleanup temp files and remove builder at the end of a job |
102103

103104
> * ¹ `config` and `config-inline` are mutually exclusive

__tests__/context.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('getCreateArgs', () => {
3232
new Map<string, string>([
3333
['install', 'false'],
3434
['use', 'true'],
35+
['cache-binary', 'true'],
3536
['cleanup', 'true'],
3637
]),
3738
[
@@ -49,6 +50,7 @@ describe('getCreateArgs', () => {
4950
['driver', 'docker'],
5051
['install', 'false'],
5152
['use', 'true'],
53+
['cache-binary', 'true'],
5254
['cleanup', 'true'],
5355
]),
5456
[
@@ -66,6 +68,7 @@ describe('getCreateArgs', () => {
6668
['install', 'false'],
6769
['use', 'false'],
6870
['driver-opts', 'image=moby/buildkit:master\nnetwork=host'],
71+
['cache-binary', 'true'],
6972
['cleanup', 'true'],
7073
]),
7174
[
@@ -85,6 +88,7 @@ describe('getCreateArgs', () => {
8588
['endpoint', 'tls://foo:1234'],
8689
['install', 'false'],
8790
['use', 'true'],
91+
['cache-binary', 'true'],
8892
['cleanup', 'true'],
8993
]),
9094
[
@@ -104,6 +108,7 @@ describe('getCreateArgs', () => {
104108
['endpoint', 'tls://foo:1234'],
105109
['install', 'false'],
106110
['use', 'true'],
111+
['cache-binary', 'true'],
107112
['cleanup', 'true'],
108113
]),
109114
[
@@ -122,6 +127,7 @@ describe('getCreateArgs', () => {
122127
['install', 'false'],
123128
['use', 'false'],
124129
['driver-opts', `"env.no_proxy=localhost,127.0.0.1,.mydomain"`],
130+
['cache-binary', 'true'],
125131
['cleanup', 'true'],
126132
]),
127133
[
@@ -139,6 +145,7 @@ describe('getCreateArgs', () => {
139145
['install', 'false'],
140146
['use', 'false'],
141147
['platforms', 'linux/amd64\n"linux/arm64,linux/arm/v7"'],
148+
['cache-binary', 'true'],
142149
['cleanup', 'true'],
143150
]),
144151
[
@@ -156,6 +163,7 @@ describe('getCreateArgs', () => {
156163
['install', 'false'],
157164
['use', 'false'],
158165
['driver', 'unknown'],
166+
['cache-binary', 'true'],
159167
['cleanup', 'true'],
160168
]),
161169
[
@@ -199,6 +207,7 @@ describe('getAppendArgs', () => {
199207
new Map<string, string>([
200208
['install', 'false'],
201209
['use', 'true'],
210+
['cache-binary', 'true'],
202211
['cleanup', 'true'],
203212
]),
204213
{

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ inputs:
4444
append:
4545
description: 'Append additional nodes to the builder'
4646
required: false
47+
cache-binary:
48+
description: 'Cache buildx binary to GitHub Actions cache backend'
49+
default: 'true'
50+
required: false
4751
cleanup:
4852
description: 'Cleanup temp files and remove builder at the end of a job'
4953
default: 'true'

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Inputs {
2020
config: string;
2121
configInline: string;
2222
append: string;
23+
cacheBinary: boolean;
2324
cleanup: boolean;
2425
}
2526

@@ -37,6 +38,7 @@ export async function getInputs(): Promise<Inputs> {
3738
config: core.getInput('config'),
3839
configInline: core.getInput('config-inline'),
3940
append: core.getInput('append'),
41+
cacheBinary: core.getBooleanInput('cache-binary'),
4042
cleanup: core.getBooleanInput('cleanup')
4143
};
4244
}

src/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ actionsToolkit.run(
3838
throw new Error(`Cannot build from source without the Docker CLI`);
3939
}
4040
await core.group(`Build buildx from source`, async () => {
41-
toolPath = await toolkit.buildxInstall.build(inputs.version);
41+
toolPath = await toolkit.buildxInstall.build(inputs.version, !inputs.cacheBinary);
4242
});
4343
} else if (!(await toolkit.buildx.isAvailable()) || inputs.version) {
4444
await core.group(`Download buildx from GitHub Releases`, async () => {
45-
toolPath = await toolkit.buildxInstall.download(inputs.version || 'latest');
45+
toolPath = await toolkit.buildxInstall.download(inputs.version || 'latest', !inputs.cacheBinary);
4646
});
4747
}
4848
if (toolPath) {

0 commit comments

Comments
 (0)