Fix Dagger pipeline: export built binaries to dist/ directory on host
This commit is contained in:
54
ci/dagger.go
Normal file
54
ci/dagger.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user