dockerimg: simplify pushdockerimg by requiring it run on linux
Replace the complex Mac/Colima-based Docker build script with a simpler
version that works on vanilla Ubuntu. The new script:
1. Provides setup instructions for Ubuntu environments
2. Builds and pushes multi-architecture images in a single command
3. Eliminates the need for multiple VMs/contexts
Co-Authored-By: sketch <hello@sketch.dev>
Signed-off-by: David Crawshaw <david@zentus.com>
diff --git a/dockerimg/pushdockerimg.go b/dockerimg/pushdockerimg.go
index cd9e543..41d1b65 100644
--- a/dockerimg/pushdockerimg.go
+++ b/dockerimg/pushdockerimg.go
@@ -8,27 +8,49 @@
"os"
"os/exec"
"path/filepath"
+ "runtime"
"sketch.dev/dockerimg"
)
func main() {
+ if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
+ fmt.Fprintf(os.Stderr, "pushdockerimg.go: requires ubuntu linux/amd64\n")
+ os.Exit(2)
+ }
+ // Display setup instructions for vanilla Ubuntu
+ fmt.Print(`Push a sketch docker image to the public GitHub container registry.
+
+ # One-off setup instructions:
+ sudo apt-get update
+ sudo apt-get install docker.io docker-buildx qemu-user-static
+ # Login to Docker with GitHub credentials
+ # You can get #GH_ACCESS_TOK from github.com or from 'gh auth token'.
+ # Make sure the token is configured to write containers for the boldsoftware org.
+ echo $GH_ACCESS_TOK | docker login ghcr.io -u $GH_USER --password-stdin
+
+This script will build and push multi-architecture Docker images to ghcr.io.
+Ensure you have followed the setup instructions above and are logged in to Docker and GitHub.
+
+Press Enter to continue or Ctrl+C to abort...`)
+ fmt.Scanln()
+
+ // Create a temporary directory for building
dir, err := os.MkdirTemp("", "sketch-pushdockerimg-*")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
+ // Get default image information
name, dockerfile, tag := dockerimg.DefaultImage()
+
+ // Write the Dockerfile to the temporary directory
if err := os.WriteFile(filepath.Join(dir, "Dockerfile"), []byte(dockerfile), 0o666); err != nil {
panic(err)
}
- fmt.Print(`NOTE: this requires:
- brew install colima docker docker-buildx qemu
- gh auth token | docker login ghcr.io -u $(gh api user --jq .login) --password-stdin
-`)
-
+ // Helper function to run commands
run := func(args ...string) {
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = dir
@@ -42,22 +64,25 @@
path := name + ":" + tag
- run("colima", "start")
- run("docker", "buildx", "create", "--name", "arm", "--use", "--driver", "docker-container", "--bootstrap")
- run("docker", "buildx", "use", "arm")
- run("docker", "buildx", "build", "--platform", "linux/arm64", "-t", path+"arm64", "--push", ".")
- run("docker", "buildx", "rm", "arm")
- run("colima", "start", "--profile=intel", "--arch=x86_64", "--vm-type=vz", "--vz-rosetta", "--memory=4", "--disk=15")
- run("docker", "context", "use", "colima-intel")
- run("docker", "buildx", "create", "--name", "intel", "--use", "--driver", "docker-container", "--bootstrap")
- run("docker", "buildx", "use", "intel")
- run("docker", "buildx", "build", "--platform", "linux/amd64", "-t", path+"amd64", "--push", ".")
- run("docker", "buildx", "rm", "intel")
- run("docker", "context", "use", "colima")
- run("colima", "stop", "--profile=intel")
- run(
- "docker", "buildx", "imagetools", "create",
- "-t", path, path+"arm64", path+"amd64",
+ // Set up BuildX for multi-arch builds
+ run("docker", "buildx", "create", "--name", "multiarch-builder", "--use")
+
+ // Make sure the builder is using the proper driver for multi-arch builds
+ run("docker", "buildx", "inspect", "--bootstrap")
+
+ // Build and push the multi-arch image in a single command
+ run("docker", "buildx", "build",
+ "--platform", "linux/amd64,linux/arm64",
+ "-t", path,
+ "--push",
+ ".",
)
+
+ // Inspect the built image to verify it contains both architectures
run("docker", "buildx", "imagetools", "inspect", path)
+
+ // Clean up the builder
+ run("docker", "buildx", "rm", "multiarch-builder")
+
+ fmt.Printf("\n✅ Successfully built and pushed multi-arch image: %s\n", path)
}