1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-08-24 20:08:55 +02:00

Create pipeline with separate builds

This commit is contained in:
ebosas
2021-11-11 10:28:14 +02:00
parent 5915b48e81
commit 608d22d39a
5 changed files with 124 additions and 113 deletions

View File

@@ -48,6 +48,7 @@ Resources:
DependsOn: DependsOn:
- SSMArtifactBucket - SSMArtifactBucket
- SSMCodePipelineServiceRole - SSMCodePipelineServiceRole
- SSMCloudFormationDeployRole
Properties: Properties:
RoleArn: !GetAtt CodePipelineServiceRole.Arn RoleArn: !GetAtt CodePipelineServiceRole.Arn
ArtifactStore: ArtifactStore:
@@ -162,71 +163,72 @@ Resources:
# InputArtifacts: # InputArtifacts:
# - Name: Source # - Name: Source
#-----------------------------------------------------------------------------# # #-----------------------------------------------------------------------------#
# Services # # Services
#-----------------------------------------------------------------------------# # #-----------------------------------------------------------------------------#
- Name: Services # - Name: Services
Actions: # Actions:
- Name: Server # - Name: Server
ActionTypeId: # ActionTypeId:
Category: Deploy # Category: Deploy
Owner: AWS # Owner: AWS
Version: 1 # Version: 1
Provider: CloudFormation # Provider: CloudFormation
Configuration: # Configuration:
ActionMode: CREATE_UPDATE # ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn # RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Server # StackName: !Sub ${EnvironmentName}-Server
TemplatePath: !Sub Source::deployments/services-${DeploymentType}/server.yml # TemplatePath: !Sub Source::deployments/services-${DeploymentType}/server.yml
Capabilities: CAPABILITY_IAM # Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | # ParameterOverrides: !Sub |
{ # {
"EnvironmentName": "${EnvironmentName}", # "EnvironmentName": "${EnvironmentName}",
"ServiceName": "server" # "ServiceName": "server",
} # "ImageUrl": "don't have it yet"
InputArtifacts: # }
- Name: Source # InputArtifacts:
# - Name: Source
- Name: Cache # - Name: Cache
ActionTypeId: # ActionTypeId:
Category: Deploy # Category: Deploy
Owner: AWS # Owner: AWS
Version: 1 # Version: 1
Provider: CloudFormation # Provider: CloudFormation
Configuration: # Configuration:
ActionMode: CREATE_UPDATE # ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn # RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Cache # StackName: !Sub ${EnvironmentName}-Cache
TemplatePath: !Sub Source::deployments/services-${DeploymentType}/cache.yml # TemplatePath: !Sub Source::deployments/services-${DeploymentType}/cache.yml
Capabilities: CAPABILITY_IAM # Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | # ParameterOverrides: !Sub |
{ # {
"EnvironmentName": "${EnvironmentName}", # "EnvironmentName": "${EnvironmentName}",
"ServiceName": "cache" # "ServiceName": "cache"
} # }
InputArtifacts: # InputArtifacts:
- Name: Source # - Name: Source
- Name: Database # - Name: Database
ActionTypeId: # ActionTypeId:
Category: Deploy # Category: Deploy
Owner: AWS # Owner: AWS
Version: 1 # Version: 1
Provider: CloudFormation # Provider: CloudFormation
Configuration: # Configuration:
ActionMode: CREATE_UPDATE # ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn # RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Database # StackName: !Sub ${EnvironmentName}-Database
TemplatePath: !Sub Source::deployments/services-${DeploymentType}/database.yml # TemplatePath: !Sub Source::deployments/services-${DeploymentType}/database.yml
Capabilities: CAPABILITY_IAM # Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | # ParameterOverrides: !Sub |
{ # {
"EnvironmentName": "${EnvironmentName}", # "EnvironmentName": "${EnvironmentName}",
"ServiceName": "database" # "ServiceName": "database"
} # }
InputArtifacts: # InputArtifacts:
- Name: Source # - Name: Source
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
@@ -252,7 +254,7 @@ Resources:
"ServiceName": "server", "ServiceName": "server",
"EnvironmentName": "${EnvironmentName}", "EnvironmentName": "${EnvironmentName}",
"DeploymentType": "${DeploymentType}", "DeploymentType": "${DeploymentType}",
"TriggerMessagePattern": "\[(BuildServer|BuildAll)\]" "TriggerMessagePattern": "\[(BuildServer|BuildAll)\]",
"GitHubRepo": "${GitHubRepo}", "GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}", "GitHubBranch": "${GitHubBranch}",
"GitHubToken": "${GitHubToken}", "GitHubToken": "${GitHubToken}",
@@ -278,7 +280,7 @@ Resources:
"ServiceName": "cache", "ServiceName": "cache",
"EnvironmentName": "${EnvironmentName}", "EnvironmentName": "${EnvironmentName}",
"DeploymentType": "${DeploymentType}", "DeploymentType": "${DeploymentType}",
"TriggerMessagePattern": "\[(BuildCache|BuildAll)\]" "TriggerMessagePattern": "\[(BuildCache|BuildAll)\]",
"GitHubRepo": "${GitHubRepo}", "GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}", "GitHubBranch": "${GitHubBranch}",
"GitHubToken": "${GitHubToken}", "GitHubToken": "${GitHubToken}",
@@ -304,7 +306,7 @@ Resources:
"ServiceName": "database", "ServiceName": "database",
"EnvironmentName": "${EnvironmentName}", "EnvironmentName": "${EnvironmentName}",
"DeploymentType": "${DeploymentType}", "DeploymentType": "${DeploymentType}",
"TriggerMessagePattern": "\[(BuildDatabase|BuildAll)\]" "TriggerMessagePattern": "\[(BuildDatabase|BuildAll)\]",
"GitHubRepo": "${GitHubRepo}", "GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}", "GitHubBranch": "${GitHubBranch}",
"GitHubToken": "${GitHubToken}", "GitHubToken": "${GitHubToken}",
@@ -429,6 +431,12 @@ Resources:
Name: /microservices/codepipeline_service_role Name: /microservices/codepipeline_service_role
Type: String Type: String
Value: !Ref CodePipelineServiceRole Value: !Ref CodePipelineServiceRole
SSMCloudFormationDeployRole:
Type: AWS::SSM::Parameter
Properties:
Name: /microservices/cloudformation_deploy_role
Type: String
Value: !Ref CloudFormationDeployRole
Outputs: Outputs:

