Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache-binary input to enable/disable caching binary to GHA cache backend #300

Merged
merged 2 commits into from Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
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
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
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
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
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
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