in mpdev/internal/resources/deployment_manager.go [204:258]
func (dm *DeploymentManagerTemplate) Apply(registry Registry, dryRun bool) error {
dmRef := registry.GetResource(dm.DeploymentManagerRef)
if dmRef == nil {
return fmt.Errorf("autogen template not found %+v", dm.DeploymentManagerRef)
}
dmTemplate, ok := dmRef.(*DeploymentManagerAutogenTemplate)
if !ok {
return fmt.Errorf("referenced autogen template is not correct type %+v", dm.DeploymentManagerRef)
}
if dm.ZipFilePath == "" {
return errors.New("ZipFilePath cannot be empty for DM template")
}
if dryRun {
return nil
}
var localZipPath string
isGCSUpload := strings.HasPrefix(dm.ZipFilePath, "gs://")
if isGCSUpload {
localZipPath = filepath.Join(dmTemplate.outDir, "dm_template.zip")
} else {
var err error
localZipPath, err = registry.ResolveFilePath(dm, dm.ZipFilePath)
if err != nil {
return errors.Wrapf(err, "failed to resolve path to zipFile: %s", dm.ZipFilePath)
}
}
executor := registry.GetExecutor()
err := util.ZipDirectory(executor, localZipPath, dmTemplate.outDir)
if err != nil {
return errors.Wrapf(err, "failed to zip DM template to %s", localZipPath)
}
fmt.Printf("DM template zipped to %s\n", localZipPath)
if isGCSUpload {
cmd := executor.Command("gsutil", "cp", localZipPath, dm.ZipFilePath)
cmd.SetStdout(os.Stdout)
cmd.SetStderr(os.Stderr)
fmt.Printf("Uploading DM template to GCS from:%s to:%s\n", localZipPath, dm.ZipFilePath)
err = cmd.Run()
if err != nil {
return errors.Wrap(err, "failed to copy DM template to GCS")
}
fmt.Printf("Uploaded DM template to GCS path: %s\n", dm.ZipFilePath)
}
return nil
}