Skip to content

Commit fdbeaac

Browse files
authored
Merge pull request #130 from crazy-max/cache-image
cache-image input to enable/disable caching of binfmt image
2 parents 8b562ef + c3bed4e commit fdbeaac

File tree

8 files changed

+47
-15
lines changed

8 files changed

+47
-15
lines changed

.github/workflows/ci.yml

+23
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,26 @@ jobs:
7979
echo "::error::Should have failed"
8080
exit 1
8181
fi
82+
83+
cache-image:
84+
runs-on: ubuntu-latest
85+
strategy:
86+
fail-fast: false
87+
matrix:
88+
cache:
89+
- true
90+
- false
91+
steps:
92+
-
93+
name: Checkout
94+
uses: actions/checkout@v4
95+
-
96+
name: Set up QEMU
97+
id: qemu
98+
uses: ./
99+
with:
100+
image: tonistiigi/binfmt:master
101+
cache-image: ${{ matrix.cache }}
102+
-
103+
name: Available platforms
104+
run: echo ${{ steps.qemu.outputs.platforms }}

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ jobs:
4141
4242
The following inputs can be used as `step.with` keys:
4343

44-
| Name | Type | Default | Description |
45-
|-------------|--------|-------------------------------------------------------------------------------|--------------------------------------------------|
46-
| `image` | String | [`tonistiigi/binfmt:latest`](https://hub.docker.com/r/tonistiigi/binfmt/tags) | QEMU static binaries Docker image |
47-
| `platforms` | String | `all` | Platforms to install (e.g., `arm64,riscv64,arm`) |
44+
| Name | Type | Default | Description |
45+
|---------------|--------|-------------------------------------------------------------------------------|----------------------------------------------------|
46+
| `image` | String | [`tonistiigi/binfmt:latest`](https://hub.docker.com/r/tonistiigi/binfmt/tags) | QEMU static binaries Docker image |
47+
| `platforms` | String | `all` | Platforms to install (e.g., `arm64,riscv64,arm`) |
48+
| `cache-image` | Bool | `true` | Cache binfmt image to GitHub Actions cache backend |
4849

4950
### outputs
5051

__tests__/context.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,38 @@ describe('getInputs', () => {
1616
test.each([
1717
[
1818
0,
19-
new Map<string, string>([]),
19+
new Map<string, string>([
20+
['cache-image', 'true'],
21+
]),
2022
{
2123
image: 'docker.io/tonistiigi/binfmt:latest',
2224
platforms: 'all',
25+
cacheImage: true,
2326
} as context.Inputs
2427
],
2528
[
2629
1,
2730
new Map<string, string>([
2831
['image', 'docker/binfmt:latest'],
2932
['platforms', 'arm64,riscv64,arm'],
33+
['cache-image', 'false'],
3034
]),
3135
{
3236
image: 'docker/binfmt:latest',
3337
platforms: 'arm64,riscv64,arm',
38+
cacheImage: false,
3439
} as context.Inputs
3540
],
3641
[
3742
2,
3843
new Map<string, string>([
3944
['platforms', 'arm64, riscv64, arm '],
45+
['cache-image', 'true'],
4046
]),
4147
{
4248
image: 'docker.io/tonistiigi/binfmt:latest',
4349
platforms: 'arm64,riscv64,arm',
50+
cacheImage: true,
4451
} as context.Inputs
4552
]
4653
])(

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
description: 'Platforms to install (e.g. arm64,riscv64,arm)'
1616
default: 'all'
1717
required: false
18+
cache-image:
19+
description: 'Cache binfmt image to GitHub Actions cache backend'
20+
default: 'true'
21+
required: false
1822

1923
outputs:
2024
platforms:
@@ -23,3 +27,4 @@ outputs:
2327
runs:
2428
using: 'node20'
2529
main: 'dist/index.js'
30+
post: 'dist/index.js'

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import {Util} from '@docker/actions-toolkit/lib/util';
44
export interface Inputs {
55
image: string;
66
platforms: string;
7+
cacheImage: boolean;
78
}
89

910
export function getInputs(): Inputs {
1011
return {
1112
image: core.getInput('image') || 'docker.io/tonistiigi/binfmt:latest',
12-
platforms: Util.getInputList('platforms').join(',') || 'all'
13+
platforms: Util.getInputList('platforms').join(',') || 'all',
14+
cacheImage: core.getBooleanInput('cache-image')
1315
};
1416
}

src/main.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ actionsToolkit.run(
2020
});
2121

2222
await core.group(`Pulling binfmt Docker image`, async () => {
23-
await Docker.getExecOutput(['pull', input.image], {
24-
ignoreReturnCode: true
25-
}).then(res => {
26-
if (res.stderr.length > 0 && res.exitCode != 0) {
27-
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
28-
}
29-
});
23+
await Docker.pull(input.image, input.cacheImage);
3024
});
3125

3226
await core.group(`Image info`, async () => {

0 commit comments

Comments
 (0)