Skip to content

Commit

Permalink
feat: Start pulling and tagging multi-arch images explicitly (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pojntfx committed Aug 25, 2021
1 parent dc75a49 commit 316107b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,30 @@ Usage: %s [OPTION...] "<COMMAND...>"
}
}

// Pull and tag images
for _, target := range targets {
if output, err := exec.Command("docker", strings.Split(fmt.Sprintf(`pull --platform linux/%v %v`, target.Architecture, target.OS), " ")...).CombinedOutput(); err != nil {
log.Fatalln("could not pull image:", err.Error()+":", string(output))
}

if output, err := exec.Command("docker", strings.Split(fmt.Sprintf(`tag %v %v-%v`, target.OS, target.OS, strings.Replace(target.Architecture, "/", "-", -1)), " ")...).CombinedOutput(); err != nil {
log.Fatalln("could not tag image:", err.Error()+":", string(output))
}
}

// Setup concurrency
sem := semaphore.NewWeighted(*jobFlag)
ctx := context.Background()

for _, target := range targets {
// Aquire lock
if err := sem.Acquire(ctx, 1); err != nil {
log.Fatalln("could acquire lock:", err)
log.Fatalln("could not acquire lock:", err)
}

go func(t Target) {
// Construct the arguments
dockerArgs := fmt.Sprintf(`run %v %v:/data:z --platform linux/%v%v %v /bin/sh -c`, func() string {
dockerArgs := fmt.Sprintf(`run %v %v:/data:z --platform linux/%v%v %v-%v /bin/sh -c`, func() string {
// Attach stdin and setup a TTY
if *itFlag {
return "-it -v"
Expand All @@ -107,7 +118,7 @@ Usage: %s [OPTION...] "<COMMAND...>"
}

return args
}(), t.OS)
}(), t.OS, strings.Replace(t.Architecture, "/", "-", -1))
commandArgs := fmt.Sprintf(`cd /data && %v`, t.Command)

// Construct the command
Expand Down

0 comments on commit 316107b

Please sign in to comment.