Skip to content

Commit

Permalink
feat: Add runtime config flag to stack deploy and stack preview comma…
Browse files Browse the repository at this point in the history
…nds (#290)
  • Loading branch information
0michalsokolowski0 authored Feb 21, 2025
1 parent e838a85 commit 3e17bfb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ linters-settings:
goimports:
local-prefixes: github.com/spacelift-io/backend
govet:
check-shadowing: false
enable:
- nilness
nolintlint:
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/stack/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ var flagAutoConfirm = &cli.BoolFlag{
Required: false,
}

var flagRuntimeConfig = &cli.StringFlag{
Name: "runtime-config",
Usage: "[Optional] Path to the runtime config file (https://docs.spacelift.io/concepts/configuration/runtime-configuration/runtime-yaml-reference#stack_defaults)",
Required: false,
}

var flagNoTail = &cli.BoolFlag{
Name: "no-tail",
Usage: "Indicate whether not to tail the run",
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/stack/inputs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package stack

// RuntimeConfigInput represents the input for triggering a run with a runtime configuration.
type RuntimeConfigInput struct {
Yaml *string `json:"yaml"`
}
30 changes: 26 additions & 4 deletions internal/cmd/stack/run_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package stack
import (
"context"
"fmt"
"os"

"github.com/shurcooL/graphql"
"github.com/spacelift-io/spacectl/client/structs"
Expand All @@ -18,16 +19,37 @@ func runTrigger(spaceliftType, humanType string) cli.ActionFunc {
return err
}

var runtimeConfigInput *RuntimeConfigInput
if cliCtx.IsSet(flagRuntimeConfig.Name) {
runtimeConfigFilePath := cliCtx.String(flagRuntimeConfig.Name)

if _, err = os.Stat(runtimeConfigFilePath); err != nil {
return fmt.Errorf("runtime config file does not exist: %v", err)
}

data, err := os.ReadFile(runtimeConfigFilePath)
if err != nil {
return fmt.Errorf("failed to read runtime config file: %v", err)
}

yaml := string(data)

runtimeConfigInput = &RuntimeConfigInput{
Yaml: &yaml,
}
}

var mutation struct {
RunTrigger struct {
ID string `graphql:"id"`
} `graphql:"runTrigger(stack: $stack, commitSha: $sha, runType: $type)"`
} `graphql:"runTrigger(stack: $stack, commitSha: $sha, runType: $type, runtimeConfig: $runtimeConfig)"`
}

variables := map[string]interface{}{
"stack": graphql.ID(stackID),
"sha": (*graphql.String)(nil),
"type": structs.NewRunType(spaceliftType),
"stack": graphql.ID(stackID),
"sha": (*graphql.String)(nil),
"type": structs.NewRunType(spaceliftType),
"runtimeConfig": runtimeConfigInput,
}

if cliCtx.IsSet(flagCommitSHA.Name) {
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func Command() *cli.Command {
flagRunMetadata,
flagTail,
flagAutoConfirm,
flagRuntimeConfig,
},
Action: runTrigger("TRACKED", "deployment"),
Before: authenticated.Ensure,
Expand Down Expand Up @@ -190,6 +191,7 @@ func Command() *cli.Command {
flagCommitSHA,
flagRunMetadata,
flagTail,
flagRuntimeConfig,
},
Action: runTrigger("PROPOSED", "preview"),
Before: authenticated.Ensure,
Expand Down

0 comments on commit 3e17bfb

Please sign in to comment.