Skip to content

Commit

Permalink
fix: default to use a temporary directory for applying helm charts (j…
Browse files Browse the repository at this point in the history
…enkins-x#4384)

* fix: default to use a temporary directory for applying helm charts

fixes jenkins-x#4383

Signed-off-by: James Strachan <james.strachan@gmail.com>

* fix: lets use https for spring boot model

Signed-off-by: James Strachan <james.strachan@gmail.com>
  • Loading branch information
jstrachan authored and David Conde committed Apr 7, 2020
1 parent fd37261 commit b60ba73
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion pkg/cmd/step/helm/step_helm_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type StepHelmApplyOptions struct {
Force bool
DisableHelmVersion bool
Vault bool
UseTempDir bool
}

var (
Expand Down Expand Up @@ -81,6 +82,7 @@ func NewCmdStepHelmApply(commonOpts *opts.CommonOptions) *cobra.Command {
cmd.Flags().BoolVarP(&options.Force, "force", "f", true, "Whether to to pass '--force' to helm to help deal with upgrading if a previous promote failed")
cmd.Flags().BoolVar(&options.DisableHelmVersion, "no-helm-version", false, "Don't set Chart version before applying")
cmd.Flags().BoolVarP(&options.Vault, "vault", "", false, "Helm secrets are stored in vault")
cmd.Flags().BoolVarP(&options.UseTempDir, "use-temp-dir", "", true, "Whether to build and apply the helm chart from a temporary directory - to avoid updating the local values.yaml file from the generated file as part of the apply which could get accidentally checked into git")

return cmd
}
Expand Down Expand Up @@ -155,8 +157,35 @@ func (o *StepHelmApplyOptions) Run() error {
}
}
}

info := util.ColorInfo

path, err := filepath.Abs(dir)
if err != nil {
return errors.Wrapf(err, "could not find absolute path of dir %s", dir)
}
dir = path

if o.UseTempDir {
rootTmpDir, err := ioutil.TempDir("", "jx-helm-apply-")
if err != nil {
return errors.Wrapf(err, "failed to create a temporary directory to apply the helm chart")
}
defer os.RemoveAll(rootTmpDir)

// lets use the same child dir name as the original as helm is quite particular about the name of the directory it runs from
_, name := filepath.Split(dir)
if name == "" {
return fmt.Errorf("could not find the relative name of the directory %s", dir)
}
tmpDir := filepath.Join(rootTmpDir, name)
log.Logger().Infof("Copying the helm source directory %s to a temporary location for building and applying %s\n", info(dir), info(tmpDir))

err = util.CopyDir(dir, tmpDir, false)
if err != nil {
return errors.Wrapf(err, "failed to copy helm dir %s to temporary dir %s", dir, tmpDir)
}
dir = tmpDir
}
log.Logger().Infof("Applying helm chart at %s as release name %s to namespace %s", info(dir), info(releaseName), info(ns))

o.Helm().SetCWD(dir)
Expand Down
2 changes: 1 addition & 1 deletion pkg/spring/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
OptionDependencyKind = "kind"
OptionType = "type"

startSpringURL = "http://start.spring.io"
startSpringURL = "https://start.spring.io"
)

var (
Expand Down

0 comments on commit b60ba73

Please sign in to comment.