Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.PHONY: docker shell deps test pacts publish-pacts get-spec-prod get-spec-local gen-models build docs package_docker_docs

API_PKGS=apps channels releases

VERSION=$(shell git describe)
Expand Down Expand Up @@ -33,14 +31,17 @@ define LDFLAGS
"
endef

.PHONY: docker
docker:
docker build -t replicatedhq.replicated .

.PHONY: shell
shell:
docker run --rm -it \
--volume `pwd`:/go/src/github.com/replicatedhq/replicated \
replicatedhq.replicated

.PHONY: deps
deps:
docker run --rm \
--volume `pwd`:/go/src/github.com/replicatedhq/replicated \
Expand All @@ -54,9 +55,11 @@ test-env:
@if [ -z "${REPLICATED_API_ORIGIN}" ]; then echo "Missing REPLICATED_API_ORIGIN"; exit 1; fi
@if [ -z "${REPLICATED_ID_ORIGIN}" ]; then echo "Missing REPLICATED_ID_ORIGIN"; exit 1; fi

.PHONY: test
test: test-env
go test -v ./cli/test

.PHONY: pacts
pacts:
docker build -t replicated-cli-test -f hack/Dockerfile.testing .
docker run --rm --name replicated-cli-tests \
Expand All @@ -65,6 +68,7 @@ pacts:
go test -v ./pkg/...


.PHONY: publish-pacts
publish-pacts:
curl \
--silent --output /dev/null --show-error --fail \
Expand All @@ -89,12 +93,14 @@ publish-pacts:
https://replicated-pact-broker.herokuapp.com/pacts/provider/vendor-api/consumer/replicated-cli/version/$(ABBREV_VERSION)

# fetch the swagger specs from the production Vendor API
.PHONY: get-spec-prod
get-spec-prod:
mkdir -p gen/spec/
curl -o gen/spec/v1.json https://api.replicated.com/vendor/v1/spec/vendor-api.json
curl -o gen/spec/v2.json https://api.replicated.com/vendor/v2/spec/swagger.json; # TODO this is still wrong, need to find where this is hosted

# generate the swagger specs from the local replicatedcom/vendor-api repo
.PHONY: get-spec-local
get-spec-local:
mkdir -p gen/spec/
docker run --rm \
Expand All @@ -110,6 +116,7 @@ get-spec-local:
-o gen/spec/v2.json'

# generate from the specs in gen/spec, which come from either get-spec-prod or get-spec-local
.PHONY: gen-models
gen-models:
docker run --rm \
--volume `pwd`:/local \
Expand All @@ -127,11 +134,13 @@ gen-models:
-l go \
-o /local/gen/go/v2;

.PHONY: build
build:
go build \
${LDFLAGS} \
-o bin/replicated \
cli/main.go

.PHONY: docs
docs:
go run ./docs/
2 changes: 1 addition & 1 deletion cli/cmd/channel_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (r *runners) InitChannelCreate(parent *cobra.Command) {
}

