From 79c62e2c055a3f2a409e9f8e17578b0b3e7cd517 Mon Sep 17 00:00:00 2001 From: "Kasper J. Hermansen" Date: Thu, 14 Dec 2023 14:25:08 +0100 Subject: [PATCH] feat: disable fallback by default, return nothing if no builder is found Signed-off-by: Kasper J. Hermansen --- docs/features/golang-actions.md | 7 +++++++ pkg/executors/golang/compile/compile.go | 14 +++++++++++++- pkg/executors/golang/errors/errors.go | 7 +++++++ pkg/executors/golang/executer/list.go | 5 +++++ pkg/executors/golang/executer/prepare.go | 5 +++++ pkg/executors/golang/executer/run.go | 6 ++++++ 6 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 pkg/executors/golang/errors/errors.go diff --git a/docs/features/golang-actions.md b/docs/features/golang-actions.md index a3c185a..d10d7cd 100644 --- a/docs/features/golang-actions.md +++ b/docs/features/golang-actions.md @@ -110,3 +110,10 @@ The variable is default `true`, `false` will disable golang, and any other value ### SHUTTLE_GOLANG_ACTIONS_IMAGE This variable controls an override for proving different image for building the golang actions. The image is automatically kept up-to-date, but it may be needed to set this in the place of use, such that a race condition doesn't occur. + +### SHUTTLE_GOLANG_ACTIONS_DAGGER_FALLBACK + +default: `false`, meaning we don't use dagger as a fallback +`true` is enabled, and will use a dagger pipeline to build the actions if go isn't installed +anything is false and will be disabled + diff --git a/pkg/executors/golang/compile/compile.go b/pkg/executors/golang/compile/compile.go index f9e5fd6..aa67a8e 100644 --- a/pkg/executors/golang/compile/compile.go +++ b/pkg/executors/golang/compile/compile.go @@ -13,6 +13,7 @@ import ( "github.com/lunarway/shuttle/pkg/executors/golang/codegen" "github.com/lunarway/shuttle/pkg/executors/golang/compile/matcher" "github.com/lunarway/shuttle/pkg/executors/golang/discover" + golangerrors "github.com/lunarway/shuttle/pkg/executors/golang/errors" "github.com/lunarway/shuttle/pkg/executors/golang/parser" "github.com/lunarway/shuttle/pkg/executors/golang/shuttlefolder" "github.com/lunarway/shuttle/pkg/ui" @@ -134,11 +135,13 @@ func compile(ctx context.Context, ui *ui.UI, actions *discover.ActionsDiscovered if err != nil { return "", fmt.Errorf("go build failed: %w", err) } - } else { + } else if goDaggerFallback() { binarypath, err = compileWithDagger(ctx, ui, shuttlelocaldir) if err != nil { return "", fmt.Errorf("failed to compile with dagger: %w", err) } + } else { + return "", golangerrors.ErrGolangActionNoBuilder } finalBinaryPath := shuttlefolder.CalculateBinaryPath(shuttlelocaldir, hash) @@ -235,3 +238,12 @@ func getGolangImage() string { return golangImage } + +func goDaggerFallback() bool { + daggerFallback := os.Getenv("SHUTTLE_GOLANG_ACTIONS_DAGGER_FALLBACK") + if daggerFallback == "true" { + return true + } + + return false +} diff --git a/pkg/executors/golang/errors/errors.go b/pkg/executors/golang/errors/errors.go new file mode 100644 index 0000000..6d4b1c7 --- /dev/null +++ b/pkg/executors/golang/errors/errors.go @@ -0,0 +1,7 @@ +package errors + +import "errors" + +var ( + ErrGolangActionNoBuilder = errors.New("golang actions no builder enabled") +) diff --git a/pkg/executors/golang/executer/list.go b/pkg/executors/golang/executer/list.go index 53d785d..a66ce5c 100644 --- a/pkg/executors/golang/executer/list.go +++ b/pkg/executors/golang/executer/list.go @@ -2,9 +2,11 @@ package executer import ( "context" + "errors" "os" "github.com/lunarway/shuttle/pkg/config" + golangerrors "github.com/lunarway/shuttle/pkg/executors/golang/errors" "github.com/lunarway/shuttle/pkg/ui" ) @@ -21,6 +23,9 @@ func List( binaries, err := prepare(ctx, ui, path, c) if err != nil { + if errors.Is(err, golangerrors.ErrGolangActionNoBuilder) { + return NewActions(), nil + } return nil, err } diff --git a/pkg/executors/golang/executer/prepare.go b/pkg/executors/golang/executer/prepare.go index 6c0710e..402a552 100644 --- a/pkg/executors/golang/executer/prepare.go +++ b/pkg/executors/golang/executer/prepare.go @@ -2,6 +2,7 @@ package executer import ( "context" + "errors" "fmt" "log" "time" @@ -9,6 +10,7 @@ import ( "github.com/lunarway/shuttle/pkg/config" "github.com/lunarway/shuttle/pkg/executors/golang/compile" "github.com/lunarway/shuttle/pkg/executors/golang/discover" + golangerrors "github.com/lunarway/shuttle/pkg/executors/golang/errors" "github.com/lunarway/shuttle/pkg/ui" ) @@ -29,6 +31,9 @@ func prepare( binaries, err := compile.Compile(ctx, ui, disc) if err != nil { + if errors.Is(err, golangerrors.ErrGolangActionNoBuilder) { + return nil, err + } return nil, fmt.Errorf("failed to compile binaries: %v", err) } diff --git a/pkg/executors/golang/executer/run.go b/pkg/executors/golang/executer/run.go index 084e50b..7c24048 100644 --- a/pkg/executors/golang/executer/run.go +++ b/pkg/executors/golang/executer/run.go @@ -2,7 +2,9 @@ package executer import ( "context" + "errors" + golangerrors "github.com/lunarway/shuttle/okg/executors/golang/errors" "github.com/lunarway/shuttle/pkg/config" "github.com/lunarway/shuttle/pkg/ui" ) @@ -21,6 +23,10 @@ func Run( binaries, err := prepare(ctx, ui, path, c) if err != nil { + if errors.Is(err, golangerrors.ErrGolangActionNoBuilder) { + return nil + } + ui.Errorln("failed to run command: %v", err) return err }