Skip to content

Commit

Permalink
feat: disable fallback by default, return nothing if no builder is fo…
Browse files Browse the repository at this point in the history
…und (#207)

* feat: disable fallback by default, return nothing if no builder is found

Signed-off-by: Kasper J. Hermansen <[email protected]>

* feat: with parse bool

Signed-off-by: Kasper J. Hermansen <[email protected]>

---------

Signed-off-by: Kasper J. Hermansen <[email protected]>
  • Loading branch information
kjuulh authored Dec 14, 2023
1 parent 57b860d commit 5c0cc23
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/features/golang-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

17 changes: 16 additions & 1 deletion pkg/executors/golang/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"os"
"os/exec"
"path"
"strconv"
"strings"

"dagger.io/dagger"
"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"
Expand Down Expand Up @@ -134,11 +136,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)
Expand Down Expand Up @@ -235,3 +239,14 @@ func getGolangImage() string {

return golangImage
}

func goDaggerFallback() bool {
daggerFallback := os.Getenv("SHUTTLE_GOLANG_ACTIONS_DAGGER_FALLBACK")

daggerFallbackEnabled, err := strconv.ParseBool(daggerFallback)
if err != nil {
return false
}

return daggerFallbackEnabled
}
7 changes: 7 additions & 0 deletions pkg/executors/golang/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package errors

import "errors"

var (
ErrGolangActionNoBuilder = errors.New("golang actions no builder enabled")
)
5 changes: 5 additions & 0 deletions pkg/executors/golang/executer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/executors/golang/executer/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package executer

import (
"context"
"errors"
"fmt"
"log"
"time"

"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"
)

Expand All @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/executors/golang/executer/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package executer

import (
"context"
"errors"

"github.com/lunarway/shuttle/pkg/config"
golangerrors "github.com/lunarway/shuttle/pkg/executors/golang/errors"
"github.com/lunarway/shuttle/pkg/ui"
)

Expand All @@ -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
}
Expand Down

0 comments on commit 5c0cc23

Please sign in to comment.