Skip to content

Commit

Permalink
Revert "Allow locally building multiplatform docker images (#6256)" (#…
Browse files Browse the repository at this point in the history
…7140)

This reverts commit 508271b.
  • Loading branch information
pchila authored Mar 3, 2025
1 parent 87d335b commit 339055e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
40 changes: 7 additions & 33 deletions dev-tools/mage/dockerbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"

Expand All @@ -24,29 +23,20 @@ import (
type dockerBuilder struct {
PackageSpec

imageName string
buildDir string
beatDir string
isBuildxEnabled bool
imageName string
buildDir string
beatDir string
}

func newDockerBuilder(spec PackageSpec) (*dockerBuilder, error) {
buildDir := filepath.Join(spec.packageDir, "docker-build")
beatDir := filepath.Join(buildDir, "beat")

buildxEnabled := isBuildxEnabled()
if buildxEnabled {
fmt.Println("Docker buildx is available, cross-platform builds are possible")
} else {
fmt.Println("Docker buildx is not available")
}

return &dockerBuilder{
PackageSpec: spec,
imageName: spec.ImageName(),
buildDir: buildDir,
beatDir: beatDir,
isBuildxEnabled: buildxEnabled,
PackageSpec: spec,
imageName: spec.ImageName(),
buildDir: buildDir,
beatDir: beatDir,
}, nil
}

Expand Down Expand Up @@ -198,18 +188,6 @@ func (b *dockerBuilder) dockerBuild() (string, error) {
if repository := b.ExtraVars["repository"]; repository != "" {
tag = fmt.Sprintf("%s/%s", repository, tag)
}

platform := fmt.Sprintf("%s/%s", "linux", b.Arch)

if runtime.GOARCH != b.Arch { // we need a cross-platform build, check if buildx is available
if !b.isBuildxEnabled {
return "", fmt.Errorf("cross-platform docker build requested, but buildx is not available")
}
// if building cross-platform, add the arch name to the tag
tag = fmt.Sprintf("%s-%s", tag, b.Arch)
return tag, sh.Run("docker", "buildx", "build", "-t", tag, "--platform", platform, "--load", b.buildDir)
}

return tag, sh.Run("docker", "build", "-t", tag, b.buildDir)
}

Expand Down Expand Up @@ -275,7 +253,3 @@ func (b *dockerBuilder) dockerSave(tag string) error {
}
return nil
}

func isBuildxEnabled() bool {
return sh.Run("docker", "buildx", "version") == nil
}
6 changes: 6 additions & 0 deletions dev-tools/mage/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strconv"

"github.com/magefile/mage/mg"
Expand Down Expand Up @@ -51,6 +52,11 @@ func Package() error {
continue
}

if target.Name == "linux/arm64" && pkgType == Docker && runtime.GOARCH != "arm64" {
log.Printf("Skipping Docker package type because build host isn't arm")
continue
}

packageArch, err := getOSArchName(target, pkgType)
if err != nil {
log.Printf("Skipping arch %v for package type %v: %v", target.Arch(), pkgType, err)
Expand Down

0 comments on commit 339055e

Please sign in to comment.