Skip to content

Commit

Permalink
Merge branch 'master' of github.com:naveego/bosun
Browse files Browse the repository at this point in the history
  • Loading branch information
CERK committed Apr 9, 2019
2 parents 935e421 + c32665b commit 0aafdc3
Show file tree
Hide file tree
Showing 18 changed files with 602 additions and 79 deletions.
2 changes: 1 addition & 1 deletion bosun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ environments: []
appRefs: {}
apps:
- name: bosun
version: 0.5.2
version: 0.7.0
images: []
scripts:
- name: publish
Expand Down
140 changes: 130 additions & 10 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package cmd

import (
"fmt"
"github.com/aryann/difflib"
"github.com/cheynewallace/tabby"
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/naveego/bosun/pkg"
"github.com/naveego/bosun/pkg/bosun"
Expand Down Expand Up @@ -671,7 +673,7 @@ var appDeployCmd = addCommand(appCmd, &cobra.Command{
}
}

ctx.Log.Debugf("Created transient release to define deploy: \n%s\n", MustYaml(r))
ctx.Log.Debugf("Created transient release to define deploy: \n%s\n", r.Name)

err = r.Deploy(ctx)

Expand Down Expand Up @@ -1089,14 +1091,132 @@ var appCloneCmd = addCommand(
cmd.Flags().String(ArgAppCloneDir, "", "The directory to clone into.")
})

func getStandardObjects(args []string) (*bosun.Bosun, *bosun.EnvironmentConfig, []*bosun.AppRepo, bosun.BosunContext) {
b := mustGetBosun()
env := b.GetCurrentEnvironment()
ctx := b.NewContext()
var appDiffCmd = addCommand(
appCmd,
&cobra.Command{
Use: "diff {app} [release/]{env} [release]/{env}",
Short: "Reports the differences between the values for an app in two scenarios.",
Long: `If the release part of the scenario is not provided, a transient release will be created and used instead.`,
Example: `This command will show the differences between the values deployed
to the blue environment in release 2.4.2 and the current values for the
green environment:
diff go-between 2.4.2/blue green
`,
Args:cobra.ExactArgs(3),
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
b := mustGetBosun()
app := mustGetApp(b, []string{args[0]})

apps, err := getAppRepos(b, args)
if err != nil {
panic(err)
env1 := args[1]
env2 := args[2]

getValuesForEnv := func(scenario string) (string, error){



segs := strings.Split(scenario, "/")
var releaseName, envName string
var appRelease *bosun.AppRelease
switch len(segs) {
case 1:
envName = segs[0]
case 2:
releaseName = segs[0]
envName = segs[1]
default:
return "", errors.Errorf("invalid scenario %q", scenario)
}

env, err := b.GetEnvironment(envName)
if err != nil {
return "", errors.Wrap(err, "environment")
}
ctx := b.NewContext().WithEnv(env)

if releaseName != "" {
releaseConfig, err := b.GetReleaseConfig(releaseName)
release, err := bosun.NewRelease(ctx, releaseConfig)
if err != nil {
return "", err
}
appReleaseConfig, ok := release.AppReleaseConfigs[app.Name]
if !ok {
return "", errors.Errorf("no app named %q in release %q", app.Name, releaseName)
}
ctx = ctx.WithRelease(release)
appRelease, err = bosun.NewAppRelease(ctx, appReleaseConfig)
if err != nil {
return "", err
}
} else {
rc := &bosun.ReleaseConfig{
Name: time.Now().Format(time.RFC3339),
}
r, err := bosun.NewRelease(ctx, rc)
if err != nil {
return "", err
}
r.Transient = true
ctx = ctx.WithRelease(r)
config, err := app.GetAppReleaseConfig(ctx)
if err != nil {
return "", errors.Wrap(err, "make app release config")
}

appRelease, err = bosun.NewAppRelease(ctx, config)
if err != nil {
return "", errors.Wrap(err, "make app release")
}
}

values, err := appRelease.GetReleaseValues(ctx)
if err != nil {
return "", errors.Wrap(err, "get release values")
}

valueYaml, err := values.Values.YAML()
if err != nil {
return "", errors.Wrap(err, "get release values yaml")
}

return valueYaml, nil
}


env1yaml, err := getValuesForEnv(env1)
if err != nil {
return errors.Errorf("error for env1 %q: %s", env1, err)
}

env2yaml, err := getValuesForEnv(env2)
if err != nil {
return errors.Errorf("error for env2 %q: %s", env2, err)
}

env1lines := strings.Split(env1yaml, "\n")
env2lines := strings.Split(env2yaml, "\n")
diffs := difflib.Diff(env1lines, env2lines)

for _, diff := range diffs {
fmt.Println(renderDiff(diff))
}

return nil

},
})

func renderDiff(diff difflib.DiffRecord) string {
switch diff.Delta {
case difflib.Common:
return fmt.Sprintf(" %s", diff.Payload)
case difflib.LeftOnly:
return color.RedString("- %s", diff.Payload)
case difflib.RightOnly:
return color.GreenString("+ %s", diff.Payload)
}
return b, env, apps, ctx
}
panic(fmt.Sprintf("invalid delta %v", diff.Delta))
}
7 changes: 6 additions & 1 deletion cmd/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,9 @@ var err error

