Skip to content

Commit

Permalink
feat(release): automatically detect what belongs to release
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveRuble committed Sep 23, 2021
1 parent 02faaa9 commit 178781d
Show file tree
Hide file tree
Showing 45 changed files with 873 additions and 1,027 deletions.
4 changes: 1 addition & 3 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ var appAcceptActualCmd = &cobra.Command{
log.WithError(getErr).Error("Could not get actual state.")
return getErr
}
b.SetDesiredState(app.Name, appDeploy.ActualState)

log.Debug("Updated.")
}

Expand Down Expand Up @@ -615,8 +615,6 @@ var appDeleteCmd = &cobra.Command{
app.DesiredState.Status = workspace.StatusDeleted
}

b.SetDesiredState(app.Name, app.DesiredState)

app.DesiredState.Routing = workspace.RoutingNA
err := app.Reconcile(ctx)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/app_toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ var appToggleCmd = &cobra.Command{
appServiceChanged = true
}

b.SetDesiredState(app.Name, app.DesiredState)
}

if appServiceChanged {
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (

func deployAppFlags(cmd *cobra.Command) {
cmd.Flags().StringSlice(argDeployPlanProviderPriority, []string{bosun.WorkspaceProviderName, bosun.SlotUnstable, bosun.SlotStable}, "Providers in priority order to use to deploy apps (current, stable, unstable, or workspace).")
cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "DeployedApps to include.")
cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "AppDeploymentProgress to include.")
cmd.Flags().Bool(argDeployPlanAll, false, "Deploy all apps.")
cmd.Flags().String(argDeployAppTag, "", "Tag to use when deploying the app or apps.")
cmd.Flags().Bool(argDeployPlanIgnoreDeps, true, "Don't validate dependencies.")
Expand Down
69 changes: 68 additions & 1 deletion cmd/deploy_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ var _ = addCommand(deployCmd, &cobra.Command{
},
}, func(cmd *cobra.Command) {
cmd.Flags().Bool(argDeployExecuteSkipValidate, false, "Skip validation")
cmd.Flags().Bool(argDeployExecuteDiffOnly, false, "Display the diffs for the deploy, but do not actually execute.")
cmd.Flags().Bool(argDeployExecuteValuesOnly, false, "Display the values which would be used for the deploy, but do not actually execute.")
})

Expand All @@ -103,3 +102,71 @@ const (
argDeployExecuteDiffOnly = "diff-only"
argDeployExecuteValuesOnly = "values-only"
)

