Skip to content

Commit 2ddad44

Browse files
committed
uninstall current emulators
Signed-off-by: CrazyMax <[email protected]>
1 parent 8c37cd6 commit 2ddad44

6 files changed

Lines changed: 45 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,23 @@ jobs:
125125
uses: ./
126126
with:
127127
image: ${{ matrix.image }}
128+
129+
reset:
130+
runs-on: ubuntu-latest
131+
steps:
132+
-
133+
name: Checkout
134+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
135+
-
136+
name: Install multiarch/qemu-user-static
137+
run: |
138+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -c yes
139+
-
140+
name: Set up QEMU
141+
id: qemu
142+
uses: ./
143+
with:
144+
reset: true
145+
-
146+
name: Available platforms
147+
run: echo ${{ steps.qemu.outputs.platforms }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The following inputs can be used as `step.with` keys:
8686
|---------------|--------|-------------------------------------------------------------------------------|----------------------------------------------------|
8787
| `image` | String | [`tonistiigi/binfmt:latest`](https://hub.docker.com/r/tonistiigi/binfmt/tags) | QEMU static binaries Docker image |
8888
| `platforms` | String | `all` | Platforms to install (e.g., `arm64,riscv64,arm`) |
89+
| `reset` | Bool | `false` | Uninstall current emulators before installation |
8990
| `cache-image` | Bool | `true` | Cache binfmt image to GitHub Actions cache backend |
9091

9192
### outputs

__tests__/context.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ describe('getInputs', () => {
1717
[
1818
0,
1919
new Map<string, string>([
20+
['reset', 'false'],
2021
['cache-image', 'true'],
2122
]),
2223
{
2324
image: 'docker.io/tonistiigi/binfmt:latest',
2425
platforms: 'all',
26+
reset: false,
2527
cacheImage: true,
2628
}
2729
],
@@ -30,23 +32,27 @@ describe('getInputs', () => {
3032
new Map<string, string>([
3133
['image', 'docker/binfmt:latest'],
3234
['platforms', 'arm64,riscv64,arm'],
35+
['reset', 'false'],
3336
['cache-image', 'false'],
3437
]),
3538
{
3639
image: 'docker/binfmt:latest',
3740
platforms: 'arm64,riscv64,arm',
41+
reset: false,
3842
cacheImage: false,
3943
}
4044
],
4145
[
4246
2,
4347
new Map<string, string>([
4448
['platforms', 'arm64, riscv64, arm '],
49+
['reset', 'false'],
4550
['cache-image', 'true'],
4651
]),
4752
{
4853
image: 'docker.io/tonistiigi/binfmt:latest',
4954
platforms: 'arm64,riscv64,arm',
55+
reset: false,
5056
cacheImage: true,
5157
}
5258
]

action.yml

Lines changed: 4 additions & 0 deletions
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+
reset:
19+
description: 'Uninstall current emulators before installation'
20+
default: 'false'
21+
required: false
1822
cache-image:
1923
description: 'Cache binfmt image to GitHub Actions cache backend'
2024
default: 'true'

src/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {Util} from '@docker/actions-toolkit/lib/util.js';
44
export interface Inputs {
55
image: string;
66
platforms: string;
7+
reset: boolean;
78
cacheImage: boolean;
89
}
910

1011
export function getInputs(): Inputs {
1112
return {
1213
image: core.getInput('image') || 'docker.io/tonistiigi/binfmt:latest',
1314
platforms: Util.getInputList('platforms').join(',') || 'all',
15+
reset: core.getBooleanInput('reset'),
1416
cacheImage: core.getBooleanInput('cache-image')
1517
};
1618
}

src/main.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ actionsToolkit.run(
4444
});
4545
});
4646

47+
if (input.reset) {
48+
await core.group(`Uninstalling current emulators`, async () => {
49+
await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--uninstall', 'qemu-*'], {
50+
ignoreReturnCode: true
51+
}).then(res => {
52+
if (res.stderr.length > 0 && res.exitCode != 0) {
53+
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
54+
}
55+
});
56+
});
57+
}
58+
4759
await core.group(`Installing QEMU static binaries`, async () => {
4860
await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--install', input.platforms], {
4961
ignoreReturnCode: true

0 commit comments

Comments
 (0)