Deploy deploys the given deployment with helm
(ctx devspacecontext.Context, forceDeploy bool)
| 28 | |
| 29 | // Deploy deploys the given deployment with helm |
| 30 | func (d *DeployConfig) Deploy(ctx devspacecontext.Context, forceDeploy bool) (bool, error) { |
| 31 | var releaseName string |
| 32 | if d.DeploymentConfig.Helm.ReleaseName != "" { |
| 33 | releaseName = d.DeploymentConfig.Helm.ReleaseName |
| 34 | } else { |
| 35 | releaseName = d.DeploymentConfig.Name |
| 36 | } |
| 37 | |
| 38 | var ( |
| 39 | chartPath = d.DeploymentConfig.Helm.Chart.Name |
| 40 | hash = "" |
| 41 | ) |
| 42 | |
| 43 | releaseNamespace := ctx.KubeClient().Namespace() |
| 44 | if d.DeploymentConfig.Namespace != "" { |
| 45 | releaseNamespace = d.DeploymentConfig.Namespace |
| 46 | } |
| 47 | |
| 48 | if d.DeploymentConfig.Helm.Chart.Source != nil { |
| 49 | downloadPath, err := d.Helm.DownloadChart(ctx, d.DeploymentConfig.Helm) |
| 50 | if err != nil { |
| 51 | return false, errors.Wrap(err, "download chart") |
| 52 | } |
| 53 | chartPath = downloadPath |
| 54 | } |
| 55 | |
| 56 | // Hash the chart directory if there is any |
| 57 | _, err := os.Stat(ctx.ResolvePath(chartPath)) |
| 58 | if err == nil { |
| 59 | chartPath = ctx.ResolvePath(chartPath) |
| 60 | |
| 61 | // Check if the chart directory has changed |
| 62 | hash, err = hashpkg.DirectoryExcludes(chartPath, []string{ |
| 63 | ".git/", |
| 64 | ".devspace/", |
| 65 | }, true) |
| 66 | if err != nil { |
| 67 | return false, errors.Errorf("Error hashing chart directory: %v", err) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // Ensure deployment config is there |
| 72 | deployCache, _ := ctx.Config().RemoteCache().GetDeployment(releaseName) |
| 73 | |
| 74 | // Check values files for changes |
| 75 | helmOverridesHash := "" |
| 76 | if d.DeploymentConfig.Helm.ValuesFiles != nil { |
| 77 | for _, override := range d.DeploymentConfig.Helm.ValuesFiles { |
| 78 | override = ctx.ResolvePath(override) |
| 79 | |
| 80 | hash, err := hashpkg.Directory(override) |
| 81 | if err != nil { |
| 82 | return false, errors.Errorf("Error stating override file %s: %v", override, err) |
| 83 | } |
| 84 | |
| 85 | helmOverridesHash += hash |
| 86 | } |
| 87 | } |