var _ = addCommand(deployCmd, &cobra.Command{
Use: "diff {path | {release|stable|unstable}} [apps...]",
Args: cobra.MinimumNArgs(1),
Short: "Shows a diff of what would change if a deployment were executed",
Long: "If apps are provided, only those apps will be deployed.",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
b := MustGetBosun()

check(b.ConfirmEnvironment())

p, err := b.GetCurrentPlatform()
if err != nil {
return err
}
req := bosun.ExecuteDeploymentPlanRequest{
Validate: false,
DiffOnly: true,
DumpValuesOnly: viper.GetBool(argDeployExecuteValuesOnly),
UseSudo: viper.GetBool(ArgGlobalSudo),
}

pathOrSlot := args[0]
switch pathOrSlot{
case "release","current", bosun.SlotStable, bosun.SlotUnstable:
r, folder, resolveReleaseErr := getReleaseAndPlanFolderName(b, pathOrSlot)
if resolveReleaseErr != nil {
return resolveReleaseErr
}
expectedReleaseHash, hashErr := r.GetChangeDetectionHash()

if hashErr != nil {
return hashErr
}

req.Path = filepath.Join(p.GetDeploymentsDir(), fmt.Sprintf("%s/plan.yaml", folder))
req.Plan, resolveReleaseErr = bosun.LoadDeploymentPlanFromFile(req.Path)
if resolveReleaseErr != nil {
return resolveReleaseErr
}

if req.Plan.BasedOnHash != "" && req.Plan.BasedOnHash != expectedReleaseHash {
confirmed := cli.RequestConfirmFromUser("The release has changed since this plan was created, are you sure you want to continue?")
if !confirmed {

color.Yellow("You may want to run `bosun deploy plan release` to update the deployment plan\n")
return nil
}
}
break
default:
req.Path = pathOrSlot
}

if len(args) > 1 {
req.IncludeApps = args[1:]
}

executor := bosun.NewDeploymentPlanExecutor(b, p)

_, err = executor.Execute(req)

return err
},
}, func(cmd *cobra.Command) {
cmd.Flags().Bool(argDeployExecuteValuesOnly, false, "Display the values which would be used for the deploy.")
})
24 changes: 13 additions & 11 deletions cmd/deploy_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var deployPlanCmd = addCommand(deployCmd, &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

if len(args) > 0 {
if len(args) > 0 {
switch args[0] {
case "release", "current", "stable", "unstable":
return releaseDeployPlan(args[0])
Expand Down Expand Up @@ -104,8 +104,8 @@ var deployPlanCmd = addCommand(deployCmd, &cobra.Command{
return err
}

if update && previousPlan != nil {
plan.EnvironmentDeployProgress = previousPlan.EnvironmentDeployProgress
if previousPlan != nil {
plan.AppDeploymentProgress = previousPlan.AppDeploymentProgress
}

err = plan.Save()
Expand Down Expand Up @@ -137,7 +137,7 @@ var deployPlanCmd = addCommand(deployCmd, &cobra.Command{
}, func(cmd *cobra.Command) {
cmd.Flags().String(argDeployPlanPath, "", "Dir where plan should be stored.")
cmd.Flags().String(argDeployPlanProviderPriority, "", "Provider to use to deploy apps (current, stable, unstable, or workspace).")
cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "DeployedApps to include.")
cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "AppDeploymentProgress to include.")
cmd.Flags().Bool(argDeployPlanAll, false, "Deploy all apps which target the current environment.")
cmd.Flags().Bool(argDeployPlanIgnoreDeps, false, "Don't validate dependencies.")
cmd.Flags().Bool(argDeployPlanAutoDeps, false, "Automatically include dependencies.")
Expand All @@ -164,7 +164,7 @@ var deployReleasePlanCmd = addCommand(deployPlanCmd, &cobra.Command{
},
})

func getReleaseAndPlanFolderName(b *bosun.Bosun, slotDescription string) (*bosun.ReleaseManifest, string, error){
func getReleaseAndPlanFolderName(b *bosun.Bosun, slotDescription string) (*bosun.ReleaseManifest, string, error) {

p, err := b.GetCurrentPlatform()
if err != nil {
Expand Down Expand Up @@ -207,7 +207,6 @@ func releaseDeployPlan(slotDescription string) error {
return err
}


r, folder, err := getReleaseAndPlanFolderName(b, slotDescription)
if err != nil {
return err
Expand All @@ -229,10 +228,13 @@ func releaseDeployPlan(slotDescription string) error {
BasedOnHash: basedOnHash,
}

for name, included := range r.UpgradedApps {
if included {
req.Apps = append(req.Apps, name)
}
pinnedApps, err := r.GetAppManifestsPinnedToRelease()
if err != nil {
return err
}

for name := range pinnedApps {
req.Apps = append(req.Apps, name)
}

planCreator := bosun.NewDeploymentPlanCreator(b, p)
Expand All @@ -244,7 +246,7 @@ func releaseDeployPlan(slotDescription string) error {
}

if previousPlan != nil {
plan.EnvironmentDeployProgress = previousPlan.EnvironmentDeployProgress
plan.AppDeploymentProgress = previousPlan.AppDeploymentProgress
}

err = plan.Save()
Expand Down
71 changes: 71 additions & 0 deletions cmd/deploy_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package cmd

import (
"fmt"
"github.com/naveego/bosun/pkg/bosun"
"github.com/spf13/cobra"
"path/filepath"
)

var deployShowCmd = addCommand(deployCmd, &cobra.Command{
Use: "show [release|stable|unstable]",
Short: "Show the deployment plan and its progress.",
Args: cobra.RangeArgs(0, 1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

b := MustGetBosun()

plan, err := getPlan(b, args)
if err != nil {
return err
}

stack, err := b.GetCurrentStack()
if err != nil {
return err
}

stackBrn := stack.Brn


report := plan.GetDeploymentProgressReportForStack(stackBrn)

return renderOutput(report)
},
})

func getPlan(b *bosun.Bosun, args []string)(*bosun.DeploymentPlan, error) {

p, err := b.GetCurrentPlatform()
if err != nil {
return nil, err
}

pathOrSlot := "release"

if len(args) > 0 {
pathOrSlot = args[0]
}

var path string
var plan *bosun.DeploymentPlan

switch pathOrSlot {
case "release", "current", bosun.SlotStable, bosun.SlotUnstable:
_, folder, resolveReleaseErr := getReleaseAndPlanFolderName(b, pathOrSlot)
if resolveReleaseErr != nil {
return nil, resolveReleaseErr
}

path = filepath.Join(p.GetDeploymentsDir(), fmt.Sprintf("%s/plan.yaml", folder))
break
default:
path = pathOrSlot
break
}

plan, err = bosun.LoadDeploymentPlanFromFile(path)

return plan, err
}
2 changes: 1 addition & 1 deletion cmd/git_accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var gitAcceptPullRequestCmd = addCommand(gitCmd, &cobra.Command{
return nil
},
}, func(cmd *cobra.Command) {
cmd.Flags().StringSlice(ArgGitAcceptPRAppVersion, []string{}, "DeployedApps to apply version bump to.")
cmd.Flags().StringSlice(ArgGitAcceptPRAppVersion, []string{}, "AppDeploymentProgress to apply version bump to.")
})

const ArgGitAcceptPRAppVersion = "app"
Expand Down
3 changes: 2 additions & 1 deletion cmd/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"github.com/fatih/color"
"github.com/naveego/bosun/pkg"
"github.com/naveego/bosun/pkg/core"
"github.com/naveego/bosun/pkg/templating"
"github.com/naveego/bosun/pkg/vault"
"github.com/spf13/cobra"
Expand All @@ -39,7 +40,7 @@ var graylogConfigureCmd = &cobra.Command{
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {

vaultClient, err := vault.NewVaultLowlevelClient("", "")
vaultClient, err := vault.NewVaultLowlevelClient("", "", core.Log)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ var _ = addCommand(platformCmd, &cobra.Command{
}
} else if viper.GetBool(argPlatformUpdateDeployed) {
args = []string{}
for name := range release.UpgradedApps {

pinnedApps, pinnedAppsErr := release.GetAppManifestsPinnedToRelease()
if pinnedAppsErr != nil {
return pinnedAppsErr
}

for name := range pinnedApps {
args = append(args, name)
}
}
Expand Down
Loading

0 comments on commit 178781d

Please sign in to comment.