Skip to content

Commit

Permalink
Merge pull request #29 from replicatedhq/ship-releaser
Browse files Browse the repository at this point in the history
Import code for generating ship releases
  • Loading branch information
dexhorthy authored Feb 22, 2019
2 parents e3b75f1 + 8cac8f0 commit 4fd5772
Show file tree
Hide file tree
Showing 7,685 changed files with 2,003,932 additions and 2 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
16 changes: 16 additions & 0 deletions cli/cmd/shiprelease.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cmd

import (
"github.com/spf13/cobra"
)

// releaseCmd represents the release command
var shipReleaseCommand = &cobra.Command{
Use: "shiprelease",
Short: "Manage ship releases",
Long: `The shiprelease command allows vendors to create, display, modify, and archive their Ship releases.`,
}

func init() {
RootCmd.AddCommand(shipReleaseCommand)
}
153 changes: 153 additions & 0 deletions cli/cmd/shiprelease_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package cmd

import (
"context"
"fmt"
"io/ioutil"
"net/url"

"github.com/go-kit/kit/log"
"github.com/mitchellh/cli"
"github.com/pkg/errors"
"github.com/replicatedhq/ship/pkg/e2e"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"strings"
)

func init() {
shipReleaseCommand.AddCommand(Cmd())
}

func Cmd() *cobra.Command {
vip := viper.New()

var stdoutLogger log.Logger
stdoutLogger = log.NewLogfmtLogger(os.Stdout)
stdoutLogger = log.With(stdoutLogger, "ts", log.DefaultTimestampUTC)

cmd := &cobra.Command{
Use: "create",
Short: "API client for creating ship releases",
Long: `
`,
RunE: func(cmd *cobra.Command, args []string) error {

releaser := &Releaser{
viper: vip,
logger: stdoutLogger,
ui: &cli.ColoredUi{
OutputColor: cli.UiColorNone,
ErrorColor: cli.UiColorRed,
WarnColor: cli.UiColorYellow,
InfoColor: cli.UiColorGreen,
Ui: &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
},
},
}

err := releaser.Release(context.Background())

if err != nil {
return errors.Wrap(err, "promote release")
}

return nil
},
}

cmd.Flags().String("vendor-token", "", "Token to use to communicate with https://g.replicated.com")
cmd.Flags().String("graphql-api-address", "https://g.replicated.com/graphql", "upstream g. address")
cmd.Flags().String("spec-file", "", "spec file to promote")
cmd.Flags().String("channel-id", "", "channel id to promote")
cmd.Flags().String("semver", "", "semver of the release")
cmd.Flags().String("release-notes", "", "release notes")
cmd.Flags().String("log-level", "off", "log level")

vip.BindPFlags(cmd.Flags())
vip.BindPFlags(cmd.PersistentFlags())
vip.AutomaticEnv()
vip.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
return cmd
}

type Releaser struct {
viper *viper.Viper
logger log.Logger
ui cli.Ui
}

func (r *Releaser) getParams() (token, specContents, semver, channelID, gqlAddr string, err error) {
token = r.viper.GetString("vendor-token")
if token == "" {
err = errors.New("param vendor-token is required")
return
}

specFile := r.viper.GetString("spec-file")
if specFile == "" {
err = errors.New("param spec-file is required")
return
}

specBytes, err := ioutil.ReadFile(specFile)
if err != nil {
err = errors.Wrapf(err, "read file %s", specFile)
return
}
specContents = string(specBytes)

semver = r.viper.GetString("semver")
if semver == "" {
err = errors.New("param semver is required")
return
}

channelID = r.viper.GetString("channel-id")
if channelID == "" {
err = errors.New("param channel-id is required")
return
}

gqlAddr = r.viper.GetString("graphql-api-address")
return
}

func (r *Releaser) Release(
ctx context.Context,
) error {

token, specContents, semver, channelID, gqlAddr, err := r.getParams()
if err != nil {
return errors.Wrap(err, "load params")
}

gqlServer, err := url.Parse(gqlAddr)
if err != nil {
return errors.Wrapf(err, "parse graphql-api-address URL \"%s\"", gqlAddr)
}
client := &e2e.GraphQLClient{
GQLServer: gqlServer,
Token: token,
Logger: r.logger,
}

data, err := client.PromoteRelease(
string(specContents),
channelID,
semver,
r.viper.GetString("release-notes"),
)

r.ui.Info(fmt.Sprintf("received data %+v", data))

if err != nil {
return errors.Wrapf(err, "promote release")
}

return nil
}
41 changes: 39 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import:
subpackages:
- doc
- package: github.com/spf13/pflag
- package: github.com/replicatedhq/ship
- package: github.com/go-kit/kit/log
- package: github.com/mitchellh/cli
- package: github.com/onsi/ginkgo
version: ~1.3.1
- package: github.com/onsi/gomega
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/armon/go-radix/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/armon/go-radix/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/armon/go-radix/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/armon/go-radix/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/armon/go-radix/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4fd5772

Please sign in to comment.