return nil
},
})
})

func init(){
rootCmd.AddCommand(metaUpgradeCmd)
}

5 changes: 3 additions & 2 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/naveego/bosun/pkg"
"github.com/naveego/bosun/pkg/bosun"
"github.com/naveego/bosun/pkg/git"
"github.com/naveego/bosun/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -405,7 +406,7 @@ func validateRelease(b *bosun.Bosun, ctx bosun.BosunContext, release *bosun.Rele
hasErrors := false

apps := release.AppReleases.GetAppsSortedByName()
p := NewProgressBar(len(apps))
p := util.NewProgressBar(len(apps))

for _, app := range apps {
if app.Excluded {
Expand Down Expand Up @@ -528,7 +529,7 @@ func processAppReleases(b *bosun.Bosun, ctx bosun.BosunContext, appReleases []*b
included = append(included, ar)
}
}
p := NewProgressBar(len(included))
p := util.NewProgressBar(len(included))

for _, appRelease := range included {
p.Add(1, appRelease.Name)
Expand Down
114 changes: 114 additions & 0 deletions cmd/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright © 2018 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"github.com/cheynewallace/tabby"
"github.com/kyokomi/emoji"
"github.com/naveego/bosun/pkg/bosun"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var toolsCmd = addCommand(rootCmd, &cobra.Command{
Use: "tools",
Short: "Commands for listing and installing tools.",

})

var toolsListCmd = addCommand(toolsCmd, &cobra.Command{
Use: "list",
Short: "Lists known tools",
Run: func(cmd *cobra.Command, args []string) {
b := mustGetBosun()
tools := b.GetTools()

byFromPath := map[string][]bosun.ToolDef{}
for _, tool := range tools {
byFromPath[tool.FromPath] = append(byFromPath[tool.FromPath], tool)
}

for fromPath, tools := range byFromPath {
fmt.Printf("Defined in %s:\n", fromPath)
t := tabby.New()
t.AddHeader("Name", "Installed", "Location", "Description")

for _, tool := range tools {

var installInfo string
var location string
executable, installErr := tool.GetExecutable()
if installErr != nil {
if tool.Installer != nil {
if _, ok := tool.GetInstaller(); ok {
installInfo = emoji.Sprint(":cloud:")
location = "(installable)"
} else {
installInfo = emoji.Sprintf(":x:")
}
}
} else {
installInfo = emoji.Sprintf(":heavy_check_mark:")
location = executable
}

t.AddLine(tool.Name, installInfo, location, tool.Description)
}
t.Print()
fmt.Println()
}
},
})

var toolsInstallCmd = addCommand(toolsCmd, &cobra.Command{
Use: "install {tool}",
Short: "Installs a tool.",
SilenceUsage:true,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
b := mustGetBosun()
tools := b.GetTools()
var tool bosun.ToolDef
var ok bool
name := args[0]
for _, tool = range tools {
if tool.Name == name {
ok = true
break
}
}
if !ok {
return errors.Errorf("no tool found with name %q", name)
}

ctx := b.NewContext()

installer, ok := tool.GetInstaller()
if !ok {
return errors.Errorf("could not get installer for %q", name)
}

err := installer.Execute(ctx)

return err
},
})


func init(){
rootCmd.AddCommand(metaUpgradeCmd)
}

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/araddon/gou v0.0.0-20190110011759-c797efecbb61 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf // indirect
github.com/aws/aws-sdk-go v1.17.11 // indirect
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 // indirect
Expand Down Expand Up @@ -114,6 +115,7 @@ require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/keybase/go-crypto v0.0.0-20181127160227-255a5089e85a // indirect
github.com/kr/binarydist v0.1.0 // indirect
github.com/kyokomi/emoji v2.1.0+incompatible
github.com/lib/pq v1.0.0 // indirect
github.com/magefile/mage v1.8.0
github.com/manifoldco/promptui v0.3.2
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZ
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a h1:pv34s756C4pEXnjgPfGYgdhg/ZdajGhyOvzx8k+23nw=
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
Expand Down Expand Up @@ -349,6 +351,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kyokomi/emoji v2.1.0+incompatible h1:+DYU2RgpI6OHG4oQkM5KlqD3Wd3UPEsX8jamTo1Mp6o=
github.com/kyokomi/emoji v2.1.0+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
Expand Down Expand Up @@ -468,6 +472,7 @@ github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqa
github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
Expand Down
Loading

0 comments on commit 0aafdc3

Please sign in to comment.