Skip to content

Commit 4fd5772

Browse files
authored
Merge pull request #29 from replicatedhq/ship-releaser
Import code for generating ship releases
2 parents e3b75f1 + 8cac8f0 commit 4fd5772

File tree

7,685 files changed

+2003932
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,685 files changed

+2003932
-2
lines changed

cli/cmd/shiprelease.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
// releaseCmd represents the release command
8+
var shipReleaseCommand = &cobra.Command{
9+
Use: "shiprelease",
10+
Short: "Manage ship releases",
11+
Long: `The shiprelease command allows vendors to create, display, modify, and archive their Ship releases.`,
12+
}
13+
14+
func init() {
15+
RootCmd.AddCommand(shipReleaseCommand)
16+
}

cli/cmd/shiprelease_create.go

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"io/ioutil"
7+
"net/url"
8+
9+
"github.com/go-kit/kit/log"
10+
"github.com/mitchellh/cli"
11+
"github.com/pkg/errors"
12+
"github.com/replicatedhq/ship/pkg/e2e"
13+
"github.com/spf13/cobra"
14+
"github.com/spf13/viper"
15+
"os"
16+
"strings"
17+
)
18+
19+
func init() {
20+
shipReleaseCommand.AddCommand(Cmd())
21+
}
22+
23+
func Cmd() *cobra.Command {
24+
vip := viper.New()
25+
26+
var stdoutLogger log.Logger
27+
stdoutLogger = log.NewLogfmtLogger(os.Stdout)
28+
stdoutLogger = log.With(stdoutLogger, "ts", log.DefaultTimestampUTC)
29+
30+
cmd := &cobra.Command{
31+
Use: "create",
32+
Short: "API client for creating ship releases",
33+
Long: `
34+
`,
35+
RunE: func(cmd *cobra.Command, args []string) error {
36+
37+
releaser := &Releaser{
38+
viper: vip,
39+
logger: stdoutLogger,
40+
ui: &cli.ColoredUi{
41+
OutputColor: cli.UiColorNone,
42+
ErrorColor: cli.UiColorRed,
43+
WarnColor: cli.UiColorYellow,
44+
InfoColor: cli.UiColorGreen,
45+
Ui: &cli.BasicUi{
46+
Reader: os.Stdin,
47+
Writer: os.Stdout,
48+
ErrorWriter: os.Stderr,
49+
},
50+
},
51+
}
52+
53+
err := releaser.Release(context.Background())
54+
55+
if err != nil {
56+
return errors.Wrap(err, "promote release")
57+
}
58+
59+
return nil
60+
},
61+
}
62+
63+
cmd.Flags().String("vendor-token", "", "Token to use to communicate with https://g.replicated.com")
64+
cmd.Flags().String("graphql-api-address", "https://g.replicated.com/graphql", "upstream g. address")
65+
cmd.Flags().String("spec-file", "", "spec file to promote")
66+
cmd.Flags().String("channel-id", "", "channel id to promote")
67+
cmd.Flags().String("semver", "", "semver of the release")
68+
cmd.Flags().String("release-notes", "", "release notes")
69+
cmd.Flags().String("log-level", "off", "log level")
70+
71+
vip.BindPFlags(cmd.Flags())
72+
vip.BindPFlags(cmd.PersistentFlags())
73+
vip.AutomaticEnv()
74+
vip.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
75+
return cmd
76+
}
77+
78+
type Releaser struct {
79+
viper *viper.Viper
80+
logger log.Logger
81+
ui cli.Ui
82+
}
83+
84+
func (r *Releaser) getParams() (token, specContents, semver, channelID, gqlAddr string, err error) {
85+
token = r.viper.GetString("vendor-token")
86+
if token == "" {
87+
err = errors.New("param vendor-token is required")
88+
return
89+
}
90+
91+
specFile := r.viper.GetString("spec-file")
92+
if specFile == "" {
93+
err = errors.New("param spec-file is required")
94+
return
95+
}
96+
97+
specBytes, err := ioutil.ReadFile(specFile)
98+
if err != nil {
99+
err = errors.Wrapf(err, "read file %s", specFile)
100+
return
101+
}
102+
specContents = string(specBytes)
103+
104+
semver = r.viper.GetString("semver")
105+
if semver == "" {
106+
err = errors.New("param semver is required")
107+
return
108+
}
109+
110+
channelID = r.viper.GetString("channel-id")
111+
if channelID == "" {
112+
err = errors.New("param channel-id is required")
113+
return
114+
}
115+
116+
gqlAddr = r.viper.GetString("graphql-api-address")
117+
return
118+
}
119+
120+
func (r *Releaser) Release(
121+
ctx context.Context,
122+
) error {
123+
124+
token, specContents, semver, channelID, gqlAddr, err := r.getParams()
125+
if err != nil {
126+
return errors.Wrap(err, "load params")
127+
}
128+
129+
gqlServer, err := url.Parse(gqlAddr)
130+
if err != nil {
131+
return errors.Wrapf(err, "parse graphql-api-address URL \"%s\"", gqlAddr)
132+
}
133+
client := &e2e.GraphQLClient{
134+
GQLServer: gqlServer,
135+
Token: token,
136+
Logger: r.logger,
137+
}
138+
139+
data, err := client.PromoteRelease(
140+
string(specContents),
141+
channelID,
142+
semver,
143+
r.viper.GetString("release-notes"),
144+
)
145+
146+
r.ui.Info(fmt.Sprintf("received data %+v", data))
147+
148+
if err != nil {
149+
return errors.Wrapf(err, "promote release")
150+
}
151+
152+
return nil
153+
}

glide.lock

+39-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import:
44
subpackages:
55
- doc
66
- package: github.com/spf13/pflag
7+
- package: github.com/replicatedhq/ship
8+
- package: github.com/go-kit/kit/log
9+
- package: github.com/mitchellh/cli
710
- package: github.com/onsi/ginkgo
811
version: ~1.3.1
912
- package: github.com/onsi/gomega

vendor/github.com/armon/go-radix/.gitignore

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/armon/go-radix/.travis.yml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/armon/go-radix/LICENSE

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/armon/go-radix/README.md

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/armon/go-radix/go.mod

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)