View File

@@ -29,13 +29,16 @@ Parameters:
CodePipelineServiceRole: CodePipelineServiceRole:
Type: AWS::SSM::Parameter::Value<String> Type: AWS::SSM::Parameter::Value<String>
Default: /microservices/codepipeline_service_role Default: /microservices/codepipeline_service_role
CloudFormationDeployRole:
Type: AWS::SSM::Parameter::Value<String>
Default: /microservices/cloudformation_deploy_role
Resources: Resources:
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# ECR # ECR
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
ServerRepository: Repository:
Type: AWS::ECR::Repository Type: AWS::ECR::Repository
Properties: Properties:
RepositoryName: !Sub ${EnvironmentName}/${ServiceName} RepositoryName: !Sub ${EnvironmentName}/${ServiceName}
@@ -72,7 +75,7 @@ Resources:
- Name: SERVICE - Name: SERVICE
Value: server Value: server
- Name: REPO_URI - Name: REPO_URI
Value: !Sub ${ServerRepository.RepositoryUri} Value: !Sub ${Repository.RepositoryUri}
Triggers: Triggers:
Webhook: true Webhook: true
FilterGroups: FilterGroups:
@@ -107,7 +110,7 @@ Resources:
detail: detail:
action-type: [PUSH] action-type: [PUSH]
image-tag: [latest] image-tag: [latest]
repository-name: [!Ref ServerRepository] repository-name: [!Ref Repository]
result: [SUCCESS] result: [SUCCESS]
detail-type: [ECR Image Action] detail-type: [ECR Image Action]
source: [aws.ecr] source: [aws.ecr]
@@ -153,7 +156,7 @@ Resources:
Version: 1 Version: 1
Provider: ECR Provider: ECR
Configuration: Configuration:
RepositoryName: !Ref ServerRepository RepositoryName: !Ref Repository
ImageTag: latest ImageTag: latest
OutputArtifacts: OutputArtifacts:
- Name: Image - Name: Image
@@ -178,22 +181,6 @@ Resources:
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# Deploy # 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 # - Name: Deploy
# Actions: # Actions:
# - Name: Deploy # - Name: Deploy
@@ -201,21 +188,37 @@ Resources:
# Category: Deploy # Category: Deploy
# Owner: AWS # Owner: AWS
# Version: 1 # Version: 1
# Provider: CloudFormation # Provider: ECS
# Configuration: # Configuration:
# ActionMode: CREATE_UPDATE # ClusterName:
# RoleArn: !GetAtt CloudFormationDeployRole.Arn # Fn::ImportValue: !Sub ${EnvironmentName}:ClusterName
# StackName: !Sub ${EnvironmentName}-ServerService # ServiceName: !Ref ServiceName
# TemplatePath: !Sub Code::deployments/services-${DeploymentType}/server.yml # FileName: imageDetail.json
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}",
# "ImageUrl": "${ServerRepository.RepositoryUri}@#{ImageVariables.ImageDigest}"
# }
# InputArtifacts: # InputArtifacts:
# - Name: Image # - 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 # Role for CodeBuild service
@@ -249,7 +252,7 @@ Resources:
- s3:GetObject - s3:GetObject
- s3:PutObject - s3:PutObject
- s3:GetObjectVersion - s3:GetObjectVersion
- Resource: !GetAtt ServerRepository.Arn - Resource: !GetAtt Repository.Arn
Effect: Allow Effect: Allow
Action: Action:
- ecr:GetDownloadUrlForLayer - ecr:GetDownloadUrlForLayer

