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: with override for golang actions #205

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions docs/features/golang-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 16 additions & 1 deletion pkg/executors/golang/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")).
Expand Down Expand Up @@ -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
}
16 changes: 16 additions & 0 deletions pkg/executors/golang/executer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package executer

import (
"context"
"os"

"github.com/lunarway/shuttle/pkg/config"
"github.com/lunarway/shuttle/pkg/ui"
Expand All @@ -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
Expand All @@ -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
}
5 changes: 5 additions & 0 deletions pkg/executors/golang/executer/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 24 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=(?<datasource>[a-z-]+?) depName=(?<depName>[a-z-]+)\\s+([a-zA-Z]*)\\s*[:|=]\\s+\"(?<currentValue>.*)\"\\,?"
],
"versioningTemplate": "docker"
}
],
"packageRules": [
{
"description": "Update docker tags frequently",
"matchDatasources": [
"docker"
],
"extends": [
"schedule:nonOfficeHours"
]
}
]
}
}
Loading