bust/pkg/cli/cli.go

56 lines
1.1 KiB
Go
Raw Normal View History

2022-10-29 18:32:51 +02:00
package cli
2022-10-29 18:00:16 +02:00
import (
2022-10-29 23:33:46 +02:00
"errors"
"fmt"
2022-10-29 18:00:16 +02:00
"log"
2022-10-29 23:33:46 +02:00
"os"
2022-10-29 18:00:16 +02:00
2022-10-29 22:23:06 +02:00
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
2022-10-30 18:13:57 +01:00
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
2022-10-29 18:00:16 +02:00
"github.com/spf13/cobra"
)
2022-10-29 23:33:46 +02:00
func Build(mainGoPath string, imageTag string) *cobra.Command {
2022-10-29 18:00:16 +02:00
cmd := &cobra.Command{
Use: "build",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.ParseFlags(args); err != nil {
return err
}
2022-10-29 23:33:46 +02:00
if imageTag == "" {
repoName := os.Getenv("DRONE_REPO_NAME")
if repoName == "" {
return errors.New("could not find DRONE_REPO_NAME")
}
imageTag = fmt.Sprintf("harbor.front.kjuulh.io/library/%s", repoName)
}
2022-10-29 22:23:06 +02:00
ctx := cmd.Context()
log.Printf("Building image: %s\n", imageTag)
2022-10-29 18:00:16 +02:00
2022-10-30 18:13:57 +01:00
builder, err := internal.New(ctx)
2022-10-29 22:23:06 +02:00
if err != nil {
return err
2022-10-29 19:06:50 +02:00
}
2022-10-30 18:13:57 +01:00
defer builder.CleanUp()
return pipelines.
New(builder).
WithGolangBin(&pipelines.GolangBinOpts{
DockerImageOpt: &pipelines.DockerImageOpt{
ImageName: "golang-bin",
},
BuildPath: "example/golang-bin/main.go",
BinName: "golang-bin",
}).
Execute(ctx)
2022-10-29 19:06:50 +02:00
2022-10-29 18:00:16 +02:00
},
}
return cmd
}