You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-09-16 09:26:22 +02:00
cloudFoundryDeploy- support manifest.yml as true default (#4050)
* Add new default * Revert "Add new default" This reverts commitc9c3ae2e80
. * Change config to have default * Revert "Change config to have default" This reverts commite65517457f
. * Add method * Add space to match * Add cf native test
This commit is contained in:
@@ -266,9 +266,11 @@ func handleCFNativeDeployment(config *cloudFoundryDeployOptions, command command
|
||||
return err
|
||||
}
|
||||
|
||||
manifestFile, err := getManifestFileName(config)
|
||||
|
||||
log.Entry().Infof("CF native deployment ('%s') with:", config.DeployType)
|
||||
log.Entry().Infof("cfAppName='%s'", appName)
|
||||
log.Entry().Infof("cfManifest='%s'", config.Manifest)
|
||||
log.Entry().Infof("cfManifest='%s'", manifestFile)
|
||||
log.Entry().Infof("cfManifestVariables: '%v'", config.ManifestVariables)
|
||||
log.Entry().Infof("cfManifestVariablesFiles: '%v'", config.ManifestVariablesFiles)
|
||||
log.Entry().Infof("cfdeployDockerImage: '%s'", config.DeployDockerImage)
|
||||
@@ -369,6 +371,15 @@ func getManifest(name string) (cloudfoundry.Manifest, error) {
|
||||
return cloudfoundry.ReadManifest(name)
|
||||
}
|
||||
|
||||
func getManifestFileName(config *cloudFoundryDeployOptions) (string, error) {
|
||||
|
||||
manifestFileName := config.Manifest
|
||||
if len(manifestFileName) == 0 {
|
||||
manifestFileName = "manifest.yml"
|
||||
}
|
||||
return manifestFileName, nil
|
||||
}
|
||||
|
||||
func getAppName(config *cloudFoundryDeployOptions) (string, error) {
|
||||
|
||||
if len(config.AppName) > 0 {
|
||||
@@ -377,17 +388,16 @@ func getAppName(config *cloudFoundryDeployOptions) (string, error) {
|
||||
if config.DeployType == "blue-green" {
|
||||
return "", fmt.Errorf("Blue-green plugin requires app name to be passed (see https://github.com/bluemixgaragelondon/cf-blue-green-deploy/issues/27)")
|
||||
}
|
||||
if len(config.Manifest) == 0 {
|
||||
return "", fmt.Errorf("Manifest file not provided in configuration. Cannot retrieve app name")
|
||||
}
|
||||
fileExists, err := fileUtils.FileExists(config.Manifest)
|
||||
manifestFile, err := getManifestFileName(config)
|
||||
|
||||
fileExists, err := fileUtils.FileExists(manifestFile)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "Cannot check if file '%s' exists", config.Manifest)
|
||||
return "", errors.Wrapf(err, "Cannot check if file '%s' exists", manifestFile)
|
||||
}
|
||||
if !fileExists {
|
||||
return "", fmt.Errorf("Manifest file '%s' not found. Cannot retrieve app name", config.Manifest)
|
||||
return "", fmt.Errorf("Manifest file '%s' not found. Cannot retrieve app name", manifestFile)
|
||||
}
|
||||
manifest, err := _getManifest(config.Manifest)
|
||||
manifest, err := _getManifest(manifestFile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -397,14 +407,14 @@ func getAppName(config *cloudFoundryDeployOptions) (string, error) {
|
||||
}
|
||||
|
||||
if len(apps) == 0 {
|
||||
return "", fmt.Errorf("No apps declared in manifest '%s'", config.Manifest)
|
||||
return "", fmt.Errorf("No apps declared in manifest '%s'", manifestFile)
|
||||
}
|
||||
namePropertyExists, err := manifest.ApplicationHasProperty(0, "name")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !namePropertyExists {
|
||||
return "", fmt.Errorf("No appName available in manifest '%s'", config.Manifest)
|
||||
return "", fmt.Errorf("No appName available in manifest '%s'", manifestFile)
|
||||
}
|
||||
appName, err := manifest.GetApplicationProperty(0, "name")
|
||||
if err != nil {
|
||||
@@ -413,10 +423,10 @@ func getAppName(config *cloudFoundryDeployOptions) (string, error) {
|
||||
var name string
|
||||
var ok bool
|
||||
if name, ok = appName.(string); !ok {
|
||||
return "", fmt.Errorf("appName from manifest '%s' has wrong type", config.Manifest)
|
||||
return "", fmt.Errorf("appName from manifest '%s' has wrong type", manifestFile)
|
||||
}
|
||||
if len(name) == 0 {
|
||||
return "", fmt.Errorf("appName from manifest '%s' is empty", config.Manifest)
|
||||
return "", fmt.Errorf("appName from manifest '%s' is empty", manifestFile)
|
||||
}
|
||||
return name, nil
|
||||
}
|
||||
@@ -461,47 +471,46 @@ func prepareBlueGreenCfNativeDeploy(config *cloudFoundryDeployOptions) (string,
|
||||
deployOptions = append(deployOptions, "--delete-old-apps")
|
||||
}
|
||||
|
||||
if len(config.Manifest) > 0 {
|
||||
manifestFileExists, err := fileUtils.FileExists(config.Manifest)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot check if file '%s' exists", config.Manifest)
|
||||
}
|
||||
manifestFile, err := getManifestFileName(config)
|
||||
|
||||
if !manifestFileExists {
|
||||
|
||||
log.Entry().Infof("Manifest file '%s' does not exist", config.Manifest)
|
||||
|
||||
} else {
|
||||
|
||||
manifestVariables, err := toStringInterfaceMap(toParameterMap(config.ManifestVariables))
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot prepare manifest variables: '%v'", config.ManifestVariables)
|
||||
}
|
||||
|
||||
manifestVariablesFiles, err := validateManifestVariablesFiles(config.ManifestVariablesFiles)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot validate manifest variables files '%v'", config.ManifestVariablesFiles)
|
||||
}
|
||||
|
||||
modified, err := _replaceVariables(config.Manifest, manifestVariables, manifestVariablesFiles)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrap(err, "Cannot prepare manifest file")
|
||||
}
|
||||
|
||||
if modified {
|
||||
log.Entry().Infof("Manifest file '%s' has been updated (variable substitution)", config.Manifest)
|
||||
} else {
|
||||
log.Entry().Infof("Manifest file '%s' has not been updated (no variable substitution)", config.Manifest)
|
||||
}
|
||||
|
||||
err = handleLegacyCfManifest(config.Manifest)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot handle legacy manifest '%s'", config.Manifest)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Entry().Info("No manifest file configured")
|
||||
manifestFileExists, err := fileUtils.FileExists(manifestFile)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot check if file '%s' exists", manifestFile)
|
||||
}
|
||||
|
||||
if !manifestFileExists {
|
||||
|
||||
log.Entry().Infof("Manifest file '%s' does not exist", manifestFile)
|
||||
|
||||
} else {
|
||||
|
||||
manifestVariables, err := toStringInterfaceMap(toParameterMap(config.ManifestVariables))
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot prepare manifest variables: '%v'", config.ManifestVariables)
|
||||
}
|
||||
|
||||
manifestVariablesFiles, err := validateManifestVariablesFiles(config.ManifestVariablesFiles)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot validate manifest variables files '%v'", config.ManifestVariablesFiles)
|
||||
}
|
||||
|
||||
modified, err := _replaceVariables(manifestFile, manifestVariables, manifestVariablesFiles)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrap(err, "Cannot prepare manifest file")
|
||||
}
|
||||
|
||||
if modified {
|
||||
log.Entry().Infof("Manifest file '%s' has been updated (variable substitution)", manifestFile)
|
||||
} else {
|
||||
log.Entry().Infof("Manifest file '%s' has not been updated (no variable substitution)", manifestFile)
|
||||
}
|
||||
|
||||
err = handleLegacyCfManifest(manifestFile)
|
||||
if err != nil {
|
||||
return "", []string{}, []string{}, errors.Wrapf(err, "Cannot handle legacy manifest '%s'", manifestFile)
|
||||
}
|
||||
}
|
||||
|
||||
return "blue-green-deploy", deployOptions, smokeTest, nil
|
||||
}
|
||||
|
||||
@@ -612,10 +621,7 @@ func toStringInterfaceMap(in *orderedmap.OrderedMap, err error) (map[string]inte
|
||||
|
||||
func checkAndUpdateDeployTypeForNotSupportedManifest(config *cloudFoundryDeployOptions) (string, error) {
|
||||
|
||||
manifestFile := config.Manifest
|
||||
if len(manifestFile) == 0 {
|
||||
manifestFile = "manifest.yml"
|
||||
}
|
||||
manifestFile, err := getManifestFileName(config)
|
||||
|
||||
manifestFileExists, err := fileUtils.FileExists(manifestFile)
|
||||
if err != nil {
|
||||
|
@@ -492,6 +492,41 @@ func TestCfDeployment(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("get app name from default manifest with cf native deployment", func(t *testing.T) {
|
||||
|
||||
defer cleanup()
|
||||
|
||||
config.DeployTool = "cf_native"
|
||||
config.Manifest = ""
|
||||
config.AppName = ""
|
||||
|
||||
//app name does not need to be set if it can be found in the manifest.yml
|
||||
//manifest name does not need to be set- the default manifest.yml will be used if not set
|
||||
defer prepareDefaultManifestMocking("manifest.yml", []string{"newAppName"})()
|
||||
|
||||
s := mock.ExecMockRunner{}
|
||||
|
||||
err := runCloudFoundryDeploy(&config, nil, nil, &s)
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
|
||||
t.Run("check shell calls", func(t *testing.T) {
|
||||
|
||||
withLoginAndLogout(t, func(t *testing.T) {
|
||||
|
||||
assert.Equal(t, []mock.ExecCall{
|
||||
{Exec: "cf", Params: []string{"version"}},
|
||||
{Exec: "cf", Params: []string{"plugins"}},
|
||||
{Exec: "cf", Params: []string{
|
||||
"push",
|
||||
}},
|
||||
}, s.Calls)
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("deploy cf native without app name", func(t *testing.T) {
|
||||
|
||||
defer cleanup()
|
||||
|
Reference in New Issue
Block a user