func (r *runners) channelCreate(cmd *cobra.Command, args []string) error {
allChannels, err := r.api.CreateChannel(r.appID, r.appType, r.args.channelCreateName, r.args.channelCreateDescription)
allChannels, err := r.api.CreateChannel(r.appID, r.appType, r.appSlug, r.args.channelCreateName, r.args.channelCreateDescription)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd/channel_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func (r *runners) InitChannelInspect(parent *cobra.Command) {
cmd.RunE = r.channelInspect
}

func (r *runners) channelInspect(cmd *cobra.Command, args []string) error {
func (r *runners) channelInspect(_ *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("channel ID is required")
return errors.New("channel name or ID is required")
}
chanID := args[0]

appChan, _, err := r.api.GetChannel(r.appID, r.appType, chanID)
channelNameOrID := args[0]
appChan, err := r.api.GetChannelByName(r.appID, r.appType, r.appSlug, channelNameOrID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/channel_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (r *runners) InitChannelList(parent *cobra.Command) {
}

func (r *runners) channelList(cmd *cobra.Command, args []string) error {
channels, err := r.api.ListChannels(r.appID, r.appType)
channels, err := r.api.ListChannels(r.appID, r.appType, r.appSlug)
if err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions cli/cmd/customer_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

func (r *runners) InitCustomersCreateCommand(parent *cobra.Command) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "create a customer",
Long: `create a customer`,
RunE: r.createCustomer,
Use: "create",
Short: "create a customer",
Long: `create a customer`,
RunE: r.createCustomer,
SilenceUsage: true,
}
parent.AddCommand(cmd)
Expand All @@ -26,9 +26,10 @@ func (r *runners) InitCustomersCreateCommand(parent *cobra.Command) *cobra.Comma

func (r *runners) createCustomer(_ *cobra.Command, _ []string) error {

channel, err := r.api.GetChannelByName(
channel, err := r.api.GetOrCreateChannelByName(
r.appID,
r.appType,
r.appSlug,
r.args.customerCreateChannel,
"",
r.args.customerCreateEnsureChannel,
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd/customer_download_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

func (r *runners) InitCustomersDownloadLicenseCommand(parent *cobra.Command) *cobra.Command {
cmd := &cobra.Command{
Use: "download-license",
Short: "download a customer license",
Long: `download a customer license`,
RunE: r.downloadCustomerLicense,
Use: "download-license",
Short: "download a customer license",
Long: `download a customer license`,
RunE: r.downloadCustomerLicense,
SilenceUsage: true,
}
parent.AddCommand(cmd)
Expand Down
7 changes: 4 additions & 3 deletions cli/cmd/release_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"strings"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

const (
Expand Down Expand Up @@ -269,9 +269,10 @@ func (r *runners) getOrCreateChannelForPromotion(channelName string, createIfAbs

description := "" // todo: do we want a flag for the desired channel description

channel, err := r.api.GetChannelByName(
channel, err := r.api.GetOrCreateChannelByName(
r.appID,
r.appType,
r.appSlug,
channelName,
description,
createIfAbsent,
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/release_promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (r *runners) releasePromote(cmd *cobra.Command, args []string) error {

if r.appType != "ship" {
// try to turn chanID into an actual id if it was a channel name
newID, err := r.api.GetChannelByName(r.appID, r.appType, chanID, "", false)
newID, err := r.api.GetOrCreateChannelByName(r.appID, r.appType, r.appSlug, chanID, "", false)
if err != nil {
return errors.Wrapf(err, "unable to get channel ID from name")
}
Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,21 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
return err
}
runCmds.appID = app.Id
runCmds.appSlug = app.Slug
} else if appType == "ship" {
app, err := shipAPI.GetApp(appSlugOrID)
if err != nil {
return err
}
runCmds.appID = app.ID
runCmds.appSlug = app.Slug
} else if appType == "kots" {
app, err := kotsAPI.GetApp(appSlugOrID)
if err != nil {
return err
}
runCmds.appID = app.ID
runCmds.appSlug = app.Slug
}

return nil
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
// commands, which are defined as methods on this type.
type runners struct {
appID string
appSlug string
appType string
api client.Client
enterpriseClient *enterpriseclient.HTTPClient
Expand Down
21 changes: 16 additions & 5 deletions cli/print/channel_attributes.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package print

import (
"github.com/replicatedhq/replicated/pkg/types"
"text/tabwriter"
"text/template"

channels "github.com/replicatedhq/replicated/gen/go/v1"
)

var channelAttrsTmplSrc = `ID: {{ .Id }}
var channelAttrsTmplSrc = `ID: {{ .ID }}
NAME: {{ .Name }}
DESCRIPTION: {{ .Description }}
RELEASE: {{ if ge .ReleaseSequence 1 }}{{ .ReleaseSequence }}{{else}} {{end}}
VERSION: {{ .ReleaseLabel }}
VERSION: {{ .ReleaseLabel }}{{ with .InstallCommands }}
EXISTING:
{{ .Existing }}
EMBEDDED:
{{ .Embedded }}
AIRGAP:
{{ .Airgap }}
{{end}}
`

var channelAttrsTmpl = template.Must(template.New("ChannelAttributes").Parse(channelAttrsTmplSrc))

func ChannelAttrs(w *tabwriter.Writer, appChan *channels.AppChannel) error {
func ChannelAttrs(w *tabwriter.Writer, appChan *types.Channel) error {
if err := channelAttrsTmpl.Execute(w, appChan); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/print/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type Logger struct {
w io.Writer
w io.Writer
spinnerStopCh chan bool
spinnerMsg string
spinnerArgs []interface{}
Expand Down
74 changes: 74 additions & 0 deletions cli/test/kots_release_create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package test

import (
"bytes"
"github.com/replicatedhq/replicated/pkg/kotsclient"
"io/ioutil"
"os"
"path/filepath"

. "github.com/onsi/ginkgo"
"github.com/replicatedhq/replicated/cli/cmd"
"github.com/replicatedhq/replicated/pkg/platformclient"
"github.com/stretchr/testify/assert"
)

var _ = Describe("kots release create", func() {
t := GinkgoT()
req := assert.New(t) // using assert since it plays nicer with ginkgo
params, err := GetParams()
req.NoError(err)

httpClient := platformclient.NewHTTPClient(params.APIOrigin, params.APIToken)
kotsRestClient := kotsclient.VendorV3Client{HTTPClient: *httpClient}
kotsGraphqlClient := kotsclient.NewGraphQLClient(params.GraphqlOrigin, params.APIToken, params.KurlOrigin)

var app *kotsclient.KotsApp
var tmpdir string


BeforeEach(func() {
var err error
app, err = kotsRestClient.CreateKOTSApp(mustToken(8))
req.NoError(err)
tmpdir, err = ioutil.TempDir("", "replicated-cli-test")
req.NoError(err)

})

AfterEach(func() {
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
req.NoError(err)
err = os.RemoveAll(tmpdir)
req.NoError(err)
})

Context("with valid --yaml-dir in an app with no releases", func() {
It("should create release 1", func() {
var stdout bytes.Buffer
var stderr bytes.Buffer

configMap := `apiVersion: v1
kind: ConfigMap
metadata:
name: fake
data:
fake: yep it's fake
`
err := ioutil.WriteFile(filepath.Join(tmpdir, "config.yaml"), []byte(configMap), 0644)
req.NoError(err)

rootCmd := cmd.GetRootCmd()
rootCmd.SetArgs([]string{"release", "create", "--yaml-dir", tmpdir, "--app", app.Slug})
rootCmd.SetOut(&stdout)
rootCmd.SetErr(&stderr)

err = cmd.Execute(rootCmd, nil, &stdout, &stderr)
req.NoError(err)

req.Empty(stderr.String(), "Expected no stderr output")
req.NotEmpty(stdout.String(), "Expected stdout output")
req.Contains(stdout.String(), "SEQUENCE: 1")
})
})
})
Loading