bust/pkg/tasks/build.go

45 lines
887 B
Go
Raw Normal View History

2022-10-29 18:15:55 +02:00
package tasks
2022-10-29 22:23:06 +02:00
import (
"context"
"log"
2022-10-29 18:15:55 +02:00
2022-10-29 22:23:06 +02:00
"dagger.io/dagger"
"git.front.kjuulh.io/kjuulh/byg"
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
)
2022-10-29 18:15:55 +02:00
2022-10-29 22:23:06 +02:00
func Build(builder *internal.Builder, imageTag string) error {
2022-10-29 18:15:55 +02:00
log.Printf("building image: %s", imageTag)
2022-10-29 22:23:06 +02:00
client := builder.Dagger
ctx := context.Background()
return byg.
New().
Step(
"build golang",
byg.Step{
Execute: func(_ byg.Context) error {
src, err := client.
Host().
Workdir().
Read().
ID(context.Background())
if err != nil {
return err
}
golang := client.Container().From("golang:latest")
golang = golang.WithMountedDirectory("/src", src).WithWorkdir("/src")
_, err = golang.Exec(dagger.ContainerExecOpts{
Args: []string{"go", "build", "-o", "build/"},
}).ExitCode(ctx)
return err
},
}).
Execute(context.Background())
2022-10-29 18:15:55 +02:00
}