View File

@@ -9,10 +9,10 @@ Parameters:
Type: String Type: String
Default: cache Default: cache
Description: A name for the service Description: A name for the service
# ImageUrl: ImageUrl:
# Type: String Type: String
# Description: The url of a docker image that contains the application process that Description: The url of a docker image that contains the application process that
# will handle the traffic for this service will handle the traffic for this service
ContainerCpu: ContainerCpu:
Type: Number Type: Number
Default: 256 Default: 256
@@ -64,7 +64,7 @@ Resources:
Cpu: !Ref 'ContainerCpu' Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory' Memory: !Ref 'ContainerMemory'
# Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest # Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest
# Image: !Ref ImageUrl Image: !Ref ImageUrl
LogConfiguration: LogConfiguration:
LogDriver: 'awslogs' LogDriver: 'awslogs'
Options: Options:

View File

@@ -9,10 +9,10 @@ Parameters:
Type: String Type: String
Default: database Default: database
Description: A name for the service Description: A name for the service
# ImageUrl: ImageUrl:
# Type: String Type: String
# Description: The url of a docker image that contains the application process that Description: The url of a docker image that contains the application process that
# will handle the traffic for this service will handle the traffic for this service
ContainerCpu: ContainerCpu:
Type: Number Type: Number
Default: 256 Default: 256
@@ -64,7 +64,7 @@ Resources:
Cpu: !Ref 'ContainerCpu' Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory' Memory: !Ref 'ContainerMemory'
# Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest # Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest
# Image: !Ref ImageUrl Image: !Ref ImageUrl
LogConfiguration: LogConfiguration:
LogDriver: 'awslogs' LogDriver: 'awslogs'
Options: Options:

View File

@@ -9,10 +9,10 @@ Parameters:
Type: String Type: String
Default: server Default: server
Description: A name for the service Description: A name for the service
# ImageUrl: ImageUrl:
# Type: String Type: String
# Description: The url of a docker image that contains the application process that Description: The url of a docker image that contains the application process that
# will handle the traffic for this service will handle the traffic for this service
ContainerPort: ContainerPort:
Type: Number Type: Number
Default: 80 Default: 80
@@ -80,7 +80,7 @@ Resources:
Cpu: !Ref 'ContainerCpu' Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory' Memory: !Ref 'ContainerMemory'
# Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest # Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/microservices/${ServiceName}:latest
# Image: !Ref ImageUrl Image: !Ref ImageUrl
PortMappings: PortMappings:
- ContainerPort: !Ref 'ContainerPort' - ContainerPort: !Ref 'ContainerPort'
LogConfiguration: LogConfiguration: