1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-06-24 22:26:56 +02:00

Create cfn task deployment

This commit is contained in:
ebosas
2021-11-12 14:08:49 +02:00
parent 628b73cebd
commit 7e5dbc5f75
2 changed files with 88 additions and 93 deletions

View File

@ -179,8 +179,8 @@ Resources:
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# Services # Services
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
- Name: Services # - Name: Services
Actions: # Actions:
# - Name: Server # - Name: Server
# ActionTypeId: # ActionTypeId:
@ -191,7 +191,7 @@ Resources:
# Configuration: # Configuration:
# ActionMode: CREATE_UPDATE # ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn # RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Service-Server # StackName: !Sub ${EnvironmentName}-Server-Service
# 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 |
@ -212,7 +212,7 @@ Resources:
# Configuration: # Configuration:
# ActionMode: CREATE_UPDATE # ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn # RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Service-Cache # StackName: !Sub ${EnvironmentName}-Cache-Service
# 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 |
@ -224,26 +224,26 @@ Resources:
# 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}-Service-Database # StackName: !Sub ${EnvironmentName}-Database-Service
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",
"ImageUrl": "amazon/amazon-ecs-sample" # "ImageUrl": "amazon/amazon-ecs-sample"
} # }
InputArtifacts: # InputArtifacts:
- Name: Source # - Name: Source
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
@ -261,7 +261,7 @@ Resources:
# Configuration: # Configuration:
# ActionMode: CREATE_UPDATE # ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn # RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Pipeline-Server # StackName: !Sub ${EnvironmentName}-Server-Pipeline
# TemplatePath: Source::deployments/pipeline-service.yml # TemplatePath: Source::deployments/pipeline-service.yml
# Capabilities: CAPABILITY_IAM # Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub | # ParameterOverrides: !Sub |
@ -287,7 +287,7 @@ Resources:
# Configuration: # Configuration:
# ActionMode: CREATE_UPDATE # ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn # RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Pipeline-Cache # StackName: !Sub ${EnvironmentName}-Cache-Pipeline
# TemplatePath: Source::deployments/pipeline-service.yml # TemplatePath: Source::deployments/pipeline-service.yml
# Capabilities: CAPABILITY_IAM # Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub | # ParameterOverrides: !Sub |
@ -313,7 +313,7 @@ Resources:
Configuration: Configuration:
ActionMode: CREATE_UPDATE ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Pipeline-Database StackName: !Sub ${EnvironmentName}-Database-Pipeline
TemplatePath: Source::deployments/pipeline-service.yml TemplatePath: Source::deployments/pipeline-service.yml
Capabilities: CAPABILITY_IAM Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | ParameterOverrides: !Sub |
@ -352,7 +352,7 @@ Resources:
# Allow codepipeline to put artifacts in the S3 bucket # Allow codepipeline to put artifacts in the S3 bucket
# as well as get artifacts back out of it. # as well as get artifacts back out of it.
- Resource: "*" - Resource: "*"
# - !Sub arn:aws:s3:::${ArtifactBucket}/* # - !Sub arn:aws:s3:::${ArtifactBucket}*
Effect: Allow Effect: Allow
Action: Action:
- s3:PutObject - s3:PutObject
@ -469,7 +469,6 @@ Resources:
Type: String Type: String
Value: !Ref CloudFormationDeployRole Value: !Ref CloudFormationDeployRole
Outputs: Outputs:
PipelineUrl: PipelineUrl:
Value: !Sub https://console.aws.amazon.com/codepipeline/home?region=${AWS::Region}#/view/${Pipeline} Value: !Sub https://console.aws.amazon.com/codepipeline/home?region=${AWS::Region}#/view/${Pipeline}

View File

