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

Uninstall all archs for a specific emulator #22

Merged
merged 1 commit into from
Apr 23, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64

Emulator names can be found from the status output.

You can also uninstall all archs for a specific emulator:

```bash
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-*
```

## Development commands

```bash
Expand Down
27 changes: 23 additions & 4 deletions cmd/binfmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,35 @@ func parseArch(in string) (out []string) {
return
}

func parseUninstall(in string) (out []string) {
if in == "" {
return
}
for _, v := range strings.Split(in, ",") {
if p, err := platforms.Parse(v); err == nil {
if c, ok := configs[p.Architecture]; ok {
v = strings.TrimPrefix(c.binary, "qemu-")
}
}
fis, err := filepath.Glob(filepath.Join(mount, v))
if err != nil || len(fis) == 0 {
out = append(out, v)
}
for _, fi := range fis {
out = append(out, filepath.Base(fi))
}
}
return
}

func main() {
flag.Parse()

if err := run(); err != nil {
log.Printf("error: %+v", err)
}
}

func run() error {
if _, err := os.Stat(filepath.Join(mount, "status")); err != nil {
if err := syscall.Mount("binfmt_misc", mount, "binfmt_misc", 0, ""); err != nil {
Expand All @@ -148,10 +170,7 @@ func run() error {
defer syscall.Unmount(mount, 0)
}

for _, name := range parseArch(toUninstall) {
if name == "arm64" {
name = "aarch64"
}
for _, name := range parseUninstall(toUninstall) {
crazy-max marked this conversation as resolved.
Show resolved Hide resolved
err := uninstall(name)
if err == nil {
log.Printf("uninstalling: %s OK", name)
Expand Down
1 change: 1 addition & 0 deletions hack/install-and-test
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fi
NAME_SUFFIX=${NAME_SUFFIX:-test} buildxCmd bake $setFlags --load mainline

set -o pipefail -x
docker run --rm --privileged tonistiigi/binfmt:${NAME_SUFFIX:-test} --uninstall qemu-*
status=$(docker run --rm --privileged tonistiigi/binfmt:${NAME_SUFFIX:-test} --install all)

echo $status | jq .supported | grep linux/arm64
Expand Down