diff --git a/docs/features/golang-actions.md b/docs/features/golang-actions.md index e05a218..a3c185a 100644 --- a/docs/features/golang-actions.md +++ b/docs/features/golang-actions.md @@ -98,3 +98,15 @@ Why would you want such a feature? - A more thorough user experience can be designed. - No longer bound to what is installed on a client machine, you don't need curl, wget, uname, grep, yq, jq etc. installed + +## Configuration + +### SHUTTLE_GOLANG_ACTIONS + +This variable controls whether or not to enable or disable the golang actions. This may be wanted in environments where golang or docker isn't available, or wanted. + +The variable is default `true`, `false` will disable golang, and any other value will be considered `true` + +### 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. diff --git a/pkg/executors/golang/compile/compile.go b/pkg/executors/golang/compile/compile.go index a81bb55..60aca95 100644 --- a/pkg/executors/golang/compile/compile.go +++ b/pkg/executors/golang/compile/compile.go @@ -175,7 +175,7 @@ func compileWithDagger(ctx context.Context, ui *ui.UI, shuttlelocaldir string) ( log.Printf("nakedShuttleDir: %s", nakedShuttleDir) shuttleBinary := client.Container(). - From("golang:1.20-alpine"). + From(getGolangImage()). WithWorkdir("/app"). WithDirectory(".", src). WithWorkdir(path.Join(nakedShuttleDir, "tmp")). @@ -220,3 +220,18 @@ func goInstalled() bool { return true } + +func getGolangImage() string { + const ( + // renovate: datasource=docker depName=golang + golangImageVersion = "1.20-alpine" + ) + + golangImage := fmt.Sprintf("golang:%s", golangImageVersion) + golangImageOverride := os.Getenv("SHUTTLE_GOLANG_ACTIONS_IMAGE") + if golangImageOverride != "" { + return golangImageOverride + } + + return golangImage +} diff --git a/pkg/executors/golang/executer/list.go b/pkg/executors/golang/executer/list.go index fb53f2b..53d785d 100644 --- a/pkg/executors/golang/executer/list.go +++ b/pkg/executors/golang/executer/list.go @@ -2,6 +2,7 @@ package executer import ( "context" + "os" "github.com/lunarway/shuttle/pkg/config" "github.com/lunarway/shuttle/pkg/ui" @@ -13,6 +14,11 @@ func List( path string, c *config.ShuttleProjectContext, ) (*Actions, error) { + if !isActionsEnabled() { + ui.Verboseln("shuttle golang actions disabled") + return NewActions(), nil + } + binaries, err := prepare(ctx, ui, path, c) if err != nil { return nil, err @@ -33,3 +39,13 @@ func List( return actions, nil } + +func isActionsEnabled() bool { + enabled := os.Getenv("SHUTTLE_GOLANG_ACTIONS") + + if enabled == "false" { + return false + } + + return true +} diff --git a/pkg/executors/golang/executer/list_test.go b/pkg/executors/golang/executer/list_test.go new file mode 100644 index 0000000..b45f432 --- /dev/null +++ b/pkg/executors/golang/executer/list_test.go @@ -0,0 +1,33 @@ +package executer + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIsActionsEnabled(t *testing.T) { + t.Run("default is enabled", func(t *testing.T) { + t.Setenv("SHUTTLE_GOLANG_ACTIONS", "") + + assert.True(t, isActionsEnabled()) + }) + + t.Run("set false is not enabled", func(t *testing.T) { + t.Setenv("SHUTTLE_GOLANG_ACTIONS", "false") + + assert.False(t, isActionsEnabled()) + }) + + t.Run("set true is enabled", func(t *testing.T) { + t.Setenv("SHUTTLE_GOLANG_ACTIONS", "true") + + assert.True(t, isActionsEnabled()) + }) + + t.Run("set any other value is enabled", func(t *testing.T) { + t.Setenv("SHUTTLE_GOLANG_ACTIONS", "blabla") + + assert.True(t, isActionsEnabled()) + }) +} diff --git a/pkg/executors/golang/executer/run.go b/pkg/executors/golang/executer/run.go index 9435c16..084e50b 100644 --- a/pkg/executors/golang/executer/run.go +++ b/pkg/executors/golang/executer/run.go @@ -14,6 +14,11 @@ func Run( path string, args ...string, ) error { + if !isActionsEnabled() { + ui.Verboseln("shuttle golang actions disabled") + return nil + } + binaries, err := prepare(ctx, ui, path, c) if err != nil { ui.Errorln("failed to run command: %v", err) diff --git a/renovate.json b/renovate.json index 3cebea3..760729a 100644 --- a/renovate.json +++ b/renovate.json @@ -2,5 +2,28 @@ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "local>lunarway/renovate-config" + ], + "regexManagers": [ + { + "description": "Update docker images in go files", + "fileMatch": [ + "^.*\\.go$" + ], + "matchStrings": [ + "\\/\\/ renovate: datasource=(?[a-z-]+?) depName=(?[a-z-]+)\\s+([a-zA-Z]*)\\s*[:|=]\\s+\"(?.*)\"\\,?" + ], + "versioningTemplate": "docker" + } + ], + "packageRules": [ + { + "description": "Update docker tags frequently", + "matchDatasources": [ + "docker" + ], + "extends": [ + "schedule:nonOfficeHours" + ] + } ] -} +} \ No newline at end of file