Deploy deploys all specified manifests via kubectl apply and adds to the specified image names the corresponding tags
(ctx devspacecontext.Context, _ bool)
| 137 | |
| 138 | // Deploy deploys all specified manifests via kubectl apply and adds to the specified image names the corresponding tags |
| 139 | func (d *DeployConfig) Deploy(ctx devspacecontext.Context, _ bool) (bool, error) { |
| 140 | deployCache, _ := ctx.Config().RemoteCache().GetDeployment(d.DeploymentConfig.Name) |
| 141 | |
| 142 | // Hash the manifests |
| 143 | manifestsHash := "" |
| 144 | for _, manifest := range d.Manifests { |
| 145 | if strings.HasPrefix(manifest, "http://") || strings.HasPrefix(manifest, "https://") { |
| 146 | manifestsHash += hash.String(manifest) |
| 147 | continue |
| 148 | } |
| 149 | |
| 150 | // Check if the chart directory has changed |
| 151 | manifest = ctx.ResolvePath(manifest) |
| 152 | hash, err := hash.Directory(manifest) |
| 153 | if err != nil { |
| 154 | return false, errors.Errorf("Error hashing %s: %v", manifest, err) |
| 155 | } |
| 156 | |
| 157 | manifestsHash += hash |
| 158 | } |
| 159 | |
| 160 | // Hash the deployment config |
| 161 | configStr, err := jsonyaml.Marshal(d.DeploymentConfig) |
| 162 | if err != nil { |
| 163 | return false, errors.Wrap(err, "marshal deployment config") |
| 164 | } |
| 165 | |
| 166 | deploymentConfigHash := hash.String(string(configStr)) |
| 167 | |
| 168 | // We force the redeploy of kubectl deployments for now, because we don't know if they are already currently deployed or not, |
| 169 | // so it is better to force deploy them, which usually takes almost no time and is better than taking the risk of skipping a needed deployment |
| 170 | // forceDeploy = forceDeploy || deployCache.KubectlManifestsHash != manifestsHash || deployCache.DeploymentConfigHash != deploymentConfigHash |
| 171 | forceDeploy := true |
| 172 | |
| 173 | ctx.Log().Info("Applying manifests with kubectl...") |
| 174 | wasDeployed := false |
| 175 | kubeObjects := []remotecache.KubectlObject{} |
| 176 | |
| 177 | for _, manifest := range d.Manifests { |
| 178 | wasDeployed, kubeObjects, err = d.applyManifest(ctx, kubeObjects, forceDeploy, false, manifest) |
| 179 | if err != nil { |
| 180 | return false, err |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // Special case for inline manifests |
| 185 | if d.InlineManifest != "" { |
| 186 | // resolve the runtime variables in the yaml |
| 187 | resolvedInlineManifest, err := runtime.NewRuntimeResolver(ctx.WorkingDir(), false).FillRuntimeVariablesAsString(ctx.Context(), d.InlineManifest, ctx.Config(), ctx.Dependencies()) |
| 188 | if err != nil { |
| 189 | return false, err |
| 190 | } |
| 191 | // proceed with regular apply |
| 192 | wasDeployed, kubeObjects, err = d.applyManifest(ctx, kubeObjects, forceDeploy, true, resolvedInlineManifest) |
| 193 | if err != nil { |
| 194 | return false, err |
| 195 | } |
| 196 | } |