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

Merge latest main changes into feature/serverless #1253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.17.x, 1.18.x ]
go-version: [ 1.18.x, 1.19.x ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.18.x
go-version: 1.19.x

- name: Restore cache
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Step 1: Build
FROM golang:1.18-alpine AS build
FROM golang:1.19-alpine AS build

ARG GOARCH=amd64
ENV OUT_D /out
Expand Down
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
62 changes: 62 additions & 0 deletions commands/apps_charm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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()
}

type appListItem struct {
*godo.App
}

func (i appListItem) Title() string {
return i.GetSpec().GetName()
}

func (i appListItem) Description() string {
desc := []string{}

if i.LiveDomain != "" {
desc = append(desc, i.LiveDomain)
}
if !i.LastDeploymentActiveAt.IsZero() {
desc = append(desc, template.String(`last deployed {{timeAgo .}}`, i.LastDeploymentActiveAt))
} else {
desc = append(desc, template.String(`created {{timeAgo .}}`, i.CreatedAt))
}

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

func (i appListItem) FilterValue() string {
return i.GetSpec().GetName()
}
Loading