55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// Dagger pipeline for multi-platform builds.
|
|
// Requires: go install dagger.io/dagger@latest && go mod tidy
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"dagger.io/dagger"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer client.Close()
|
|
|
|
platforms := []struct {
|
|
OS string
|
|
Arch string
|
|
}{
|
|
{"darwin", "arm64"},
|
|
{"darwin", "amd64"},
|
|
{"windows", "amd64"},
|
|
{"linux", "amd64"},
|
|
}
|
|
|
|
src := client.Host().Directory(".")
|
|
|
|
for _, p := range platforms {
|
|
binName := fmt.Sprintf("valhallir-deconvolver-%s-%s", p.OS, p.Arch)
|
|
if p.OS == "windows" {
|
|
binName += ".exe"
|
|
}
|
|
|
|
ctr := client.Container().From("golang:1.24.5").
|
|
WithMountedDirectory("/src", src).
|
|
WithWorkdir("/src").
|
|
WithEnvVariable("GOOS", p.OS).
|
|
WithEnvVariable("GOARCH", p.Arch).
|
|
WithExec([]string{"go", "build", "-o", binName, "."})
|
|
|
|
// Export the binary from the container to the host's dist/ directory
|
|
outPath := fmt.Sprintf("dist/%s", binName)
|
|
_, err := ctr.File(binName).Export(ctx, outPath)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("export failed for %s/%s: %v", p.OS, p.Arch, err))
|
|
}
|
|
fmt.Printf("Built and exported %s\n", outPath)
|
|
}
|
|
}
|