From 250653a3172d60d6b5f65317c7c584fbeece99be Mon Sep 17 00:00:00 2001 From: Chris Pates Date: Thu, 24 Nov 2022 18:14:22 +0000 Subject: [PATCH] cross pipeline int refining cross pipeline integration --- cicd/{buildapp => build/build}/buildspec.yml | 0 .../build}/goreleaser.patch | 0 cicd/{ => build}/gitvars/buildspec.yml | 0 .../gitvars/codebuild-git-wrapper.sh | 0 cicd/{ => build}/package/buildspec.yml | 0 cicd/{ => build}/package/release.patch | 0 cicd/{ => build}/package/staging.patch | 0 cicd/cloudformation/production.yaml | 30 +++++++++------- cicd/{ => old}/approverelease/buildspec.yml | 0 .../build => old/buildapp}/buildspec.yml | 0 .../build => old/buildapp}/goreleaser.patch | 0 cicd/{ => old}/deploy/buildspec.yml | 0 cicd/{ => old}/deploy/stack.yml | 0 .../build => old}/gitvars/buildspec.yml | 0 .../gitvars/codebuild-git-wrapper.sh | 0 .../build => old}/package/buildspec.yml | 0 .../build => old}/package/release.patch | 0 .../build => old}/package/staging.patch | 0 .../staging => old/publish}/buildspec.yml | 0 .../public => old/release}/buildspec.yml | 0 .../cli => old/test-container}/buildspec.yml | 0 cicd/{ => old}/test-lambda/buildspec.yml | 0 .../release/approve/buildspec.yml | 0 cicd/release/{ => public}/buildspec.yml | 0 cicd/{publish => staging/build}/buildspec.yml | 36 ++++++++++++------- cicd/staging/{deploy => build}/params.json | 2 +- cicd/staging/{deploy => build}/stack.yml | 0 cicd/staging/deploy/buildspec.yml | 36 ------------------- .../testing => staging}/testing/buildspec.yml | 34 ++++++++++-------- .../smoke/cli}/buildspec.yml | 0 .../smoke/lambda/buildspec.yml | 0 31 files changed, 63 insertions(+), 75 deletions(-) rename cicd/{buildapp => build/build}/buildspec.yml (100%) rename cicd/{buildapp => build/build}/goreleaser.patch (100%) rename cicd/{ => build}/gitvars/buildspec.yml (100%) rename cicd/{ => build}/gitvars/codebuild-git-wrapper.sh (100%) rename cicd/{ => build}/package/buildspec.yml (100%) rename cicd/{ => build}/package/release.patch (100%) rename cicd/{ => build}/package/staging.patch (100%) rename cicd/{ => old}/approverelease/buildspec.yml (100%) rename cicd/{production/build/build => old/buildapp}/buildspec.yml (100%) rename cicd/{production/build/build => old/buildapp}/goreleaser.patch (100%) rename cicd/{ => old}/deploy/buildspec.yml (100%) rename cicd/{ => old}/deploy/stack.yml (100%) rename cicd/{production/build => old}/gitvars/buildspec.yml (100%) rename cicd/{production/build => old}/gitvars/codebuild-git-wrapper.sh (100%) rename cicd/{production/build => old}/package/buildspec.yml (100%) rename cicd/{production/build => old}/package/release.patch (100%) rename cicd/{production/build => old}/package/staging.patch (100%) rename cicd/{production/testing/staging => old/publish}/buildspec.yml (100%) rename cicd/{production/release/public => old/release}/buildspec.yml (100%) rename cicd/{staging/smoke/cli => old/test-container}/buildspec.yml (100%) rename cicd/{ => old}/test-lambda/buildspec.yml (100%) rename cicd/{production => }/release/approve/buildspec.yml (100%) rename cicd/release/{ => public}/buildspec.yml (100%) rename cicd/{publish => staging/build}/buildspec.yml (67%) rename cicd/staging/{deploy => build}/params.json (89%) rename cicd/staging/{deploy => build}/stack.yml (100%) delete mode 100644 cicd/staging/deploy/buildspec.yml rename cicd/{production/testing => staging}/testing/buildspec.yml (52%) rename cicd/{test-container => tests/smoke/cli}/buildspec.yml (100%) rename cicd/{staging => tests}/smoke/lambda/buildspec.yml (100%) diff --git a/cicd/buildapp/buildspec.yml b/cicd/build/build/buildspec.yml similarity index 100% rename from cicd/buildapp/buildspec.yml rename to cicd/build/build/buildspec.yml diff --git a/cicd/buildapp/goreleaser.patch b/cicd/build/build/goreleaser.patch similarity index 100% rename from cicd/buildapp/goreleaser.patch rename to cicd/build/build/goreleaser.patch diff --git a/cicd/gitvars/buildspec.yml b/cicd/build/gitvars/buildspec.yml similarity index 100% rename from cicd/gitvars/buildspec.yml rename to cicd/build/gitvars/buildspec.yml diff --git a/cicd/gitvars/codebuild-git-wrapper.sh b/cicd/build/gitvars/codebuild-git-wrapper.sh similarity index 100% rename from cicd/gitvars/codebuild-git-wrapper.sh rename to cicd/build/gitvars/codebuild-git-wrapper.sh diff --git a/cicd/package/buildspec.yml b/cicd/build/package/buildspec.yml similarity index 100% rename from cicd/package/buildspec.yml rename to cicd/build/package/buildspec.yml diff --git a/cicd/package/release.patch b/cicd/build/package/release.patch similarity index 100% rename from cicd/package/release.patch rename to cicd/build/package/release.patch diff --git a/cicd/package/staging.patch b/cicd/build/package/staging.patch similarity index 100% rename from cicd/package/staging.patch rename to cicd/build/package/staging.patch diff --git a/cicd/cloudformation/production.yaml b/cicd/cloudformation/production.yaml index c4090340..5bc31e51 100644 --- a/cicd/cloudformation/production.yaml +++ b/cicd/cloudformation/production.yaml @@ -13,6 +13,10 @@ Parameters: Description: AWS Account where staging build is automatically deployed and tested Type: String AllowedPattern: '[0-9]+' + TargetBucket: + Description: Where we upload the tests.zip + Type: String + AllowedPattern: '[A-Za-z0-9:/-]+' CodeStarConnection: Description: Resource ARN for the CodeStar Connection to use Type: String @@ -22,9 +26,9 @@ Metadata: AWS::CloudFormation::Interface: ParameterGroups: - Label: - default: End 2 End Test environment + default: The bucket name in the End 2 End Test environment Parameters: - - StagingAccount + - TargetBucket - Label: default: Connection id for the CodeStar Connection to use Parameters: @@ -35,6 +39,8 @@ Metadata: default: "123456789012" CodeStarConnection: default: "arn:aws:codestar-connections:::connection/abcd1234-ab12-ab12--ab12-abcdef123456" + TargetBucket: + default: "staging-stagingbucket-10swep1lrlrau" Resources: @@ -261,10 +267,11 @@ Resources: PrimarySource: Source EnvironmentVariables: '[{"name":"GitTag","value":"#{Git.Tag}","type":"PLAINTEXT"},{"name":"GitVersionHash","value":"#{Git.CommitHash}","type":"PLAINTEXT"}]' OutputArtifacts: - - Name: Staging + - Name: Tests InputArtifacts: - Name: Source - Name: Packaged + - Name: Built - Name: Testing ActionTypeId: Category: Build @@ -275,7 +282,6 @@ Resources: Configuration: ProjectName: !Ref CodeBuildTesting PrimarySource: Source - EnvironmentVariables: '[{"name":"AppArn","value":"#{RC.AppArn}","type":"PLAINTEXT"},{"name":"AppVersion","value":"#{RC.AppVersion}","type":"PLAINTEXT"}]' InputArtifacts: - Name: Source - Name: Release @@ -316,7 +322,7 @@ Resources: ServiceRole: !Ref CodeBuildAppRole Source: Type: CODEPIPELINE - BuildSpec: "cicd/gitvars/buildspec.yml" + BuildSpec: "cicd/build/gitvars/buildspec.yml" Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 @@ -390,7 +396,7 @@ Resources: ServiceRole: !Ref CodeBuildPackageRole Source: Type: CODEPIPELINE - BuildSpec: "cicd/production/build/package/buildspec.yml" + BuildSpec: "cicd/build/package/buildspec.yml" Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 @@ -425,7 +431,7 @@ Resources: ServiceRole: !Ref CodeBuildPublishRole Source: Type: CODEPIPELINE - BuildSpec: "cicd/production/testing/staging/buildspec.yml" + BuildSpec: "cicd/staging/buildspec.yml" Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 @@ -460,14 +466,14 @@ Resources: ServiceRole: !Ref CodeBuildTestRole Source: Type: CODEPIPELINE - BuildSpec: "cicd/production/testing/testing/buildspec.yml" + BuildSpec: "cicd/staging/testing/buildspec.yml" Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 Type: LINUX_CONTAINER EnvironmentVariables: - - Name: ARTIFACT_S3_BUCKET - Value: !Sub ${ArtifactBucket} + - Name: TARGETS3BUCKET + Value: !Sub ${TargetBucket} Artifacts: Name: SSOSync-Build Type: CODEPIPELINE @@ -491,7 +497,7 @@ Resources: ServiceRole: !Ref CodeBuildPublishRole Source: Type: CODEPIPELINE - BuildSpec: "cicd/production/release/approve/buildspec.yml" + BuildSpec: "cicd/release/approve/buildspec.yml" Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 @@ -522,7 +528,7 @@ Resources: ServiceRole: !Ref CodeBuildPublishRole Source: Type: CODEPIPELINE - BuildSpec: "cicd/production/release/release/buildspec.yml" + BuildSpec: "cicd/release/release/buildspec.yml" Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 diff --git a/cicd/approverelease/buildspec.yml b/cicd/old/approverelease/buildspec.yml similarity index 100% rename from cicd/approverelease/buildspec.yml rename to cicd/old/approverelease/buildspec.yml diff --git a/cicd/production/build/build/buildspec.yml b/cicd/old/buildapp/buildspec.yml similarity index 100% rename from cicd/production/build/build/buildspec.yml rename to cicd/old/buildapp/buildspec.yml diff --git a/cicd/production/build/build/goreleaser.patch b/cicd/old/buildapp/goreleaser.patch similarity index 100% rename from cicd/production/build/build/goreleaser.patch rename to cicd/old/buildapp/goreleaser.patch diff --git a/cicd/deploy/buildspec.yml b/cicd/old/deploy/buildspec.yml similarity index 100% rename from cicd/deploy/buildspec.yml rename to cicd/old/deploy/buildspec.yml diff --git a/cicd/deploy/stack.yml b/cicd/old/deploy/stack.yml similarity index 100% rename from cicd/deploy/stack.yml rename to cicd/old/deploy/stack.yml diff --git a/cicd/production/build/gitvars/buildspec.yml b/cicd/old/gitvars/buildspec.yml similarity index 100% rename from cicd/production/build/gitvars/buildspec.yml rename to cicd/old/gitvars/buildspec.yml diff --git a/cicd/production/build/gitvars/codebuild-git-wrapper.sh b/cicd/old/gitvars/codebuild-git-wrapper.sh similarity index 100% rename from cicd/production/build/gitvars/codebuild-git-wrapper.sh rename to cicd/old/gitvars/codebuild-git-wrapper.sh diff --git a/cicd/production/build/package/buildspec.yml b/cicd/old/package/buildspec.yml similarity index 100% rename from cicd/production/build/package/buildspec.yml rename to cicd/old/package/buildspec.yml diff --git a/cicd/production/build/package/release.patch b/cicd/old/package/release.patch similarity index 100% rename from cicd/production/build/package/release.patch rename to cicd/old/package/release.patch diff --git a/cicd/production/build/package/staging.patch b/cicd/old/package/staging.patch similarity index 100% rename from cicd/production/build/package/staging.patch rename to cicd/old/package/staging.patch diff --git a/cicd/production/testing/staging/buildspec.yml b/cicd/old/publish/buildspec.yml similarity index 100% rename from cicd/production/testing/staging/buildspec.yml rename to cicd/old/publish/buildspec.yml diff --git a/cicd/production/release/public/buildspec.yml b/cicd/old/release/buildspec.yml similarity index 100% rename from cicd/production/release/public/buildspec.yml rename to cicd/old/release/buildspec.yml diff --git a/cicd/staging/smoke/cli/buildspec.yml b/cicd/old/test-container/buildspec.yml similarity index 100% rename from cicd/staging/smoke/cli/buildspec.yml rename to cicd/old/test-container/buildspec.yml diff --git a/cicd/test-lambda/buildspec.yml b/cicd/old/test-lambda/buildspec.yml similarity index 100% rename from cicd/test-lambda/buildspec.yml rename to cicd/old/test-lambda/buildspec.yml diff --git a/cicd/production/release/approve/buildspec.yml b/cicd/release/approve/buildspec.yml similarity index 100% rename from cicd/production/release/approve/buildspec.yml rename to cicd/release/approve/buildspec.yml diff --git a/cicd/release/buildspec.yml b/cicd/release/public/buildspec.yml similarity index 100% rename from cicd/release/buildspec.yml rename to cicd/release/public/buildspec.yml diff --git a/cicd/publish/buildspec.yml b/cicd/staging/build/buildspec.yml similarity index 67% rename from cicd/publish/buildspec.yml rename to cicd/staging/build/buildspec.yml index 92e5d80d..85f0361a 100644 --- a/cicd/publish/buildspec.yml +++ b/cicd/staging/build/buildspec.yml @@ -3,19 +3,8 @@ version: 0.2 env: variables: ShareWith: "NOT-SHARED" - exported-variables: - - AppArn - - AppVersion phases: - install: - commands: - # Update sam to latest version - - wget -q https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip - - unzip -q aws-sam-cli-linux-x86_64.zip -d sam-installation - - sudo ./sam-installation/install --update - - rm -rf ./sam-installation aws-sam-cli-linux-x86_64.zip - pre_build: commands: # Print all environment variables (handy for AWS CodeBuild logs @@ -35,7 +24,7 @@ phases: # remove the previous builds #- aws serverlessrepo delete-application --application-id ${AppArn} - + # Package our application with AWS SAM - echo sam publish --template packaged.yaml --semantic-version ${AppVersion} - sam publish --template packaged.yaml --semantic-version ${AppVersion} @@ -47,3 +36,26 @@ phases: else aws serverlessrepo put-application-policy --application-id ${AppArn} --statements Principals=${ShareWith},Actions=Deploy fi + + post_build: + commands: + # Copy in the executable + - cp ${CODEBUILD_SRC_DIR_Built}/dist/ssosync_linux_amd64_v1/ssosync ./ + + # Copy in the tests + - cp cicd/tests ./ + + # Copy in the stack and params templates + - mkdir deploy + - cp cicd/staging/build/params.json ./deploy/ + - cp cicd/staging/build/stack.yml ./deploy/ + + # Update params with the values for this run + - sed -i 's/APPARN/${AppArn}/g' params.json + - sed -i 's/APPVERSION/${AppVersion}/g' params.json + +artifacts: + files: + - ssosync + - deploy/**/* + - tests/**/* diff --git a/cicd/staging/deploy/params.json b/cicd/staging/build/params.json similarity index 89% rename from cicd/staging/deploy/params.json rename to cicd/staging/build/params.json index f61918c0..5ec339f6 100644 --- a/cicd/staging/deploy/params.json +++ b/cicd/staging/build/params.json @@ -1,6 +1,6 @@ { "Parameters": { - "AppArn": "APPARN}", + "AppArn": "APPARN", "AppVersion": "APPVERSION" }, "StackPolicy": { diff --git a/cicd/staging/deploy/stack.yml b/cicd/staging/build/stack.yml similarity index 100% rename from cicd/staging/deploy/stack.yml rename to cicd/staging/build/stack.yml diff --git a/cicd/staging/deploy/buildspec.yml b/cicd/staging/deploy/buildspec.yml deleted file mode 100644 index 9360ba2a..00000000 --- a/cicd/staging/deploy/buildspec.yml +++ /dev/null @@ -1,36 +0,0 @@ -version: 0.2 - -phases: - install: - commands: - # Update sam to latest version - - wget -q https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip - - unzip -q awscli-exe-linux-x86_64.zip - - sudo ./aws/install --update - - rm -rf ./aws awscli-exe-linux-x86_64.zip - - pre_build: - commands: - # Print all environment variables (handy for AWS CodeBuild logs) - - env - - build: - commands: - - Parameters="[{\"ParameterKey\":\"AppArn\",\"ParameterValue\":\"${AppArn}\"}, {\"ParameterKey\":\"AppVersion\",\"ParameterValue\":\"${AppVersion}\"}]" - - echo ${Parameters} - - - Capabilities="CAPABILITY_IAM CAPABILITY_AUTO_EXPAND" - - # Assume correct role on the staging account - - export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" $(aws sts assume-role --role-arn "${ProductionAcctCodePipelineCloudFormationRole}" --role-session-name "CloudFormationRole" --query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" --output text)) - - # Create a changeset for the deployment - - echo aws cloudformation create-change-set --stack-name "${StackName}" --template-body "file://${TemplatePath}" --parameters "${Parameters}" --capabilities ${Capabilities} --role-arn "${CloudFormationDeployerRole}" --change-set-name "${ChangeSetName}" --client-token "${ChangeSetName}" --change-set-type "CREATE" - - aws cloudformation create-change-set --stack-name "${StackName}" --template-body "file://${TemplatePath}" --parameters "${Parameters}" --capabilities ${Capabilities} --role-arn "${CloudFormationDeployerRole}" --change-set-name "${ChangeSetName}" --client-token "${ChangeSetName}" --change-set-type "CREATE" - - # Wait for the change set to be created - - aws cloudformation wait change-set-create-complete --stack-name "${StackName}" --change-set-name "${ChangeSetName}" - - # Deploy the changeset - - aws cloudformation execute-change-set --stack-name "${StackName}" --change-set-name "${ChangeSetName}" - diff --git a/cicd/production/testing/testing/buildspec.yml b/cicd/staging/testing/buildspec.yml similarity index 52% rename from cicd/production/testing/testing/buildspec.yml rename to cicd/staging/testing/buildspec.yml index 2ec4e20b..6db5c3fd 100644 --- a/cicd/production/testing/testing/buildspec.yml +++ b/cicd/staging/testing/buildspec.yml @@ -2,39 +2,45 @@ version: 0.2 env: variables: + ShareWith: "NOT-SHARED" pipeline: "SSOSync" interval: 10 Success: '"Succeeded"' InProgress: '"InProgress"' - -phases: - install: - commands: - # Update sam to latest version - - wget -q https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip - - unzip -q awscli-exe-linux-x86_64.zip - - sudo ./aws/install --update - - rm -rf ./aws awscli-exe-linux-x86_64.zip + exported-variables: + - AppArn + - AppVersion - pre_build: +phases: + pre_build: commands: - # Print all environment variables (handy for AWS CodeBuild logs) + # Print all environment variables (handy for AWS CodeBuild logs - env build: commands: + # zip up the content of TESTS + - cp -r ${CODEBUILD_SRC_DIR_Tests} ./ + - zip -r tests.zip ./ssosync + - zip -r tests.zip ./tests + - zip -r tests.zip ./deploy + + # Auth into the Staging Account - export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" $(aws sts assume-role --role-arn "${ProductionAcctCodePipelineRole}" --role-session-name "CodePipelineRole" --query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" --output text)) + # upload the zipfile to the S3 Bucket + - aws s3 cp ./tests.zip s3://${TARGETS3BUCKET}/ + # Start the test pipeline in the staging account - - export ExecutionId=$(aws --profile=ssosync-dev codepipeline start-pipeline-execution --name $pipeline --output text) + - export ExecutionId=$(aws codepipeline start-pipeline-execution --name $pipeline --output text) - echo "ExecutionId=" $ExecutionId - - export Status=$(aws --profile=ssosync-dev codepipeline get-pipeline-execution --pipeline-name $pipeline --output json --pipeline-execution-id $ExecutionId --query "pipelineExecution.status") + - export Status=$(aws codepipeline get-pipeline-execution --pipeline-name $pipeline --output json --pipeline-execution-id $ExecutionId --query "pipelineExecution.status") - | while [ "$Status" == "$InProgress" ] do sleep $interval - export Status="$(aws --profile=ssosync-dev codepipeline get-pipeline-execution --pipeline-name $pipeline --output json --pipeline-execution-id $ExecutionId --query "pipelineExecution.status")" + export Status="$(aws codepipeline get-pipeline-execution --pipeline-name $pipeline --output json --pipeline-execution-id $ExecutionId --query "pipelineExecution.status")" echo $Status done diff --git a/cicd/test-container/buildspec.yml b/cicd/tests/smoke/cli/buildspec.yml similarity index 100% rename from cicd/test-container/buildspec.yml rename to cicd/tests/smoke/cli/buildspec.yml diff --git a/cicd/staging/smoke/lambda/buildspec.yml b/cicd/tests/smoke/lambda/buildspec.yml similarity index 100% rename from cicd/staging/smoke/lambda/buildspec.yml rename to cicd/tests/smoke/lambda/buildspec.yml