From 659c4c6c1cf9a8f3c133d00708538cf35937ff61 Mon Sep 17 00:00:00 2001 From: Satish Malireddi Date: Wed, 26 Dec 2018 15:01:38 -0800 Subject: [PATCH] Fixing few minor formatting issues (#703) * Added more unit tests * fixing few formatting issues --- .travis.yml | 6 +- .../Jenkinsfile | 66 ++++++++-------- .../service-configuration-data-loader.groovy | 1 - builds/jenkins-build-pack-api/Jenkinsfile | 72 ++++++++--------- builds/jenkins-build-pack-lambda/Jenkinsfile | 78 +++++++++---------- builds/jenkins-build-pack-website/Jenkinsfile | 22 +++--- .../service-onboarding-build-pack/Jenkinsfile | 12 +-- 7 files changed, 123 insertions(+), 134 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d59eb69c2..ae13063cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - "node" env: + - PLATFORM_SERVICE=core/jazz_admin - PLATFORM_SERVICE=core/jazz_asset-event-handler - PLATFORM_SERVICE=core/jazz_assets - PLATFORM_SERVICE=core/jazz_codeq @@ -9,9 +10,11 @@ env: - PLATFORM_SERVICE=core/jazz_delete-serverless-service - PLATFORM_SERVICE=core/jazz_deployments - PLATFORM_SERVICE=core/jazz_deployments-event-handler - - PLATFORM_SERVICE=core/jazz_environments + - PLATFORM_SERVICE=core/jazz_email - PLATFORM_SERVICE=core/jazz_environment-event-handler + - PLATFORM_SERVICE=core/jazz_environments - PLATFORM_SERVICE=core/jazz_events + - PLATFORM_SERVICE=core/jazz_events-handler - PLATFORM_SERVICE=core/jazz_is-service-available - PLATFORM_SERVICE=core/jazz_is-slack-channel-available - PLATFORM_SERVICE=core/jazz_login @@ -24,6 +27,7 @@ env: - PLATFORM_SERVICE=core/jazz_slack-channel - PLATFORM_SERVICE=core/jazz_slack-event-handler - PLATFORM_SERVICE=core/jazz_test-lambda + - PLATFORM_SERVICE=core/jazz_usermanagement before_script: - npm prune diff --git a/builds/delete-serverless-service-build-pack/Jenkinsfile b/builds/delete-serverless-service-build-pack/Jenkinsfile index 64f23d3581..e0a4f88e6d 100644 --- a/builds/delete-serverless-service-build-pack/Jenkinsfile +++ b/builds/delete-serverless-service-build-pack/Jenkinsfile @@ -337,10 +337,10 @@ def unDeployService(stage) { ]) { try { def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" def env_key if (stage.endsWith("-dev")) { @@ -353,7 +353,7 @@ def unDeployService(stage) { echo "Service undeployed" - resetCredentials(cloudApi) + resetCredentials(credsId) } catch (ex) { handleFailureEvent(ex.getMessage()) } @@ -499,10 +499,10 @@ def cleanUpApiGatewayResources(stage, path) { ]) { try { def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" def resource_id = null def resource_search_key @@ -548,7 +548,7 @@ def cleanUpApiGatewayResources(stage, path) { } else { echo "Resource Id does not exist in API gateway." } - resetCredentials(cloudApi) + resetCredentials(credsId) } catch (ex) { handleFailureEvent(ex.getMessage()) } @@ -610,13 +610,13 @@ def cleanUpApiDocs(stage) { ]) { try { def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" def apiRootFolder = getApiDocsFolder(stage) sh "aws s3 rm s3://${apiRootFolder}/${service_config['domain']}/${service_config['service']}/${stage} --recursive" - resetCredentials(cloudApi) + resetCredentials(credsId) } catch (ex) { handleFailureEvent(ex.getMessage()) } @@ -717,10 +717,10 @@ def unDeployWebsite(stage) { ]) { try { def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" sh "aws configure set preview.cloudfront true" def assetInfo = generateAssetInfo(stage) @@ -746,7 +746,7 @@ def unDeployWebsite(stage) { sh "aws s3 rm s3://${assetInfo['folder_name']} --recursive" } } - resetCredentials(cloudApi) + resetCredentials(credsId) } catch (ex) { handleFailureEvent(ex.getMessage()) } @@ -806,10 +806,10 @@ def cleanupS3BucketPolicy(stage, assetInfo) { ]) { try { def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" sh "aws configure set preview.cloudfront true" def bucketPolicy = sh( script: "aws s3api get-bucket-policy --bucket ${assetInfo['s3Bucket']} --output json", @@ -834,7 +834,7 @@ def cleanupS3BucketPolicy(stage, assetInfo) { def policy_json = JsonOutput.toJson(policyObjectUpdated) updateBucketPolicy(policy_json, assetInfo['s3Bucket']) } - resetCredentials(cloudApi) + resetCredentials(credsId) } catch (ex) { resetCredentials() if (ex.getMessage().indexOf("groovy.json.internal.LazyMap") < 0) { @@ -846,10 +846,10 @@ def cleanupS3BucketPolicy(stage, assetInfo) { /** Reset credentials */ -def resetCredentials(cloudApi) { +def resetCredentials(credsId) { echo "resetting AWS credentials" - sh "aws configure set profile.${cloudApi}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" + sh "aws configure set profile.${credsId}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" + sh "aws configure set profile.${credsId}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" } @NonCPS def updateBucketPolicy(policy_json, bucketName){ @@ -875,10 +875,10 @@ def cleanupCloudFrontDistribution(stage) { ]) { try { def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" sh "aws configure set preview.cloudfront true" def distributionID @@ -891,7 +891,7 @@ def cleanupCloudFrontDistribution(stage) { _Etag = generateDistributionConfigForDisable(distributionConfig) _Etag = disableCloudFrontDistribution(distributionID, _Etag, "disable-cf-distribution-config.json", stage) } - resetCredentials(cloudApi) + resetCredentials(credsId) } catch (ex) { if ((ex.getMessage()).indexOf("getDistributionId Failed") > -1) { echo "Could not find a CloudFront distribution Id for service: ${service_config['service']} and environment $stage" diff --git a/builds/jazz-build-module/service-configuration-data-loader.groovy b/builds/jazz-build-module/service-configuration-data-loader.groovy index 542b3b5762..a35f275569 100644 --- a/builds/jazz-build-module/service-configuration-data-loader.groovy +++ b/builds/jazz-build-module/service-configuration-data-loader.groovy @@ -308,7 +308,6 @@ def loadServiceConfigurationData() { sh "sed -i -- 's/{conf-region}/${region}/g' ./config/local-config.json" } - if (service_name.trim() == "jazz_is-service-available") { sh "sed -i -- 's/{inst_stack_prefix}/${config_loader.INSTANCE_PREFIX}/g' ./config/dev-config.json" sh "sed -i -- 's/{inst_stack_prefix}/${config_loader.INSTANCE_PREFIX}/g' ./config/stg-config.json" diff --git a/builds/jenkins-build-pack-api/Jenkinsfile b/builds/jenkins-build-pack-api/Jenkinsfile index 48e4f0f040..5082f97dad 100644 --- a/builds/jenkins-build-pack-api/Jenkinsfile +++ b/builds/jenkins-build-pack-api/Jenkinsfile @@ -118,7 +118,6 @@ node() { def internalAccess = config['require_internal_access'] - // @TODO: the below statement will be replaced with regular expression in very near future; def roleId = config['iamRoleARN'].substring(config['iamRoleARN'].indexOf("::") + 2, config['iamRoleARN'].lastIndexOf(":")) sonarModule.initialize(configLoader, config, branch) @@ -219,12 +218,11 @@ node() { environmentDeploymentMetadata.setEnvironmentEndpoint(endpointUrl) events.sendStartedEvent('UPDATE_ENVIRONMENT', "Environment status update event for ${env_key} deployment", environmentDeploymentMetadata.generateEnvironmentMap("deployment_started", environment_logical_id, null), environment_logical_id) withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: configLoader.AWS_CREDENTIAL_ID, secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) { - echo "AWS Configure ......." def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" // Generate serverless yml file with domain added in function name echo "Generate deployment env with domain for ${env_key}" @@ -237,7 +235,7 @@ node() { def envBucketKey = "${env_key}${configLoader.JAZZ.S3_BUCKET_NAME_SUFFIX}" sh "serverless deploy --stage ${environment_logical_id} -v --bucket ${configLoader.AWS.S3[envBucketKey]}" - def lambdaARN = getLambdaARN(stackName, cloudApi); + def lambdaARN = getLambdaARN(stackName, credsId); events.sendCompletedEvent('CREATE_ASSET', null, utilModule.generateAssetMap("aws", lambdaARN, "lambda", config), environment_logical_id); if (fileExists('swagger/swagger.json')) { @@ -257,9 +255,9 @@ node() { sh "cat swagger/swagger.json " echo "Deploying to API Gateway environment.." - sh "aws apigateway put-rest-api --rest-api-id ${aws_api_id} --mode merge --parameters basepath=prepend --body 'file://swagger/swagger.json'" + " --profile ${cloudApi}" - sh "aws apigateway create-deployment --rest-api-id ${aws_api_id} --stage-name ${current_environment} --profile ${cloudApi}" - sh "aws apigateway tag-resource --resource-arn arn:aws:apigateway:${configLoader.AWS.REGION}::/restapis/${aws_api_id}/stages/${current_environment} --tags Application=Jazz,JazzInstance=${configLoader.INSTANCE_PREFIX} --profile ${cloudApi}" + sh "aws apigateway put-rest-api --rest-api-id ${aws_api_id} --mode merge --parameters basepath=prepend --body 'file://swagger/swagger.json'" + " --profile ${credsId}" + sh "aws apigateway create-deployment --rest-api-id ${aws_api_id} --stage-name ${current_environment} --profile ${credsId}" + sh "aws apigateway tag-resource --resource-arn arn:aws:apigateway:${configLoader.AWS.REGION}::/restapis/${aws_api_id}/stages/${current_environment} --tags Application=Jazz,JazzInstance=${configLoader.INSTANCE_PREFIX} --profile ${credsId}" if("${configLoader.JAZZ.API_DETAILED_MONITORING}" == "true") { sh "aws apigateway update-stage --rest-api-id ${aws_api_id} --stage-name ${current_environment} --patch-operations op=replace,path=/*/*/metrics/enabled,value=true --region ${configLoader.AWS.REGION}" @@ -292,13 +290,12 @@ node() { events.sendCompletedEvent('CREATE_ASSET', null, utilModule.generateAssetMap("aws", swaggerDocUrl, "swagger_url", config), environment_logical_id); def svc_status = "Your service endpoint for ${current_environment} environment: ${endpointUrl} \n\nView and test your API here: ${configLoader.JAZZ.SWAGGER.EDITOR_URL}${swaggerDocUrl}" - send_status_email(config, 'COMPLETED', svc_status) + send_status_email(config, 'COMPLETED', svc_status) } - resetCredentials(cloudApi) + resetCredentials(credsId) if (domain && domain == "jazz") { serviceConfigdata.setLogStreamPermission(config) - } } } catch (ex) { @@ -321,11 +318,11 @@ node() { }//dir ends here } -def getLambdaARN(String stackName, cloudApi) { +def getLambdaARN(stackName, credsId) { def ARN = ""; try { def cloudformation_resources = ""; - cloudformation_resources = sh(returnStdout: true, script: "aws cloudformation describe-stacks --output json --stack-name ${stackName} --profile ${cloudApi}") + cloudformation_resources = sh(returnStdout: true, script: "aws cloudformation describe-stacks --output json --stack-name ${stackName} --profile ${credsId}") def parsedObject = parseJson(cloudformation_resources); def outputs = parsedObject.Stacks[0].Outputs; @@ -494,17 +491,16 @@ def buildLambda(String runtime, String repo_name) { . venv/bin/activate pip install pytest """ + } else if (runtime.indexOf("go") > -1 ) { + // Installing dependencies using dep ensure + // golang build scripts + withEnv(["GOPATH=${env.WORKSPACE}"]) { + sh "mkdir -p $GOPATH/src" + sh "rsync -a --exclude='.*' $GOPATH/" + repo_name + " $GOPATH/src" + sh "cd $GOPATH/src/" + repo_name + " && dep ensure" + sh "env GOOS=linux GOARCH=amd64 go build -o main $GOPATH/src/" + repo_name + "/main.go" + } } - else if (runtime.indexOf("go") > -1 ){ - //Installing dependencies using dep ensure - //golang build scripts - withEnv(["GOPATH=${env.WORKSPACE}"]) { - sh "mkdir -p $GOPATH/src" - sh "rsync -a --exclude='.*' $GOPATH/"+ repo_name+" $GOPATH/src" - sh "cd $GOPATH/src/"+ repo_name+" && dep ensure" - sh "env GOOS=linux GOARCH=amd64 go build -o main $GOPATH/src/"+ repo_name+"/main.go" - } - } } @@ -563,10 +559,10 @@ def setLambdaExecutionRole(role) { /** Reset credentials */ -def resetCredentials(cloudApi) { - echo "resetting AWS credentials" - sh "aws configure set profile.${cloudApi}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" +def resetCredentials(credsId) { + echo "resetting AWS credentials" + sh "aws configure set profile.${credsId}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" + sh "aws configure set profile.${credsId}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" } /** @@ -667,15 +663,10 @@ def loadServerlessConfig(config) { } else if (config['providerRuntime'].indexOf("python") > -1) { sh "cp _config/serverless-python.yml ./serverless.yml" } else if (config['providerRuntime'].indexOf("go") > -1) { - sh "cp _config/serverless-go.yml ./serverless.yml" - } - - if ((config['service'] == 'cloud-logs-streamer' || config['service'] == 'logs') && config['domain'] == 'jazz') { - //addVpcDetails() + sh "cp _config/serverless-go.yml ./serverless.yml" } - - removeEventResources() - + + removeEventResources() echoServerlessFile() } @@ -846,16 +837,15 @@ def send_status_email(config, build_status, email_content) { /** Run validation based on runtime */ def runValidation(String runtime) { + echo "running validations for $runtime" if (runtime.indexOf("nodejs") > -1) { - echo "running validations for $runtime" sh "jshint *.js" } else if (runtime.indexOf("java") > -1) { - echo "running validations for $runtime" sh "java -cp ${configLoader.CODE_QUALITY.SONAR.CHECKSTYLE_LIB} com.puppycrawl.tools.checkstyle.Main -c sun_checks.xml src" } else if (runtime.indexOf("python") > -1) { - echo "running validations for $runtime" + // placeholder for adding runtime specific validations } else if (runtime.indexOf("go") > -1) { - echo "running validations for $runtime" + // placeholder for adding runtime specific validations } } diff --git a/builds/jenkins-build-pack-lambda/Jenkinsfile b/builds/jenkins-build-pack-lambda/Jenkinsfile index 9e646d24e7..41b7eb57fe 100644 --- a/builds/jenkins-build-pack-lambda/Jenkinsfile +++ b/builds/jenkins-build-pack-lambda/Jenkinsfile @@ -129,15 +129,14 @@ node() { def internalAccess = config['require_internal_access'] domain = config['domain'] - // @TODO: the below statement will be replaced with regular expression in very near future; def roleId = config['iamRoleARN'].substring(config['iamRoleARN'].indexOf("::") + 2, config['iamRoleARN'].lastIndexOf(":")) sonarModule.initialize(configLoader, config, branch) stackName = "${configLoader.INSTANCE_PREFIX}-${config['domain']}-${config['service']}-${environment_logical_id}" if (isScheduleEnabled || isEc2EventEnabled || isS3EventEnabled || isStreamEnabled || isDynamoDbEnabled || isSQSEventEnabled){ - isEventSchdld = true - } + isEventSchdld = true + } def requestId = utilModule.generateRequestId() if (requestId != null) { @@ -224,10 +223,10 @@ node() { try { // initialize aws credentials def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + def credsId = "jazz-${randomString}"; + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" loadServerlessConfig(runtime, isEventSchdld, isScheduleEnabled, isEc2EventEnabled, isS3EventEnabled, isSQSEventEnabled, isStreamEnabled, isDynamoDbEnabled) @@ -281,7 +280,7 @@ node() { } } - def function_arn = getLambdaARN(stackName, cloudApi); + def function_arn = getLambdaARN(stackName, credsId); lambdaARN = function_arn.split(":(?!.*:.*)")[0] events.sendCompletedEvent('CREATE_ASSET', null, utilModule.generateAssetMap("aws", lambdaARN, "lambda", config), environment_logical_id); @@ -299,7 +298,7 @@ node() { } // reset Credentials - resetCredentials(cloudApi) + resetCredentials(credsId) if (domain != "jazz") { createSubscriptionFilters(stackName, configLoader.AWS.REGION, roleId); } @@ -474,8 +473,8 @@ def addEvents(def isScheduleEnabled, def isEc2EventEnabled, def isS3EventEnabled } def removeEventResources(){ - sh "sed -i -- '/#Start:resources/,/#End:resources/d' ./serverless.yml" - sh "sed -i -- '/#Start:events/,/#End:events/d' ./serverless.yml" + sh "sed -i -- '/#Start:resources/,/#End:resources/d' ./serverless.yml" + sh "sed -i -- '/#Start:events/,/#End:events/d' ./serverless.yml" } @@ -525,8 +524,8 @@ def LoadConfiguration() { /** Build project based on runtime */ def buildLambda(String runtime, String repo_name) { - echo "installing dependencies for $runtime" - if (runtime.indexOf("nodejs") > -1) { + echo "installing dependencies for $runtime" + if (runtime.indexOf("nodejs") > -1) { sh "npm install --save" } else if (runtime.indexOf("java") > -1) { sh "mvn package" @@ -543,24 +542,24 @@ def buildLambda(String runtime, String repo_name) { . venv/bin/activate pip install pytest """ - } else if (runtime.indexOf("go") > -1 ){ - //Installing dependencies using dep ensure - //golang build scripts + } else if (runtime.indexOf("go") > -1 ) { + // Installing dependencies using dep ensure + // golang build scripts withEnv(["GOPATH=${env.WORKSPACE}"]) { sh "mkdir -p $GOPATH/src" - sh "rsync -a --exclude='.*' $GOPATH/"+ repo_name+" $GOPATH/src" + sh "rsync -a --exclude='.*' $GOPATH/" + repo_name + " $GOPATH/src" sh "cd $GOPATH/src/"+ repo_name+" && dep ensure" - sh "env GOOS=linux GOARCH=amd64 go build -o main $GOPATH/src/"+ repo_name+"/main.go" + sh "env GOOS=linux GOARCH=amd64 go build -o main $GOPATH/src/" + repo_name + "/main.go" } } } /** Reset credentials */ -def resetCredentials(cloudApi) { +def resetCredentials(credsId) { echo "resetting AWS credentials" - sh "aws configure set profile.${cloudApi}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" + sh "aws configure set profile.${credsId}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" + sh "aws configure set profile.${credsId}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" } /** Validate basic configurations in the deployment yaml file and error if any keys are @@ -579,7 +578,7 @@ def validateDeploymentConfigurations(def prop) { if (_runtime == "") { error "Wrong configuration. Value for Key 'providerRuntime' is missing in the configuration" } else { - def validRuntimes = ["nodejs4.3", "nodejs6.10", "nodejs8.10", "python2.7", "java8", "go1.x"] //@TODO. Add more runtime supports. + def validRuntimes = ["nodejs4.3", "nodejs6.10", "nodejs8.10", "python2.7", "java8", "go1.x"] def flag = false for (int i = 0; i < validRuntimes.size(); i++) { @@ -670,8 +669,8 @@ def loadServerlessConfig(String runtime, def isEventSchdld, def isScheduleEnable } if(!isEventSchdld) { - removeEventResources() - } + removeEventResources() + } echoServerlessFile() } @@ -699,10 +698,11 @@ def echoServiceInfo(String env) { echo "===============================================================================================" echo svc_response echo "===============================================================================================" - + return svc_response + } catch (Exception ex) { - echo " Error while getting service info : " + ex.getMessage() + echo "Error while getting service info: " + ex.getMessage() } } @@ -764,10 +764,10 @@ def writeServerlessFile(config, env) { if (config['event_source_s3']) { def event_source_s3 = lambdaEvents.getEventResourceNamePerEnvironment(config['event_source_s3'], env, "-") - def event_s3_arn = "arn:aws:s3:::${event_source_s3}" - sh "sed -i -- 's/{event_source_s3}/${event_source_s3}/g' ./serverless.yml" - sh "sed -i -- 's/{event_action_s3}/${config['event_action_s3']}/g' ./serverless.yml" - sh "sed -i -- 's|{event_s3_arn}|${event_s3_arn}|g' policyFile.yml" + def event_s3_arn = "arn:aws:s3:::${event_source_s3}" + sh "sed -i -- 's/{event_source_s3}/${event_source_s3}/g' ./serverless.yml" + sh "sed -i -- 's/{event_action_s3}/${config['event_action_s3']}/g' ./serverless.yml" + sh "sed -i -- 's|{event_s3_arn}|${event_s3_arn}|g' policyFile.yml" sh "sed -i -- 's/resourcesDisabled/resources/g' ./serverless.yml" } @@ -929,13 +929,12 @@ def getEventsArn(config, env) { } } -def getLambdaARN(String stackName, cloudApi) { - def ARN = ""; - - try { - def cloudformation_resources = ""; - cloudformation_resources = sh(returnStdout: true, script: "aws cloudformation describe-stacks --output json --stack-name ${stackName} --profile ${cloudApi}") - +def getLambdaARN(stackName, credsId) { + def ARN = ""; + + try { + def cloudformation_resources = ""; + cloudformation_resources = sh(returnStdout: true, script: "aws cloudformation describe-stacks --output json --stack-name ${stackName} --profile ${credsId}") def parsedObject = parseJson(cloudformation_resources); def outputs = parsedObject.Stacks[0].Outputs; @@ -954,18 +953,15 @@ def getLambdaARN(String stackName, cloudApi) { /** Run validation based on runtime */ def runValidation(String runtime) { + echo "running validations for $runtime" if (runtime.indexOf("nodejs") > -1) { - echo "running validations for $runtime" sh "jshint *.js" } else if (runtime.indexOf("java") > -1) { - echo "running validations for $runtime" sh "java -cp ${configLoader.CODE_QUALITY.SONAR.CHECKSTYLE_LIB} com.puppycrawl.tools.checkstyle.Main -c sun_checks.xml src" } else if (runtime.indexOf("python") > -1) { // placeholder for adding runtime specific validations - echo "running validations for $runtime" } else if (runtime.indexOf("go") > -1) { // placeholder for adding runtime specific validations - echo "running validations for $runtime" } } diff --git a/builds/jenkins-build-pack-website/Jenkinsfile b/builds/jenkins-build-pack-website/Jenkinsfile index e6d1e1a388..a6740946b6 100644 --- a/builds/jenkins-build-pack-website/Jenkinsfile +++ b/builds/jenkins-build-pack-website/Jenkinsfile @@ -141,21 +141,19 @@ node() { stage("Deployment to ${current_environment} Env"){ def randomString = utilModule.generateRequestId(); - def cloudApi = "jazz-${randomString}"; + def credsId = "jazz-${randomString}"; events.sendStartedEvent("DEPLOY_TO_AWS", 'deployment starts', context_map) events.sendStartedEvent('UPDATE_ENVIRONMENT', "Environment status update event for ${environment} deployment", environmentDeploymentMetadata.generateEnvironmentMap("deployment_started", environment, null), environment) withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: configLoader.AWS_CREDENTIAL_ID, secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) { - echo "AWS Configure ......." - sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}" - sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" + sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}" + sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID" + sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY" sh "aws configure set preview.cloudfront true" - - generateAssetInfo() + + generateAssetInfo() def assetInfo = "S3 Folder - /${asset_info}" echo "Checking if the website already exists.." - if (configLoader.JAZZ.BUCKET_PER_SERVICE == "true") { def isBucketExists = checkIfBucketExists(s3Bucket) if (!isBucketExists) { @@ -222,7 +220,7 @@ node() { } // reset Credentials - resetCredentials(cloudApi) + resetCredentials(credsId) } } } @@ -623,10 +621,10 @@ def LoadConfiguration() { /** Reset credentials */ -def resetCredentials(cloudApi) { +def resetCredentials(credsId) { echo "resetting AWS credentials" - sh "aws configure set profile.${cloudApi}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" - sh "aws configure set profile.${cloudApi}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" + sh "aws configure set profile.${credsId}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX" + sh "aws configure set profile.${credsId}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX" } /** diff --git a/builds/service-onboarding-build-pack/Jenkinsfile b/builds/service-onboarding-build-pack/Jenkinsfile index 314cff3144..71c7fd278c 100644 --- a/builds/service-onboarding-build-pack/Jenkinsfile +++ b/builds/service-onboarding-build-pack/Jenkinsfile @@ -138,11 +138,13 @@ node { checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: repo_credential_id, url: scmModule.getTemplateUrl(service_template)]]]) def config = LoadConfiguration() def roleARN - if (service_config['domain'] && service_config['domain'] == "jazz") { - roleARN = configLoader.AWS.PLATFORMSERVICES_ROLEID - } else { - roleARN = configLoader.AWS.USERSERVICES_ROLEID - } + + if (service_config['domain'] && service_config['domain'] == "jazz") { + roleARN = configLoader.AWS.PLATFORMSERVICES_ROLEID + } else { + roleARN = configLoader.AWS.USERSERVICES_ROLEID + } + def serviceMetadataJson = [ "securityGroupIds": configLoader.AWS.SECURITY_GROUP_IDS, "subnetIds": configLoader.AWS.SUBNET_IDS,