This commit is contained in:
@@ -8,9 +8,19 @@ import (
|
||||
"time"
|
||||
|
||||
"dagger.io/dagger"
|
||||
platformFormat "github.com/containerd/containerd/platforms"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var platforms = []dagger.Platform{
|
||||
"linux/amd64",
|
||||
"linux/arm64",
|
||||
}
|
||||
|
||||
func architectureOf(platform dagger.Platform) string {
|
||||
return platformFormat.MustParse(string(platform)).Architecture
|
||||
}
|
||||
|
||||
func Build(ctx context.Context) error {
|
||||
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
|
||||
if err != nil {
|
||||
@@ -18,11 +28,7 @@ func Build(ctx context.Context) error {
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
platforms := []dagger.Platform{
|
||||
"linux/amd64",
|
||||
"linux/arm64",
|
||||
}
|
||||
containers := make([]*dagger.Container, 0)
|
||||
containers := make([]*dagger.Container, 0, len(platforms))
|
||||
|
||||
egrp, _ := errgroup.WithContext(ctx)
|
||||
|
||||
@@ -32,9 +38,7 @@ func Build(ctx context.Context) error {
|
||||
platform := platform
|
||||
|
||||
egrp.Go(func() error {
|
||||
golang := client.Container(dagger.ContainerOpts{
|
||||
Platform: platform,
|
||||
}).From("golang:1.20")
|
||||
golang := client.Container().From("golang:1.20.3")
|
||||
|
||||
golangDir := golang.Directory("/usr/local/go")
|
||||
|
||||
@@ -49,6 +53,8 @@ func Build(ctx context.Context) error {
|
||||
WithDirectory("/app", shuttleGit).
|
||||
WithWorkdir("/app").
|
||||
WithEnvVariable("CGO_ENABLED", "0").
|
||||
WithEnvVariable("GOOS", "linux").
|
||||
WithEnvVariable("GOARCH", architectureOf(platform)).
|
||||
WithExec([]string{"go", "build"})
|
||||
|
||||
if _, err := shuttleImg.ExitCode(ctx); err != nil {
|
||||
@@ -91,6 +97,8 @@ func Build(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
|
||||
if err := egrp.Wait(); err != nil {
|
||||
|
Reference in New Issue
Block a user