Skip to content

Commit

Permalink
Ntate/appdev/rebased (#1237)
Browse files Browse the repository at this point in the history
* Feature/appdev (#1204)

* apps: add base scaffolding for app dev command subtree

* charm templates: change up method signatures for easier use

* only use 1.18.x in ci

* add internal package to unit test

* disable interactive mode

* only use logging pager in interactive mode

Co-authored-by: Kamal Nasser <kamal@digitalocean.com>

* extract pager component and improve build log output

* Add support for an app dev config and management (#1208)

* Add support for build environment variables (#1209)

* confirmation prompt component

* text input component

* Add support for build command overrides (#1211)

* Add copy on write support for CNB builds (#1213)

* confirm: display result options

* split off list subpackage

* split off pager subpackage

* split off template and textbox packages

* StyledText for icons

* split off text component

* improve indent util

* confirm: clarify prompt persistance behavior

* Add snap support for docker interface for app dev builds (#1214)

* Add snap support for docker interface for app dev builds

* add snap warning message

* support cnb versioning, clean up build envs (#1215)

* add support for local cnb caching (#1216)

* add support for local cnb caching

* address pr feedback

* charm: improved output handling, add warning textbox variant

* add config interfaces and types

* use new config interfaces, add support for per-component config

* address pr feedback, app dev workspace

* structured config

* unexport Config.AppID and config.AppSpecPath

* unexport internal method

* fix unclosed file handler in tests

* test setting and unsetting component-level settings

* appdev: handle user cancellation, log pager styling updates (#1229)

* correctly handle user cancellation

* log pager: update header/footer styling, scroll indicator

* log pager: add title spinner

* add support to build static site server image

* add docker support for static builds

* docker static site build cleanup

* docker static site build tests

* cnb static site build cleanup

* cnb static site build tests

* docker static site build input validation updates

remove /var/run/docker.sock dependency from tests

* fix path handling on windows

* intercept ctrl-c to exit cleanly

* Ntate/appdev/macossupport (#1235)

* mount docker.sock.raw for mac docker-for-desktop

* update local builder to v0.50.2

* support for windows docker-for-desktop (#1238)

* appdev: pull required container images (#1240)

* pull required container images

* pull cnb stack run image

* update no app spec error message

* vendor latest godo

* bump godo to v1.85.0

* support new godo interface types

* address pr feedback

* add better help messaging for app dev config

Co-authored-by: Kamal Nasser <kamal@digitalocean.com>
  • Loading branch information
nicktate and kamaln7 authored Sep 22, 2022
1 parent ff53e5e commit de1918a
Show file tree
Hide file tree
Showing 1,102 changed files with 139,105 additions and 3,958 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ docker_build:
test_unit:
@echo "==> run unit tests"
@echo ""
go test -mod=vendor ./commands/... ./do/... ./pkg/... .
go test -mod=vendor ./commands/... ./do/... ./pkg/... ./internal/... .

.PHONY: test_integration
test_integration:
Expand Down Expand Up @@ -158,6 +158,7 @@ snap:
mocks:
@echo "==> update mocks"
@echo ""
@go generate ./...
@scripts/regenmocks.sh

.PHONY: _upgrade_godo
Expand Down
14 changes: 14 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const (
ArgAppLogType = "type"
// ArgAppDeployment is the deployment ID.
ArgAppDeployment = "deployment"
// ArgAppDevConfig is the path to the app dev link config.
ArgAppDevConfig = "dev-config"
// ArgBuildCommand is an optional build command to set for local development.
ArgBuildCommand = "build-command"
// ArgAppLogFollow follow logs.
ArgAppLogFollow = "follow"
// ArgAppLogTail tail logs.
Expand All @@ -62,6 +66,8 @@ const (
ArgClusterNodePool = "node-pool"
// ArgClusterUpdateKubeconfig updates the local kubeconfig.
ArgClusterUpdateKubeconfig = "update-kubeconfig"
// ArgNoCache represents whether or not to omit the cache on the next command.
ArgNoCache = "no-cache"
// ArgNodePoolName is a cluster's node pool name argument.
ArgNodePoolName = "name"
// ArgNodePoolCount is a cluster's node pool count argument.
Expand Down Expand Up @@ -110,10 +116,14 @@ const (
ArgImagePublic = "public"
// ArgImageSlug is an image slug argument.
ArgImageSlug = "image-slug"
// ArgInteractive is the argument to enable an interactive CLI.
ArgInteractive = "interactive"
// ArgIPAddress is an IP address argument.
ArgIPAddress = "ip-address"
// ArgDropletName is a droplet name argument.
ArgDropletName = "droplet-name"
// ArgEnvFile is an environment file to load variables from.
ArgEnvFile = "env-file"
// ArgResizeDisk is a resize disk argument.
ArgResizeDisk = "resize-disk"
// ArgSnapshotName is a snapshot name argument.
Expand Down Expand Up @@ -212,6 +222,8 @@ const (
ArgTag = "tag"
//ArgTemplate is template format
ArgTemplate = "template"
// ArgTimeout is a timeout duration
ArgTimeout = "timeout"
// ArgVersion is the version of the command to use
ArgVersion = "version"
// ArgVerbose enables verbose output
Expand Down Expand Up @@ -343,6 +355,8 @@ const (

// ArgReadWrite indicates a generated token should be read/write.
ArgReadWrite = "read-write"
// 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
57 changes: 7 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 All @@ -45,6 +46,8 @@ func Apps() *Command {
},
}

cmd.AddCommand(AppsDev())

create := CmdBuilder(
cmd,
RunAppsCreate,
Expand Down Expand Up @@ -235,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 @@ -332,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 @@ -633,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 @@ -651,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 @@ -776,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
35 changes: 35 additions & 0 deletions commands/apps_charm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package commands

import (
"strings"

"github.com/digitalocean/doctl/commands/charm"
"github.com/digitalocean/doctl/commands/charm/template"
"github.com/digitalocean/godo"
)

type componentListItem struct {
spec godo.AppComponentSpec
}

func (i componentListItem) Title() string {
return i.spec.GetName()
}

func (i componentListItem) Description() string {
desc := []string{
strings.ToLower(charm.SnakeToTitle(i.spec.GetType())) + " component",
}

if buildable, ok := i.spec.(godo.AppBuildableComponentSpec); ok {
if sourceDir := buildable.GetSourceDir(); sourceDir != "" {
desc = append(desc, template.String(`located in ./{{highlight .}}`, sourceDir))
}
}

return strings.Join(desc, "\n")
}

func (i componentListItem) FilterValue() string {
return i.spec.GetName()
}
Loading

0 comments on commit de1918a

Please sign in to comment.