Skip to content

Commit

Permalink
cross pipeline int
Browse files Browse the repository at this point in the history
refining cross pipeline integration
  • Loading branch information
ChrisPates committed Nov 24, 2022
1 parent e2b6810 commit 250653a
Show file tree
Hide file tree
Showing 31 changed files with 63 additions and 75 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 18 additions & 12 deletions cicd/cloudformation/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -35,6 +39,8 @@ Metadata:
default: "123456789012"
CodeStarConnection:
default: "arn:aws:codestar-connections:<AWS::Region>:<AWS::AccountId>:connection/abcd1234-ab12-ab12--ab12-abcdef123456"
TargetBucket:
default: "staging-stagingbucket-10swep1lrlrau"

Resources:

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 24 additions & 12 deletions cicd/publish/buildspec.yml → cicd/staging/build/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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/**/*
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Parameters": {
"AppArn": "APPARN}",
"AppArn": "APPARN",
"AppVersion": "APPVERSION"
},
"StackPolicy": {
Expand Down
File renamed without changes.
36 changes: 0 additions & 36 deletions cicd/staging/deploy/buildspec.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 250653a

Please sign in to comment.