bust/pkg/cli/cli.go

46 lines
896 B
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-29 19:06:50 +02:00
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks"
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-29 22:23:06 +02:00
client, err := internal.New(ctx)
if err != nil {
return err
2022-10-29 19:06:50 +02:00
}
2022-10-29 22:23:06 +02:00
defer client.CleanUp()
2022-10-29 19:06:50 +02:00
2022-10-29 23:27:43 +02:00
return tasks.Build(client, imageTag, mainGoPath)
2022-10-29 18:00:16 +02:00
},
}
return cmd
}