From 608d22d39a7399f68e4f9d44b197bd075f45e8c9 Mon Sep 17 00:00:00 2001 From: ebosas Date: Thu, 11 Nov 2021 10:28:14 +0200 Subject: [PATCH] Create pipeline with separate builds --- deployments/pipeline-new.yml | 138 ++++++++++++---------- deployments/pipeline-service.yml | 69 +++++------ deployments/services-fargate/cache.yml | 10 +- deployments/services-fargate/database.yml | 10 +- deployments/services-fargate/server.yml | 10 +- 5 files changed, 124 insertions(+), 113 deletions(-) diff --git a/deployments/pipeline-new.yml b/deployments/pipeline-new.yml index 94d501d..be18a51 100644 --- a/deployments/pipeline-new.yml +++ b/deployments/pipeline-new.yml @@ -48,6 +48,7 @@ Resources: DependsOn: - SSMArtifactBucket - SSMCodePipelineServiceRole + - SSMCloudFormationDeployRole Properties: RoleArn: !GetAtt CodePipelineServiceRole.Arn ArtifactStore: @@ -162,71 +163,72 @@ Resources: # InputArtifacts: # - Name: Source - #-----------------------------------------------------------------------------# - # Services - #-----------------------------------------------------------------------------# - - Name: Services - Actions: + # #-----------------------------------------------------------------------------# + # # Services + # #-----------------------------------------------------------------------------# + # - Name: Services + # Actions: - - Name: Server - ActionTypeId: - Category: Deploy - Owner: AWS - Version: 1 - Provider: CloudFormation - Configuration: - ActionMode: CREATE_UPDATE - RoleArn: !GetAtt CloudFormationDeployRole.Arn - StackName: !Sub ${EnvironmentName}-Server - TemplatePath: !Sub Source::deployments/services-${DeploymentType}/server.yml - Capabilities: CAPABILITY_IAM - ParameterOverrides: !Sub | - { - "EnvironmentName": "${EnvironmentName}", - "ServiceName": "server" - } - InputArtifacts: - - Name: Source + # - Name: Server + # ActionTypeId: + # Category: Deploy + # Owner: AWS + # Version: 1 + # Provider: CloudFormation + # Configuration: + # ActionMode: CREATE_UPDATE + # RoleArn: !GetAtt CloudFormationDeployRole.Arn + # StackName: !Sub ${EnvironmentName}-Server + # TemplatePath: !Sub Source::deployments/services-${DeploymentType}/server.yml + # Capabilities: CAPABILITY_IAM + # ParameterOverrides: !Sub | + # { + # "EnvironmentName": "${EnvironmentName}", + # "ServiceName": "server", + # "ImageUrl": "don't have it yet" + # } + # InputArtifacts: + # - Name: Source - - Name: Cache - ActionTypeId: - Category: Deploy - Owner: AWS - Version: 1 - Provider: CloudFormation - Configuration: - ActionMode: CREATE_UPDATE - RoleArn: !GetAtt CloudFormationDeployRole.Arn - StackName: !Sub ${EnvironmentName}-Cache - TemplatePath: !Sub Source::deployments/services-${DeploymentType}/cache.yml - Capabilities: CAPABILITY_IAM - ParameterOverrides: !Sub | - { - "EnvironmentName": "${EnvironmentName}", - "ServiceName": "cache" - } - InputArtifacts: - - Name: Source + # - Name: Cache + # ActionTypeId: + # Category: Deploy + # Owner: AWS + # Version: 1 + # Provider: CloudFormation + # Configuration: + # ActionMode: CREATE_UPDATE + # RoleArn: !GetAtt CloudFormationDeployRole.Arn + # StackName: !Sub ${EnvironmentName}-Cache + # TemplatePath: !Sub Source::deployments/services-${DeploymentType}/cache.yml + # Capabilities: CAPABILITY_IAM + # ParameterOverrides: !Sub | + # { + # "EnvironmentName": "${EnvironmentName}", + # "ServiceName": "cache" + # } + # InputArtifacts: + # - Name: Source - - Name: Database - ActionTypeId: - Category: Deploy - Owner: AWS - Version: 1 - Provider: CloudFormation - Configuration: - ActionMode: CREATE_UPDATE - RoleArn: !GetAtt CloudFormationDeployRole.Arn - StackName: !Sub ${EnvironmentName}-Database - TemplatePath: !Sub Source::deployments/services-${DeploymentType}/database.yml - Capabilities: CAPABILITY_IAM - ParameterOverrides: !Sub | - { - "EnvironmentName": "${EnvironmentName}", - "ServiceName": "database" - } - InputArtifacts: - - Name: Source + # - Name: Database + # ActionTypeId: + # Category: Deploy + # Owner: AWS + # Version: 1 + # Provider: CloudFormation + # Configuration: + # ActionMode: CREATE_UPDATE + # RoleArn: !GetAtt CloudFormationDeployRole.Arn + # StackName: !Sub ${EnvironmentName}-Database + # TemplatePath: !Sub Source::deployments/services-${DeploymentType}/database.yml + # Capabilities: CAPABILITY_IAM + # ParameterOverrides: !Sub | + # { + # "EnvironmentName": "${EnvironmentName}", + # "ServiceName": "database" + # } + # InputArtifacts: + # - Name: Source #-----------------------------------------------------------------------------# @@ -252,7 +254,7 @@ Resources: "ServiceName": "server", "EnvironmentName": "${EnvironmentName}", "DeploymentType": "${DeploymentType}", - "TriggerMessagePattern": "\[(BuildServer|BuildAll)\]" + "TriggerMessagePattern": "\[(BuildServer|BuildAll)\]", "GitHubRepo": "${GitHubRepo}", "GitHubBranch": "${GitHubBranch}", "GitHubToken": "${GitHubToken}", @@ -278,7 +280,7 @@ Resources: "ServiceName": "cache", "EnvironmentName": "${EnvironmentName}", "DeploymentType": "${DeploymentType}", - "TriggerMessagePattern": "\[(BuildCache|BuildAll)\]" + "TriggerMessagePattern": "\[(BuildCache|BuildAll)\]", "GitHubRepo": "${GitHubRepo}", "GitHubBranch": "${GitHubBranch}", "GitHubToken": "${GitHubToken}", @@ -304,7 +306,7 @@ Resources: "ServiceName": "database", "EnvironmentName": "${EnvironmentName}", "DeploymentType": "${DeploymentType}", - "TriggerMessagePattern": "\[(BuildDatabase|BuildAll)\]" + "TriggerMessagePattern": "\[(BuildDatabase|BuildAll)\]", "GitHubRepo": "${GitHubRepo}", "GitHubBranch": "${GitHubBranch}", "GitHubToken": "${GitHubToken}", @@ -429,6 +431,12 @@ Resources: Name: /microservices/codepipeline_service_role Type: String Value: !Ref CodePipelineServiceRole + SSMCloudFormationDeployRole: + Type: AWS::SSM::Parameter + Properties: + Name: /microservices/cloudformation_deploy_role + Type: String + Value: !Ref CloudFormationDeployRole Outputs: diff --git a/deployments/pipeline-service.yml b/deployments/pipeline-service.yml index 39315a7..1e8776c 100644 --- a/deployments/pipeline-service.yml +++ b/deployments/pipeline-service.yml @@ -29,13 +29,16 @@ Parameters: CodePipelineServiceRole: Type: AWS::SSM::Parameter::Value Default: /microservices/codepipeline_service_role + CloudFormationDeployRole: + Type: AWS::SSM::Parameter::Value + Default: /microservices/cloudformation_deploy_role Resources: #-----------------------------------------------------------------------------# # ECR #-----------------------------------------------------------------------------# - ServerRepository: + Repository: Type: AWS::ECR::Repository Properties: RepositoryName: !Sub ${EnvironmentName}/${ServiceName} @@ -72,7 +75,7 @@ Resources: - Name: SERVICE Value: server - Name: REPO_URI - Value: !Sub ${ServerRepository.RepositoryUri} + Value: !Sub ${Repository.RepositoryUri} Triggers: Webhook: true FilterGroups: @@ -107,7 +110,7 @@ Resources: detail: action-type: [PUSH] image-tag: [latest] - repository-name: [!Ref ServerRepository] + repository-name: [!Ref Repository] result: [SUCCESS] detail-type: [ECR Image Action] source: [aws.ecr] @@ -153,7 +156,7 @@ Resources: Version: 1 Provider: ECR Configuration: - RepositoryName: !Ref ServerRepository + RepositoryName: !Ref Repository ImageTag: latest OutputArtifacts: - Name: Image @@ -178,22 +181,6 @@ Resources: #-----------------------------------------------------------------------------# # Deploy #-----------------------------------------------------------------------------# - - Name: Deploy - Actions: - - Name: Deploy - ActionTypeId: - Category: Deploy - Owner: AWS - Version: 1 - Provider: ECS - Configuration: - ClusterName: - Fn::ImportValue: !Sub ${EnvironmentName}:ClusterName - ServiceName: !Ref ServiceName - FileName: imageDetail.json - InputArtifacts: - - Name: Image - # - Name: Deploy # Actions: # - Name: Deploy @@ -201,21 +188,37 @@ Resources: # Category: Deploy # Owner: AWS # Version: 1 - # Provider: CloudFormation + # Provider: ECS # Configuration: - # ActionMode: CREATE_UPDATE - # RoleArn: !GetAtt CloudFormationDeployRole.Arn - # StackName: !Sub ${EnvironmentName}-ServerService - # TemplatePath: !Sub Code::deployments/services-${DeploymentType}/server.yml - # Capabilities: CAPABILITY_IAM - # ParameterOverrides: !Sub | - # { - # "EnvironmentName": "${EnvironmentName}", - # "ImageUrl": "${ServerRepository.RepositoryUri}@#{ImageVariables.ImageDigest}" - # } + # ClusterName: + # Fn::ImportValue: !Sub ${EnvironmentName}:ClusterName + # ServiceName: !Ref ServiceName + # FileName: imageDetail.json # InputArtifacts: # - Name: Image - # - Name: Code + + - Name: Deploy + Actions: + - Name: Deploy + ActionTypeId: + Category: Deploy + Owner: AWS + Version: 1 + Provider: CloudFormation + Configuration: + ActionMode: CREATE_UPDATE + RoleArn: !Ref CloudFormationDeployRole + StackName: !Sub ${EnvironmentName}-ServerService + TemplatePath: !Sub Code::deployments/services-${DeploymentType}/server.yml + Capabilities: CAPABILITY_IAM + ParameterOverrides: !Sub | + { + "EnvironmentName": "${EnvironmentName}", + "ImageUrl": "${Repository.RepositoryUri}@#{ImageVariables.ImageDigest}" + } + InputArtifacts: + - Name: Image + - Name: Code #-----------------------------------------------------------------------------# # Role for CodeBuild service @@ -249,7 +252,7 @@ Resources: - s3:GetObject - s3:PutObject - s3:GetObjectVersion - - Resource: !GetAtt ServerRepository.Arn + - Resource: !GetAtt Repository.Arn Effect: Allow Action: - ecr:GetDownloadUrlForLayer diff --git a/deployments/services-fargate/cache.yml b/deployments/services-fargate/cache.yml index 2b164ea..d1affd1 100644 --- a/deployments/services-fargate/cache.yml +++ b/deployments/services-fargate/cache.yml @@ -9,10 +9,10 @@ Parameters: Type: String Default: cache Description: A name for the service - # ImageUrl: - # Type: String - # Description: The url of a docker image that contains the application process that - # will handle the traffic for this service + ImageUrl: + Type: String + Description: The url of a docker image that contains the application process that + will handle the traffic for this service ContainerCpu: Type: Number Default: 256 @@ -64,7 +64,7 @@ Resources: Cpu: !Ref 'ContainerCpu' Memory: !Ref 'ContainerMemory' # Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest - # Image: !Ref ImageUrl + Image: !Ref ImageUrl LogConfiguration: LogDriver: 'awslogs' Options: diff --git a/deployments/services-fargate/database.yml b/deployments/services-fargate/database.yml index 5c10cc3..9285c18 100644 --- a/deployments/services-fargate/database.yml +++ b/deployments/services-fargate/database.yml @@ -9,10 +9,10 @@ Parameters: Type: String Default: database Description: A name for the service - # ImageUrl: - # Type: String - # Description: The url of a docker image that contains the application process that - # will handle the traffic for this service + ImageUrl: + Type: String + Description: The url of a docker image that contains the application process that + will handle the traffic for this service ContainerCpu: Type: Number Default: 256 @@ -64,7 +64,7 @@ Resources: Cpu: !Ref 'ContainerCpu' Memory: !Ref 'ContainerMemory' # Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest - # Image: !Ref ImageUrl + Image: !Ref ImageUrl LogConfiguration: LogDriver: 'awslogs' Options: diff --git a/deployments/services-fargate/server.yml b/deployments/services-fargate/server.yml index 7dc495f..c944240 100644 --- a/deployments/services-fargate/server.yml +++ b/deployments/services-fargate/server.yml @@ -9,10 +9,10 @@ Parameters: Type: String Default: server Description: A name for the service - # ImageUrl: - # Type: String - # Description: The url of a docker image that contains the application process that - # will handle the traffic for this service + ImageUrl: + Type: String + Description: The url of a docker image that contains the application process that + will handle the traffic for this service ContainerPort: Type: Number Default: 80 @@ -80,7 +80,7 @@ Resources: Cpu: !Ref 'ContainerCpu' Memory: !Ref 'ContainerMemory' # Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest - # Image: !Ref ImageUrl + Image: !Ref ImageUrl PortMappings: - ContainerPort: !Ref 'ContainerPort' LogConfiguration: