From 0e1af4bf74136ecc70fe709eb57377c952e1819c Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 21 Nov 2024 14:32:43 -0600 Subject: [PATCH 01/10] Starting point for Solutions CFN create vpc test Signed-off-by: Tanner Lewis --- .../solutionsCFNTestCover.groovy | 9 ++ test/awsRunInitBootstrap.sh | 84 +++++++++++++++++++ vars/solutionsCFNTest.groovy | 79 +++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy create mode 100755 test/awsRunInitBootstrap.sh create mode 100644 vars/solutionsCFNTest.groovy diff --git a/jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy b/jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy new file mode 100644 index 000000000..2769f1ff2 --- /dev/null +++ b/jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy @@ -0,0 +1,9 @@ +def gitBranch = params.GIT_BRANCH ?: 'sol-pipeline' +def gitUrl = params.GIT_REPO_URL ?: 'https://github.com/lewijacn/opensearch-migrations.git' + +library identifier: "migrations-lib@${gitBranch}", retriever: modernSCM( + [$class: 'GitSCMSource', + remote: "${gitUrl}"]) + +// Shared library function (location from root: vars/solutionsCFNTest.groovy) +solutionsCFNTest() diff --git a/test/awsRunInitBootstrap.sh b/test/awsRunInitBootstrap.sh new file mode 100755 index 000000000..81a5a05ec --- /dev/null +++ b/test/awsRunInitBootstrap.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +usage() { + echo "" + echo "Script to run initBootstrap.sh on Migration Assistant bootstrap box" + echo "" + echo "Usage: " + echo " ./awsRunInitBootstrap.sh [--stage]" + echo "" + echo "Options:" + echo " --stage Deployment stage name" + echo "" + exit 1 +} + +STAGE="aws-integ" +REGION="us-east-1" +while [[ $# -gt 0 ]]; do + case $1 in + --stage) + STAGE="$2" + shift # past argument + shift # past value + ;; + -h|--help) + usage + ;; + -*) + echo "Unknown option $1" + usage + ;; + *) + shift # past argument + ;; + esac +done + +execute_command_and_wait_for_result() { + local command="$1" + local instance_id="$2" + echo "Executing command: [$command] on node: $instance_id" + command_id=$(aws ssm send-command --instance-ids "$instance_id" --document-name "AWS-RunShellScript" --parameters commands="$command" --output text --query 'Command.CommandId') + sleep 10 + command_status=$(aws ssm get-command-invocation --command-id "$command_id" --instance-id "$instance_id" --output text --query 'Status') + max_attempts=25 + attempt_count=0 + while [ "$command_status" != "Success" ] && [ "$command_status" != "Failed" ] && [ "$command_status" != "TimedOut" ] + do + ((attempt_count++)) + if [[ $attempt_count -ge $max_attempts ]]; then + echo "Error: Command did not complete within the maximum retry limit." + exit 1 + fi + echo "Waiting for command to complete, current status is $command_status" + sleep 60 + command_status=$(aws ssm get-command-invocation --command-id "$command_id" --instance-id "$instance_id" --output text --query 'Status') + done + echo "Command has completed with status: $command_status, appending output" + echo "Standard Output:" + aws ssm get-command-invocation --command-id "$command_id" --instance-id "$instance_id" --output text --query 'StandardOutputContent' + echo "Standard Error:" + aws ssm get-command-invocation --command-id "$command_id" --instance-id "$instance_id" --output text --query 'StandardErrorContent' + + if [[ "$command_status" != "Success" ]]; then + echo "Error: Command [$command] was not successful, see logs above" + exit 1 + fi +} + +# Retrieve the instance ID +instance_id=$(aws ec2 describe-instances \ + --filters "Name=tag:Name,Values=bootstrap-instance-${STAGE}-${REGION}" "Name=instance-state-name,Values=running" \ + --query "Reservations[0].Instances[0].InstanceId" \ + --output text) + +if [[ -z "$instance_id" || "$instance_id" == "None" ]]; then + echo "Error: Running bootstrap EC2 instance not found" + exit 1 +fi + +init_command="/opensearch-migrations/initBootstrap.sh" +execute_command_and_wait_for_result "$init_command" "$instance_id" +verify_command="cdk --version && docker --version && java --version && python3 --version" +execute_command_and_wait_for_result "$verify_command" "$instance_id" diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy new file mode 100644 index 000000000..c396be642 --- /dev/null +++ b/vars/solutionsCFNTest.groovy @@ -0,0 +1,79 @@ +def call(Map config = [:]) { + + pipeline { + agent { label config.workerAgent ?: 'Jenkins-Default-Agent-X64-C5xlarge-Single-Host' } + + parameters { + string(name: 'GIT_REPO_URL', defaultValue: 'https://github.com/lewijacn/opensearch-migrations.git', description: 'Git repository url') + string(name: 'GIT_BRANCH', defaultValue: 'sol-pipeline', description: 'Git branch to use for repository') + string(name: 'STAGE', defaultValue: "sol-integ", description: 'Stage name for deployment environment') + } + + options { + // Acquire lock on a given deployment stage + lock(label: params.STAGE, quantity: 1, variable: 'stage') + timeout(time: 1, unit: 'HOURS') + buildDiscarder(logRotator(daysToKeepStr: '30')) + } + + stages { + stage('Checkout') { + steps { + script { + git branch: "${params.GIT_BRANCH}", url: "${params.GIT_REPO_URL}" + } + } + } + + stage('Deployment') { + steps { + timeout(time: 15, unit: 'MINUTES') { + dir('deployment/migration-assistant-solution') { + script { + sh "sudo npm install" + withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { + withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { + sh "sudo --preserve-env cdk deploy 'Migration-Assistant-Infra-Create-VPC'--require-approval never --concurrency 3" + } + } + } + } + } + } + } + + stage('Init Bootstrap') { + steps { + timeout(time: 30, unit: 'MINUTES') { + dir('test') { + script { + withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { + withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { + sh "sudo --preserve-env ./awsRunInitBootstrap.sh " + } + } + } + } + } + } + } + } + post { + always { + timeout(time: 30, unit: 'MINUTES') { + dir('test/cleanupDeployment') { + script { + sh "sudo --preserve-env pipenv install --deploy --ignore-pipfile" + def command = "pipenv run python3 cleanup_deployment.py --stage ${stage}" + withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { + withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { + sh "sudo --preserve-env ${command}" + } + } + } + } + } + } + } + } +} From cce902f0070dff799a37fe616e74390477b23668 Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 21 Nov 2024 14:50:03 -0600 Subject: [PATCH 02/10] Update spacing for command Signed-off-by: Tanner Lewis --- vars/solutionsCFNTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy index c396be642..29f11f346 100644 --- a/vars/solutionsCFNTest.groovy +++ b/vars/solutionsCFNTest.groovy @@ -33,7 +33,7 @@ def call(Map config = [:]) { sh "sudo npm install" withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { - sh "sudo --preserve-env cdk deploy 'Migration-Assistant-Infra-Create-VPC'--require-approval never --concurrency 3" + sh "sudo --preserve-env cdk deploy 'Migration-Assistant-Infra-Create-VPC' --require-approval never --concurrency 3" } } } From e43d36572b04fca0b239ffc770037122bf950ec9 Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 21 Nov 2024 15:05:28 -0600 Subject: [PATCH 03/10] Provide stage CFN parameter and use cdk destroy for cleanup Signed-off-by: Tanner Lewis --- vars/solutionsCFNTest.groovy | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy index 29f11f346..bdaf809d1 100644 --- a/vars/solutionsCFNTest.groovy +++ b/vars/solutionsCFNTest.groovy @@ -33,7 +33,7 @@ def call(Map config = [:]) { sh "sudo npm install" withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { - sh "sudo --preserve-env cdk deploy 'Migration-Assistant-Infra-Create-VPC' --require-approval never --concurrency 3" + sh "sudo --preserve-env cdk deploy 'Migration-Assistant-Infra-Create-VPC' --parameters Stage=${stage} --require-approval never --concurrency 3" } } } @@ -61,13 +61,11 @@ def call(Map config = [:]) { post { always { timeout(time: 30, unit: 'MINUTES') { - dir('test/cleanupDeployment') { + dir('deployment/migration-assistant-solution') { script { - sh "sudo --preserve-env pipenv install --deploy --ignore-pipfile" - def command = "pipenv run python3 cleanup_deployment.py --stage ${stage}" withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { - sh "sudo --preserve-env ${command}" + sh "sudo --preserve-env cdk destroy 'Migration-Assistant-Infra-Create-VPC' --force" } } } From 53bdd0c0718b592f4e9a480a3bb7e18a891aea58 Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 21 Nov 2024 15:15:47 -0600 Subject: [PATCH 04/10] Add stage to awsRunInitBootstrap.sh Signed-off-by: Tanner Lewis --- vars/solutionsCFNTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy index bdaf809d1..b27239f8b 100644 --- a/vars/solutionsCFNTest.groovy +++ b/vars/solutionsCFNTest.groovy @@ -49,7 +49,7 @@ def call(Map config = [:]) { script { withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { - sh "sudo --preserve-env ./awsRunInitBootstrap.sh " + sh "sudo --preserve-env ./awsRunInitBootstrap.sh --stage ${stage}" } } } From 8d928811aab5f89d4c52834e48f0038001fa9bbe Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 21 Nov 2024 15:30:21 -0600 Subject: [PATCH 05/10] Adjust path for init Signed-off-by: Tanner Lewis --- test/awsRunInitBootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/awsRunInitBootstrap.sh b/test/awsRunInitBootstrap.sh index 81a5a05ec..8d4f2b266 100755 --- a/test/awsRunInitBootstrap.sh +++ b/test/awsRunInitBootstrap.sh @@ -78,7 +78,7 @@ if [[ -z "$instance_id" || "$instance_id" == "None" ]]; then exit 1 fi -init_command="/opensearch-migrations/initBootstrap.sh" +init_command="cd /opensearch-migrations && ./initBootstrap.sh" execute_command_and_wait_for_result "$init_command" "$instance_id" verify_command="cdk --version && docker --version && java --version && python3 --version" execute_command_and_wait_for_result "$verify_command" "$instance_id" From 0c9a30c006c4dfeaf792163f428d30fcee9816d1 Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Thu, 21 Nov 2024 16:46:02 -0600 Subject: [PATCH 06/10] Error handling around not retrieving command id Signed-off-by: Tanner Lewis --- test/awsRunInitBootstrap.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/awsRunInitBootstrap.sh b/test/awsRunInitBootstrap.sh index 8d4f2b266..644b31acc 100755 --- a/test/awsRunInitBootstrap.sh +++ b/test/awsRunInitBootstrap.sh @@ -39,8 +39,13 @@ execute_command_and_wait_for_result() { local command="$1" local instance_id="$2" echo "Executing command: [$command] on node: $instance_id" + sleep 5 command_id=$(aws ssm send-command --instance-ids "$instance_id" --document-name "AWS-RunShellScript" --parameters commands="$command" --output text --query 'Command.CommandId') - sleep 10 + if [[ -z "$command_id" ]]; then + echo "Error: Unable to retrieve command id from triggered SSM command" + exit 1 + fi + sleep 5 command_status=$(aws ssm get-command-invocation --command-id "$command_id" --instance-id "$instance_id" --output text --query 'Status') max_attempts=25 attempt_count=0 From f7807ce45c7a7c9b0240f10a08ab57457c3c5555 Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Fri, 22 Nov 2024 15:29:54 -0600 Subject: [PATCH 07/10] Update flexibility and allow specifying stack suffix Signed-off-by: Tanner Lewis --- .../migration-assistant-solution/bin/app.ts | 15 ++++--- test/awsRunInitBootstrap.sh | 45 +++++++++++++------ vars/solutionsCFNTest.groovy | 19 +++++++- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/deployment/migration-assistant-solution/bin/app.ts b/deployment/migration-assistant-solution/bin/app.ts index 4b0425365..8efbaaf4f 100644 --- a/deployment/migration-assistant-solution/bin/app.ts +++ b/deployment/migration-assistant-solution/bin/app.ts @@ -3,7 +3,7 @@ import { App, DefaultStackSynthesizer } from 'aws-cdk-lib'; import { SolutionsInfrastructureStack } from '../lib/solutions-stack'; const getProps = () => { - const { CODE_BUCKET, SOLUTION_NAME, CODE_VERSION } = process.env; + const { CODE_BUCKET, SOLUTION_NAME, CODE_VERSION, STACK_NAME_SUFFIX } = process.env; if (typeof CODE_BUCKET !== 'string' || CODE_BUCKET.trim() === '') { console.warn(`Missing environment variable CODE_BUCKET, using a default value`); } @@ -19,6 +19,7 @@ const getProps = () => { const codeBucket = CODE_BUCKET ?? "Unknown"; const solutionVersion = CODE_VERSION ?? "Unknown"; const solutionName = SOLUTION_NAME ?? "MigrationAssistant"; + const stackNameSuffix = STACK_NAME_SUFFIX ?? undefined; const solutionId = 'SO0290'; const description = `(${solutionId}) - The AWS CloudFormation template for deployment of the ${solutionName}. Version ${solutionVersion}`; return { @@ -26,20 +27,24 @@ const getProps = () => { solutionVersion, solutionId, solutionName, - description + description, + stackNameSuffix }; }; const app = new App(); const infraProps = getProps() - -new SolutionsInfrastructureStack(app, 'Migration-Assistant-Infra-Import-VPC', { +const baseImportVPCStackName = "Migration-Assistant-Infra-Import-VPC" +const baseCreateVPCStackName = "Migration-Assistant-Infra-Create-VPC" +new SolutionsInfrastructureStack(app, baseImportVPCStackName, { synthesizer: new DefaultStackSynthesizer(), createVPC: false, + stackName: infraProps.stackNameSuffix ? `${baseImportVPCStackName}-${infraProps.stackNameSuffix}` : baseImportVPCStackName, ...infraProps }); -new SolutionsInfrastructureStack(app, 'Migration-Assistant-Infra-Create-VPC', { +new SolutionsInfrastructureStack(app, baseCreateVPCStackName, { synthesizer: new DefaultStackSynthesizer(), createVPC: true, + stackName: infraProps.stackNameSuffix ? `${baseCreateVPCStackName}-${infraProps.stackNameSuffix}` : baseCreateVPCStackName, ...infraProps }); diff --git a/test/awsRunInitBootstrap.sh b/test/awsRunInitBootstrap.sh index 644b31acc..1999f475e 100755 --- a/test/awsRunInitBootstrap.sh +++ b/test/awsRunInitBootstrap.sh @@ -5,15 +5,17 @@ usage() { echo "Script to run initBootstrap.sh on Migration Assistant bootstrap box" echo "" echo "Usage: " - echo " ./awsRunInitBootstrap.sh [--stage]" + echo " ./awsRunInitBootstrap.sh [--stage] [--workflow]--" echo "" echo "Options:" - echo " --stage Deployment stage name" + echo " --stage Deployment stage name, e.g. sol-integ" + echo " --workflow Workflow to execute, options include ALL(default)|INIT_BOOTSTRAP|VERIFY_INIT_BOOTSTRAP" echo "" exit 1 } STAGE="aws-integ" +WORKFLOW="ALL" REGION="us-east-1" while [[ $# -gt 0 ]]; do case $1 in @@ -22,6 +24,11 @@ while [[ $# -gt 0 ]]; do shift # past argument shift # past value ;; + --workflow) + WORKFLOW="$2" + shift # past argument + shift # past value + ;; -h|--help) usage ;; @@ -72,18 +79,30 @@ execute_command_and_wait_for_result() { fi } -# Retrieve the instance ID -instance_id=$(aws ec2 describe-instances \ - --filters "Name=tag:Name,Values=bootstrap-instance-${STAGE}-${REGION}" "Name=instance-state-name,Values=running" \ - --query "Reservations[0].Instances[0].InstanceId" \ - --output text) +get_instance_id() { + # Retrieve the instance ID + instance_id=$(aws ec2 describe-instances \ + --filters "Name=tag:Name,Values=bootstrap-instance-${STAGE}-${REGION}" "Name=instance-state-name,Values=running" \ + --query "Reservations[0].Instances[0].InstanceId" \ + --output text) -if [[ -z "$instance_id" || "$instance_id" == "None" ]]; then - echo "Error: Running bootstrap EC2 instance not found" - exit 1 -fi + if [[ -z "$instance_id" || "$instance_id" == "None" ]]; then + echo "Error: Running bootstrap EC2 instance not found" + exit 1 + fi + echo "$instance_id" +} +instance_id=$(get_instance_id) init_command="cd /opensearch-migrations && ./initBootstrap.sh" -execute_command_and_wait_for_result "$init_command" "$instance_id" verify_command="cdk --version && docker --version && java --version && python3 --version" -execute_command_and_wait_for_result "$verify_command" "$instance_id" +if [ "$WORKFLOW" = "ALL" ]; then + execute_command_and_wait_for_result "$init_command" "$instance_id" + execute_command_and_wait_for_result "$verify_command" "$instance_id" +elif [ "$WORKFLOW" = "INIT_BOOTSTRAP" ]; then + execute_command_and_wait_for_result "$init_command" "$instance_id" +elif [ "$WORKFLOW" = "VERIFY_INIT_BOOTSTRAP" ]; then + execute_command_and_wait_for_result "$verify_command" "$instance_id" +else + echo "Error: Unknown workflow: ${WORKFLOW} specified" +fi \ No newline at end of file diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy index b27239f8b..fe8b571c6 100644 --- a/vars/solutionsCFNTest.groovy +++ b/vars/solutionsCFNTest.groovy @@ -30,6 +30,7 @@ def call(Map config = [:]) { timeout(time: 15, unit: 'MINUTES') { dir('deployment/migration-assistant-solution') { script { + env.STACK_NAME_SUFFIX = "${stage}-us-east-1" sh "sudo npm install" withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { @@ -49,7 +50,23 @@ def call(Map config = [:]) { script { withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { - sh "sudo --preserve-env ./awsRunInitBootstrap.sh --stage ${stage}" + sh "sudo --preserve-env ./awsRunInitBootstrap.sh --stage ${stage} --workflow INIT_BOOTSTRAP" + } + } + } + } + } + } + } + + stage('Verify Bootstrap Instance') { + steps { + timeout(time: 5, unit: 'MINUTES') { + dir('test') { + script { + withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { + withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { + sh "sudo --preserve-env ./awsRunInitBootstrap.sh --stage ${stage} --workflow VERIFY_INIT_BOOTSTRAP" } } } From bb4c2dd33ce8e90863faad00f3f5489707b6295a Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Fri, 22 Nov 2024 15:55:05 -0600 Subject: [PATCH 08/10] Update wait after deployment Signed-off-by: Tanner Lewis --- test/awsRunInitBootstrap.sh | 1 - vars/solutionsCFNTest.groovy | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/awsRunInitBootstrap.sh b/test/awsRunInitBootstrap.sh index 1999f475e..c0fefe718 100755 --- a/test/awsRunInitBootstrap.sh +++ b/test/awsRunInitBootstrap.sh @@ -46,7 +46,6 @@ execute_command_and_wait_for_result() { local command="$1" local instance_id="$2" echo "Executing command: [$command] on node: $instance_id" - sleep 5 command_id=$(aws ssm send-command --instance-ids "$instance_id" --document-name "AWS-RunShellScript" --parameters commands="$command" --output text --query 'Command.CommandId') if [[ -z "$command_id" ]]; then echo "Error: Unable to retrieve command id from triggered SSM command" diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy index fe8b571c6..2001cc81d 100644 --- a/vars/solutionsCFNTest.groovy +++ b/vars/solutionsCFNTest.groovy @@ -37,6 +37,8 @@ def call(Map config = [:]) { sh "sudo --preserve-env cdk deploy 'Migration-Assistant-Infra-Create-VPC' --parameters Stage=${stage} --require-approval never --concurrency 3" } } + // Wait for instance to be ready to accept SSM commands + sh "sleep 15" } } } From 63c4c3662ee114fdfef064d61946e3434c1bf08b Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Fri, 22 Nov 2024 17:02:07 -0600 Subject: [PATCH 09/10] Update per PR comments Signed-off-by: Tanner Lewis --- deployment/migration-assistant-solution/bin/app.ts | 8 ++------ .../migration-assistant-solution/lib/solutions-stack.ts | 8 +++++--- vars/solutionsCFNTest.groovy | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/deployment/migration-assistant-solution/bin/app.ts b/deployment/migration-assistant-solution/bin/app.ts index 8efbaaf4f..de0cf883b 100644 --- a/deployment/migration-assistant-solution/bin/app.ts +++ b/deployment/migration-assistant-solution/bin/app.ts @@ -34,17 +34,13 @@ const getProps = () => { const app = new App(); const infraProps = getProps() -const baseImportVPCStackName = "Migration-Assistant-Infra-Import-VPC" -const baseCreateVPCStackName = "Migration-Assistant-Infra-Create-VPC" -new SolutionsInfrastructureStack(app, baseImportVPCStackName, { +new SolutionsInfrastructureStack(app, "Migration-Assistant-Infra-Import-VPC", { synthesizer: new DefaultStackSynthesizer(), createVPC: false, - stackName: infraProps.stackNameSuffix ? `${baseImportVPCStackName}-${infraProps.stackNameSuffix}` : baseImportVPCStackName, ...infraProps }); -new SolutionsInfrastructureStack(app, baseCreateVPCStackName, { +new SolutionsInfrastructureStack(app, "Migration-Assistant-Infra-Create-VPC", { synthesizer: new DefaultStackSynthesizer(), createVPC: true, - stackName: infraProps.stackNameSuffix ? `${baseCreateVPCStackName}-${infraProps.stackNameSuffix}` : baseCreateVPCStackName, ...infraProps }); diff --git a/deployment/migration-assistant-solution/lib/solutions-stack.ts b/deployment/migration-assistant-solution/lib/solutions-stack.ts index 71b64a7e7..257e31693 100644 --- a/deployment/migration-assistant-solution/lib/solutions-stack.ts +++ b/deployment/migration-assistant-solution/lib/solutions-stack.ts @@ -38,6 +38,7 @@ export interface SolutionsInfrastructureStackProps extends StackProps { readonly solutionVersion: string; readonly codeBucket: string; readonly createVPC: boolean; + readonly stackNameSuffix?: string; } interface ParameterLabel { @@ -113,7 +114,8 @@ function getVpcEndpointForEFS(stack: Stack): InterfaceVpcEndpointAwsService { export class SolutionsInfrastructureStack extends Stack { constructor(scope: Construct, id: string, props: SolutionsInfrastructureStackProps) { - super(scope, id, props); + const finalId = props.stackNameSuffix ? `${id}-${props.stackNameSuffix}` : id + super(scope, finalId, props); this.templateOptions.templateFormatVersion = '2010-09-09'; new CfnMapping(this, 'Solution', { mapping: { @@ -189,7 +191,7 @@ export class SolutionsInfrastructureStack extends Stack { }); const serviceEndpoints = [ - // Logs and disk usage scales based on total data transfer + // Logs and disk usage scales based on total data transfer InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS, getVpcEndpointForEFS(this), @@ -197,7 +199,7 @@ export class SolutionsInfrastructureStack extends Stack { InterfaceVpcEndpointAwsService.ECR, InterfaceVpcEndpointAwsService.ECR_DOCKER, ]; - + serviceEndpoints.forEach(service => { new InterfaceVpcEndpoint(this, `${service.shortName}VpcEndpoint`, { service, diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy index 2001cc81d..8fa61d64c 100644 --- a/vars/solutionsCFNTest.groovy +++ b/vars/solutionsCFNTest.groovy @@ -34,7 +34,7 @@ def call(Map config = [:]) { sh "sudo npm install" withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { - sh "sudo --preserve-env cdk deploy 'Migration-Assistant-Infra-Create-VPC' --parameters Stage=${stage} --require-approval never --concurrency 3" + sh "sudo --preserve-env cdk deploy Migration-Assistant-Infra-Create-VPC-${env.STACK_NAME_SUFFIX} --parameters Stage=${stage} --require-approval never --concurrency 3" } } // Wait for instance to be ready to accept SSM commands @@ -84,7 +84,7 @@ def call(Map config = [:]) { script { withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) { withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", region: "us-east-1", duration: 3600, roleSessionName: 'jenkins-session') { - sh "sudo --preserve-env cdk destroy 'Migration-Assistant-Infra-Create-VPC' --force" + sh "sudo --preserve-env cdk destroy Migration-Assistant-Infra-Create-VPC-${env.STACK_NAME_SUFFIX} --force" } } } From ac162492ca2a00794e82bbddf9deeaca2575a25e Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Fri, 22 Nov 2024 18:02:35 -0600 Subject: [PATCH 10/10] Update to main repo branch and url Signed-off-by: Tanner Lewis --- jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy | 4 ++-- vars/solutionsCFNTest.groovy | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy b/jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy index 2769f1ff2..9bbe43672 100644 --- a/jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy +++ b/jenkins/migrationIntegPipelines/solutionsCFNTestCover.groovy @@ -1,5 +1,5 @@ -def gitBranch = params.GIT_BRANCH ?: 'sol-pipeline' -def gitUrl = params.GIT_REPO_URL ?: 'https://github.com/lewijacn/opensearch-migrations.git' +def gitBranch = params.GIT_BRANCH ?: 'main' +def gitUrl = params.GIT_REPO_URL ?: 'https://github.com/opensearch-project/opensearch-migrations.git' library identifier: "migrations-lib@${gitBranch}", retriever: modernSCM( [$class: 'GitSCMSource', diff --git a/vars/solutionsCFNTest.groovy b/vars/solutionsCFNTest.groovy index 8fa61d64c..194b7ba35 100644 --- a/vars/solutionsCFNTest.groovy +++ b/vars/solutionsCFNTest.groovy @@ -4,8 +4,8 @@ def call(Map config = [:]) { agent { label config.workerAgent ?: 'Jenkins-Default-Agent-X64-C5xlarge-Single-Host' } parameters { - string(name: 'GIT_REPO_URL', defaultValue: 'https://github.com/lewijacn/opensearch-migrations.git', description: 'Git repository url') - string(name: 'GIT_BRANCH', defaultValue: 'sol-pipeline', description: 'Git branch to use for repository') + string(name: 'GIT_REPO_URL', defaultValue: 'https://github.com/opensearch-project/opensearch-migrations.git', description: 'Git repository url') + string(name: 'GIT_BRANCH', defaultValue: 'main', description: 'Git branch to use for repository') string(name: 'STAGE', defaultValue: "sol-integ", description: 'Stage name for deployment environment') }