@ -29,9 +29,9 @@ Parameters:
CodePipelineServiceRoleArn: CodePipelineServiceRoleArn:
Type: AWS::SSM::Parameter::Value<String> Type: AWS::SSM::Parameter::Value<String>
Default: /microservices/codepipeline_service_role_arn Default: /microservices/codepipeline_service_role_arn
# CloudFormationDeployRole: CloudFormationDeployRole:
# Type: AWS::SSM::Parameter::Value<String> Type: AWS::SSM::Parameter::Value<String>
# Default: /microservices/cloudformation_deploy_role Default: /microservices/cloudformation_deploy_role
Resources: Resources:
@ -111,17 +111,12 @@ Resources:
Properties: Properties:
EventPattern: EventPattern:
detail: detail:
eventSource: [s3.amazonaws.com] action-type: [PUSH]
eventName: image-tag: [latest]
- CopyObject repository-name: [!Ref Repository]
- CompleteMultipartUpload result: [SUCCESS]
- PutObject detail-type: [ECR Image Action]
requestParameters: source: [aws.ecr]
bucketName: [!Ref ArtifactBucket]
key:
- !Sub imagedefinitions/${ServiceName}.zip
detail-type: [AWS API Call via CloudTrail]
source: [aws.s3]
Targets: Targets:
- Arn: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline} - Arn: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}
RoleArn: !GetAtt CloudWatchEventRole.Arn RoleArn: !GetAtt CloudWatchEventRole.Arn
@ -156,34 +151,34 @@ Resources:
- Name: Source - Name: Source
Actions: Actions:
# - Name: Image
# Namespace: ImageVariables
# ActionTypeId:
# Category: Source
# Owner: AWS
# Version: 1
# Provider: ECR
# Configuration:
# RepositoryName: !Ref Repository
# ImageTag: latest
# OutputArtifacts:
# - Name: Image
# RunOrder: 1
- Name: Image - Name: Image
Namespace: ImageVariables
ActionTypeId: ActionTypeId:
Category: Source Category: Source
Owner: AWS Owner: AWS
Version: 1 Version: 1
Provider: S3 Provider: ECR
Configuration: Configuration:
S3Bucket: !Ref ArtifactBucket RepositoryName: !Ref Repository
S3ObjectKey: !Sub imagedefinitions/${ServiceName}.zip ImageTag: latest
PollForSourceChanges: false
OutputArtifacts: OutputArtifacts:
- Name: Image - Name: Image
RunOrder: 1 RunOrder: 1
# - Name: Image
# ActionTypeId:
# Category: Source
# Owner: AWS
# Version: 1
# Provider: S3
# Configuration:
# S3Bucket: !Ref ArtifactBucket
# S3ObjectKey: !Sub imagedefinitions/${ServiceName}.zip
# PollForSourceChanges: false
# OutputArtifacts:
# - Name: Image
# RunOrder: 1
- Name: Code - Name: Code
ActionTypeId: ActionTypeId:
Category: Source Category: Source
@ -203,26 +198,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
# Needs imagedefinitions.json but ECR produces imageDetail.json.
# Need a build stage to build images or transform imageDetail.json
# as described here: https://stackoverflow.com/a/57015190
# Or use blue/green deployment
FileName: imagedefinitions.json
InputArtifacts:
- Name: Image
# - Name: Deploy # - Name: Deploy
# Actions: # Actions:
# - Name: Deploy # - Name: Deploy
@ -230,21 +205,42 @@ Resources:
# Category: Deploy # Category: Deploy
# Owner: AWS # Owner: AWS
# Version: 1 # Version: 1
# Provider: CloudFormation # Provider: ECS
# Configuration: # Configuration:
# ActionMode: CREATE_UPDATE # ClusterName:
# RoleArn: !Ref CloudFormationDeployRole # Fn::ImportValue: !Sub ${EnvironmentName}:ClusterName
# StackName: !Sub ${EnvironmentName}-ServerService # ServiceName: !Ref ServiceName
# TemplatePath: !Sub Code::deployments/services-${DeploymentType}/server.yml # # Needs imagedefinitions.json but ECR produces imageDetail.json.
# Capabilities: CAPABILITY_IAM # # Need a build stage to build images or transform imageDetail.json
# ParameterOverrides: !Sub | # # as described here: https://stackoverflow.com/a/57015190
# { # # Or use blue/green deployment
# "EnvironmentName": "${EnvironmentName}", # FileName: imagedefinitions.json
# "ImageUrl": "${Repository.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}-Server-Service
TemplatePath: !Sub Code::deployments/services-${DeploymentType}/server.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}",
"ServiceName": "${ServiceName}",
"ImageUrl": "${Repository.RepositoryUri}@#{ImageVariables.ImageDigest}"
}
InputArtifacts:
- Name: Image
- Name: Code
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# Role for CodeBuild service # Role for CodeBuild service