Skip to content

Commit

Permalink
feat: update chart lock, switch to helm dependency build command
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Dec 12, 2023
1 parent ac0686c commit 180007b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func createHelmCmd() *cobra.Command {
addChildCmd(cmd, createHelmReleaseCmd())
addChildCmd(cmd, createHelmDepsValidateCmd())
addChildCmd(cmd, createHelmDepsUpdateCmd())
addChildCmd(cmd, createHelmLockUpdateCmd())
return cmd
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/helm_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type helmBuildFlags struct {
Helm helmFlags `mapstructure:",squash"`
Source string `mapstructure:"helm-source-dir"`
DepsCmd string `mapstructure:"helm-deps-cmd"`
Copy bool `mapstructure:"helm-source-copy"`
ChartFilterTemplate string `mapstructure:"helm-chart-template-list"`
ValuesFilterTemplate string `mapstructure:"helm-values-template-list"`
Expand All @@ -32,6 +33,7 @@ func createHelmBuildCmd() *cobra.Command {
}

addStringFlag(cmd, "helm-source-dir", "", "", "project helm chart source directory")
addStringFlag(cmd, "helm-deps-cmd", "", "build", "helm dependency command.")
addBoolFlag(cmd, "helm-source-copy", "", false, "copy helm source to helm directory")
addStringFlag(cmd, "helm-chart-template-list", "", "version={{ .Version }},appVersion={{ .Version }},name={{ .Name }}", `list of key value to be replaced in the Chart.yaml
Values: `+templateValues+`
Expand All @@ -56,7 +58,7 @@ func helmBuild(project *Project, flags helmBuildFlags) {
updateHelmValues(project, flags.Helm, flags.ValuesFilterTemplate)

// update helm dependencies
tools.ExecCmd("helm", "dependency", "update", helmDir(project, flags.Helm))
tools.ExecCmd("helm", "dependency", flags.DepsCmd, helmDir(project, flags.Helm))

// package helm chart
helmPackage(project, flags.Helm)
Expand Down
54 changes: 54 additions & 0 deletions cmd/helm_lock_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cmd

import (
"github.com/lorislab/samo/log"
"github.com/lorislab/samo/tools"
"github.com/spf13/cobra"
"os"
)

type helmLockUpdateFlags struct {
Helm helmFlags `mapstructure:",squash"`
KeepCharts bool `mapstructure:"helm-keep-charts"`
}

func createHelmLockUpdateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "lock-update",
Short: "Update Chart.lock file",
Long: `Update the Helm chart Chart.lock or create a new one if it doesn't exist`,
Run: func(cmd *cobra.Command, args []string) {
flags := helmLockUpdateFlags{}
readOptions(&flags)
project := loadProject(flags.Helm.Project)
helmLockUpdate(project, flags)
},
TraverseChildren: true,
}

addBoolFlag(cmd, "helm-clean-charts", "", false, "keep chart directory after Chart.lock update")
return cmd
}

func helmLockUpdate(project *Project, flags helmLockUpdateFlags) {

dir := helmDir(project, flags.Helm)

// update helm Chart.lock
tools.ExecCmd("helm", "dependency", "update", dir)

// keep chart directory?
if flags.KeepCharts {
return
}

charts := dir + "/charts"
if _, err := os.Stat(charts); !os.IsNotExist(err) {
log.Debug("Clean helm dependencies directory", log.F("dir", charts))
err := os.RemoveAll(charts)
if err != nil {
log.Panic("error delete directory", log.F("output", charts).E(err))
}
}

}

0 comments on commit 180007b

Please sign in to comment.