Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading