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

Create new pipeline

This commit is contained in:
ebosas
2021-11-13 21:18:17 +02:00
parent 5736130611
commit 7d9e66b7fc
7 changed files with 225 additions and 203 deletions

View File

@@ -18,8 +18,10 @@ Parameters:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id
Description: The Amazon Machine Image ID used for the EC2 cluster
Conditions:
EC2: !Equals [ !Ref LaunchType, 'EC2' ]
Resources:
#-----------------------------------------------------------------------------#

View File

@@ -184,9 +184,6 @@ Resources:
GroupDescription: Access to the ECS hosts that run containers
VpcId: !Ref 'VPC'
# These are the values output by the CloudFormation template. Be careful
# about changing any of them, because of them are exported with specific
# names so that the other task related CF templates can use them.
Outputs:
VpcId:
Description: The ID of the VPC that this stack is deployed in

View File

@@ -16,6 +16,9 @@ Parameters:
Default: Fargate
AllowedValues: [Fargate, EC2]
Conditions:
Fargate: !Equals [ !Ref LaunchType, 'Fargate' ]
Resources:
#-----------------------------------------------------------------------------#
@@ -89,92 +92,92 @@ Resources:
- Name: Source
RunOrder: 1
# #-----------------------------------------------------------------------------#
# # Infrastructure Resources
# #-----------------------------------------------------------------------------#
# - Name: Network_Resources
# Actions:
# - Name: Deploy
# ActionTypeId:
# Category: Deploy
# Owner: AWS
# Version: 1
# Provider: CloudFormation
# Configuration:
# ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Network
# TemplatePath: Source::deployments/network.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}"
# }
# InputArtifacts:
# - Name: Source
#-----------------------------------------------------------------------------#
# Infrastructure Resources
#-----------------------------------------------------------------------------#
- Name: Network_Resources
Actions:
- Name: Deploy
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Network
TemplatePath: Source::deployments/network.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}"
}
InputArtifacts:
- Name: Source
# - Name: Base_Resources
# Actions:
# # Rabbit, Redis, and Postgres
# - Name: Resources
# ActionTypeId:
# Category: Deploy
# Owner: AWS
# Version: 1
# Provider: CloudFormation
# Configuration:
# ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Resources
# TemplatePath: Source::deployments/resources.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}"
# }
# InputArtifacts:
# - Name: Source
- Name: Base_Resources
Actions:
# Rabbit, Redis, and Postgres
- Name: Resources
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Resources
TemplatePath: Source::deployments/resources.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}"
}
InputArtifacts:
- Name: Source
# # Application load balancer
# - Name: Load_Balancer
# ActionTypeId:
# Category: Deploy
# Owner: AWS
# Version: 1
# Provider: CloudFormation
# Configuration:
# ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-LoadBalancer
# TemplatePath: Source::deployments/alb.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}"
# }
# InputArtifacts:
# - Name: Source
# Application load balancer
- Name: Load_Balancer
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-LoadBalancer
TemplatePath: Source::deployments/alb.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}"
}
InputArtifacts:
- Name: Source
# # ECS/Fargate cluster
# - Name: Cluster
# ActionTypeId:
# Category: Deploy
# Owner: AWS
# Version: 1
# Provider: CloudFormation
# Configuration:
# ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Cluster
# TemplatePath: Source::deployments/cluster.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}",
# "LaunchType": "${LaunchType}"
# }
# InputArtifacts:
# - Name: Source
# ECS/Fargate cluster
- Name: Cluster
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Cluster
TemplatePath: Source::deployments/cluster.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}",
"LaunchType": "${LaunchType}"
}
InputArtifacts:
- Name: Source
#-----------------------------------------------------------------------------#
# Services
@@ -182,49 +185,55 @@ Resources:
- 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-Service
# TemplatePath: Source::deployments/services/server.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "ServiceName": "server",
# "EnvironmentName": "${EnvironmentName}",
# "LaunchType": "${LaunchType}",
# "ImageUrl": "amazon/amazon-ecs-sample"
# }
# 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-Service
TemplatePath: Source::deployments/services/server.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub
- |
{
"ServiceName": "server",
"EnvironmentName": "${EnvironmentName}",
"LaunchType": "${LaunchType}",
"ImageUrl": "amazon/amazon-ecs-sample",
"ContainerMemory": ${memory}
}
- memory: !If [ Fargate, 512, 230 ]
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-Service
# TemplatePath: Source::deployments/services/cache.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "ServiceName": "cache",
# "EnvironmentName": "${EnvironmentName}",
# "LaunchType": "${LaunchType}",
# "ImageUrl": "amazon/amazon-ecs-sample"
# }
# 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-Service
TemplatePath: Source::deployments/services/cache.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub
- |
{
"ServiceName": "cache",
"EnvironmentName": "${EnvironmentName}",
"LaunchType": "${LaunchType}",
"ImageUrl": "amazon/amazon-ecs-sample",
"ContainerMemory": ${memory}
}
- memory: !If [ Fargate, 512, 230 ]
InputArtifacts:
- Name: Source
- Name: Database
ActionTypeId:
@@ -238,14 +247,16 @@ Resources:
StackName: !Sub ${EnvironmentName}-Database-Service
TemplatePath: Source::deployments/services/database.yml
Capabilities: CAPABILITY_IAM
# Using a sample image at this point
ParameterOverrides: !Sub |
{
"ServiceName": "database",
"EnvironmentName": "${EnvironmentName}",
"LaunchType": "${LaunchType}",
"ImageUrl": "amazon/amazon-ecs-sample"
}
ParameterOverrides: !Sub
- |
{
"ServiceName": "database",
"EnvironmentName": "${EnvironmentName}",
"LaunchType": "${LaunchType}",
"ImageUrl": "amazon/amazon-ecs-sample",
"ContainerMemory": ${memory}
}
- memory: !If [ Fargate, 512, 230 ]
InputArtifacts:
- Name: Source
@@ -256,53 +267,53 @@ Resources:
- Name: Service_Pipelines
Actions:
# - Name: Server
# ActionTypeId:
# Category: Deploy
# Owner: AWS
# Version: 1
# Provider: CloudFormation
# Configuration:
# ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Server-Pipeline
# TemplatePath: Source::deployments/service-pipeline.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}",
# "ServiceName": "server",
# "TriggerPattern": "\\[(BuildServer|BuildAll)\\]",
# "GitHubRepo": "${GitHubRepo}",
# "GitHubBranch": "${GitHubBranch}",
# "GitHubUser": "${GitHubUser}"
# }
# 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-Pipeline
TemplatePath: Source::deployments/service-pipeline.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"ServiceName": "server",
"EnvironmentName": "${EnvironmentName}",
"TriggerPattern": "\\[(BuildServer|BuildAll)\\]",
"GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}",
"GitHubUser": "${GitHubUser}"
}
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-Pipeline
# TemplatePath: Source::deployments/service-pipeline.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}",
# "ServiceName": "cache",
# "TriggerPattern": "\\[(BuildCache|BuildAll)\\]",
# "GitHubRepo": "${GitHubRepo}",
# "GitHubBranch": "${GitHubBranch}",
# "GitHubUser": "${GitHubUser}"
# }
# 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-Pipeline
TemplatePath: Source::deployments/service-pipeline.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"ServiceName": "cache",
"EnvironmentName": "${EnvironmentName}",
"TriggerPattern": "\\[(BuildCache|BuildAll)\\]",
"GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}",
"GitHubUser": "${GitHubUser}"
}
InputArtifacts:
- Name: Source
- Name: Database
ActionTypeId:
@@ -318,8 +329,8 @@ Resources:
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}",
"ServiceName": "database",
"EnvironmentName": "${EnvironmentName}",
"TriggerPattern": "\\[(BuildDatabase|BuildAll)\\]",
"GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}",

View File

@@ -4,7 +4,6 @@ Parameters:
EnvironmentName:
Type: String
Default: production
Description: "A friendly environment name that will be used for namespacing all cluster resources. Example: staging, qa, or production"
RabbitUsername:
Type: String
Default: rabbit
@@ -26,7 +25,10 @@ Parameters:
AllowedPattern: "^[a-zA-Z0-9]{12,20}$"
Description: The Postgres password
Resources:
# A RabbitMQ broker
#-----------------------------------------------------------------------------#
# RabbitMQ Broker
#-----------------------------------------------------------------------------#
RabbitMQ:
Type: AWS::AmazonMQ::Broker
Properties:
@@ -43,6 +45,7 @@ Resources:
Users:
- Password: !Ref RabbitPassword
Username: !Ref RabbitUsername
RabbitSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
@@ -56,7 +59,9 @@ Resources:
FromPort: 5671
ToPort: 5671
# A Redis cluster
#-----------------------------------------------------------------------------#
# Redis Cluster
#-----------------------------------------------------------------------------#
Redis:
Type: AWS::ElastiCache::CacheCluster
DeletionPolicy: Delete
@@ -67,6 +72,7 @@ Resources:
NumCacheNodes: 1
CacheSubnetGroupName: !Ref RedisSubnetGroup
VpcSecurityGroupIds: [!Ref RedisSecurityGroup]
RedisSubnetGroup:
Type: AWS::ElastiCache::SubnetGroup
Properties:
@@ -74,6 +80,7 @@ Resources:
SubnetIds:
- Fn::ImportValue: !Sub ${EnvironmentName}:PrivateSubnetOne
- Fn::ImportValue: !Sub ${EnvironmentName}:PrivateSubnetTwo
RedisSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
@@ -87,7 +94,9 @@ Resources:
FromPort: 6379
ToPort: 6379
# A Postgres database
#-----------------------------------------------------------------------------#
# Postgres Database
#-----------------------------------------------------------------------------#
Postgres:
Type: AWS::RDS::DBInstance
DeletionPolicy: Delete
@@ -106,6 +115,7 @@ Resources:
PubliclyAccessible: false
VPCSecurityGroups: [!Ref PostgresSecurityGroup]
DBSubnetGroupName: !Ref PostgresSubnetGroup
PostgresSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
@@ -113,6 +123,7 @@ Resources:
SubnetIds:
- Fn::ImportValue: !Sub ${EnvironmentName}:PrivateSubnetOne
- Fn::ImportValue: !Sub ${EnvironmentName}:PrivateSubnetTwo
PostgresSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
@@ -130,24 +141,15 @@ Resources:
# FromPort: 5432
# ToPort: 5432
# # An example showing how to use Secrets Manager to generate login credentials.
# # Refer in templates like this '{{resolve:secretsmanager:RabbitSecrets::password}}'
# RabbitSecrets:
# Type: AWS::SecretsManager::Secret
# Properties:
# Name: RabbitSecrets
# Description: This secret has a dynamically generated password
# GenerateSecretString:
# SecretStringTemplate: '{"username": "rabbit"}'
# GenerateStringKey: "password"
# PasswordLength: 15
# ExcludeCharacters: ',:='
#-----------------------------------------------------------------------------#
# SSM Parameter Store
#-----------------------------------------------------------------------------#
# Connection strings for the resources created in this stack, will be passed to
# services as environmental variables. This will expose passwords in SSM Parameter
# Store as well as the ECS tasks definitions interface. Instead, use Secrets
# Manager to generate passwords and retrieve directly in applicaton code as shown
# in the commented example above.
# in the commented example below.
RabbitURLParameter:
Type: AWS::SSM::Parameter
Properties:
@@ -177,3 +179,16 @@ Resources:
Type: String
Description: A connection string for Redis
Value: !Sub ${Redis.RedisEndpoint.Address}:${Redis.RedisEndpoint.Port}
# # An example showing how to use Secrets Manager to generate login credentials.
# # Refer in templates like this '{{resolve:secretsmanager:RabbitSecrets::password}}'
# RabbitSecrets:
# Type: AWS::SecretsManager::Secret
# Properties:
# Name: RabbitSecrets
# Description: This secret has a dynamically generated password
# GenerateSecretString:
# SecretStringTemplate: '{"username": "rabbit"}'
# GenerateStringKey: "password"
# PasswordLength: 15
# ExcludeCharacters: ',:='

View File

@@ -107,7 +107,6 @@ Resources:
# Choose private subnets if using NAT gateways
- Fn::ImportValue: !Sub ${EnvironmentName}:PublicSubnetOne
- Fn::ImportValue: !Sub ${EnvironmentName}:PublicSubnetTwo
EC2Service:
Type: AWS::ECS::Service
Condition: EC2

View File

@@ -107,7 +107,6 @@ Resources:
# Choose private subnets if using NAT gateways
- Fn::ImportValue: !Sub ${EnvironmentName}:PublicSubnetOne
- Fn::ImportValue: !Sub ${EnvironmentName}:PublicSubnetTwo
EC2Service:
Type: AWS::ECS::Service
Condition: EC2

View File

@@ -132,7 +132,6 @@ Resources:
- ContainerName: !Ref 'ServiceName'
ContainerPort: !Ref 'ContainerPort'
TargetGroupArn: !Ref 'TargetGroup'
EC2Service:
Type: AWS::ECS::Service
Condition: EC2