with actual cli
This commit is contained in:
15
pkg/cli/build.go
Normal file
15
pkg/cli/build.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func Build() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "build",
|
||||
}
|
||||
|
||||
cmd.AddCommand(BuildGolangBin())
|
||||
|
||||
return cmd
|
||||
}
|
45
pkg/cli/build_golang_bin.go
Normal file
45
pkg/cli/build_golang_bin.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func BuildGolangBin() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "golangbin",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
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)
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
builder, err := builder.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer builder.CleanUp()
|
||||
|
||||
return pipelines.
|
||||
New(builder).
|
||||
WithGolangBin(&pipelines.GolangBinOpts{
|
||||
DockerImageOpt: &pipelines.DockerImageOpt{
|
||||
ImageName: imageTag,
|
||||
},
|
||||
BuildPath: "main.go",
|
||||
BinName: "main",
|
||||
}).
|
||||
Execute(ctx)
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func Build(mainGoPath string, imageTag string) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "build",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := cmd.ParseFlags(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
log.Printf("Building image: %s\n", imageTag)
|
||||
|
||||
builder, err := internal.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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)
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
13
pkg/cli/root.go
Normal file
13
pkg/cli/root.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package cli
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
func NewCli() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "dagger",
|
||||
}
|
||||
|
||||
cmd.AddCommand(Build())
|
||||
|
||||
return cmd
|
||||
}
|
Reference in New Issue
Block a user