add build steps
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func Build(requirementsf func(*cobra.Command), buildf func(ctx context.Context) error) *cobra.Command {
|
||||
func Build() *cobra.Command {
|
||||
var (
|
||||
imageTag string
|
||||
)
|
||||
@@ -20,21 +20,22 @@ func Build(requirementsf func(*cobra.Command), buildf func(ctx context.Context)
|
||||
return err
|
||||
}
|
||||
|
||||
if imageTag != "" {
|
||||
log.Printf("Building image: %s\n", imageTag)
|
||||
}
|
||||
ctx := cmd.Context()
|
||||
|
||||
if buildf != nil {
|
||||
return buildf(cmd.Context())
|
||||
}
|
||||
log.Printf("Building image: %s\n", imageTag)
|
||||
|
||||
return tasks.Build(imageTag)
|
||||
client, err := internal.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.CleanUp()
|
||||
|
||||
return tasks.Build(client, imageTag)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().StringVar(&imageTag, "image-tag", "", "the url for which to tag the docker image, defaults to private url, with repo as image name")
|
||||
|
||||
requirementsf(cmd)
|
||||
cmd.MarkPersistentFlagRequired("image-tag")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@@ -1,10 +1,44 @@
|
||||
package tasks
|
||||
|
||||
import "log"
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
func Build(imageTag string) error {
|
||||
"dagger.io/dagger"
|
||||
"git.front.kjuulh.io/kjuulh/byg"
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
|
||||
)
|
||||
|
||||
func Build(builder *internal.Builder, imageTag string) error {
|
||||
log.Printf("building image: %s", imageTag)
|
||||
|
||||
return nil
|
||||
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())
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user