Skip to content

Commit

Permalink
Merge pull request #1219 from nicktate/feature/appdev-config-updates
Browse files Browse the repository at this point in the history
appdev: config updates: add hierarchy and per-component overrides, updated env-file handling
  • Loading branch information
Kamal Nasser authored Sep 7, 2022
2 parents 1b6a1cf + eba81df commit d4c7a39
Show file tree
Hide file tree
Showing 19 changed files with 1,512 additions and 596 deletions.
8 changes: 4 additions & 4 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const (
ArgAppDeployment = "deployment"
// ArgAppDevConfig is the path to the app dev link config.
ArgAppDevConfig = "dev-config"
// ArgAppDevBuildCommand is an optional build command to set for local development.
ArgAppDevBuildCommand = "build-command"
// ArgBuildCommand is an optional build command to set for local development.
ArgBuildCommand = "build-command"
// ArgAppLogFollow follow logs.
ArgAppLogFollow = "follow"
// ArgAppLogTail tail logs.
Expand Down Expand Up @@ -353,8 +353,8 @@ const (

// ArgReadWrite indicates a generated token should be read/write.
ArgReadWrite = "read-write"
// ArgRegistryName indicates the name of the registry.
ArgRegistryName = "registry-name"
// ArgRegistry indicates the name of the registry.
ArgRegistry = "registry"
// ArgRegistryExpirySeconds indicates the length of time the token will be valid in seconds.
ArgRegistryExpirySeconds = "expiry-seconds"
// ArgSubscriptionTier is a subscription tier slug.
Expand Down
55 changes: 5 additions & 50 deletions commands/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/commands/displayers"
"github.com/digitalocean/doctl/do"
"github.com/digitalocean/doctl/internal/apps"
"github.com/digitalocean/godo"
multierror "github.com/hashicorp/go-multierror"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -237,7 +238,7 @@ func RunAppsCreate(c *CmdConfig) error {
return err
}

appSpec, err := readAppSpec(os.Stdin, specPath)
appSpec, err := apps.ReadAppSpec(os.Stdin, specPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -334,7 +335,7 @@ func RunAppsUpdate(c *CmdConfig) error {
return err
}

appSpec, err := readAppSpec(os.Stdin, specPath)
appSpec, err := apps.ReadAppSpec(os.Stdin, specPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -635,7 +636,7 @@ func RunAppsPropose(c *CmdConfig) error {
return err
}

appSpec, err := readAppSpec(os.Stdin, specPath)
appSpec, err := apps.ReadAppSpec(os.Stdin, specPath)
if err != nil {
return err
}
Expand All @@ -653,52 +654,6 @@ func RunAppsPropose(c *CmdConfig) error {
return c.Display(displayers.AppProposeResponse{Res: res})
}

func readAppSpec(stdin io.Reader, path string) (*godo.AppSpec, error) {
var spec io.Reader
if path == "-" {
spec = stdin
} else {
specFile, err := os.Open(path) // guardrails-disable-line
if err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("opening app spec: %s does not exist", path)
}
return nil, fmt.Errorf("opening app spec: %w", err)
}
defer specFile.Close()
spec = specFile
}

byt, err := ioutil.ReadAll(spec)
if err != nil {
return nil, fmt.Errorf("reading app spec: %w", err)
}

s, err := parseAppSpec(byt)
if err != nil {
return nil, fmt.Errorf("parsing app spec: %w", err)
}

return s, nil
}

func parseAppSpec(spec []byte) (*godo.AppSpec, error) {
jsonSpec, err := yaml.YAMLToJSON(spec)
if err != nil {
return nil, err
}

dec := json.NewDecoder(bytes.NewReader(jsonSpec))
dec.DisallowUnknownFields()

var appSpec godo.AppSpec
if err := dec.Decode(&appSpec); err != nil {
return nil, err
}

return &appSpec, nil
}

func appsSpec() *Command {
cmd := &Command{
Command: &cobra.Command{
Expand Down Expand Up @@ -778,7 +733,7 @@ func RunAppsSpecValidate(c *CmdConfig) error {
}

specPath := c.Args[0]
appSpec, err := readAppSpec(os.Stdin, specPath)
appSpec, err := apps.ReadAppSpec(os.Stdin, specPath)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit d4c7a39

Please sign in to comment.