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:
- 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:

View File

@@ -29,13 +29,16 @@ Parameters:
CodePipelineServiceRole:
Type: AWS::SSM::Parameter::Value<String>
Default: /microservices/codepipeline_service_role
CloudFormationDeployRole:
Type: AWS::SSM::Parameter::Value<String>
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

View File

@@ -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:

View File

@@ -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:

View File

@@ -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: