1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-02-16 18:34:37 +02:00

Create multi-build pipeline

This commit is contained in:
ebosas 2021-11-12 21:49:32 +02:00
parent 1274d685e6
commit 6a420e7e02
2 changed files with 17 additions and 109 deletions

View File

@ -60,7 +60,6 @@ Resources:
DependsOn: DependsOn:
- SSMArtifactBucket - SSMArtifactBucket
- SSMCodePipelineServiceRoleArn - SSMCodePipelineServiceRoleArn
# - SSMCloudFormationDeployRole
Properties: Properties:
RoleArn: !GetAtt CodePipelineServiceRole.Arn RoleArn: !GetAtt CodePipelineServiceRole.Arn
ArtifactStore: ArtifactStore:
@ -269,11 +268,9 @@ Resources:
# { # {
# "EnvironmentName": "${EnvironmentName}", # "EnvironmentName": "${EnvironmentName}",
# "ServiceName": "server", # "ServiceName": "server",
# "DeploymentType": "${DeploymentType}", # "TriggerPattern": "\\[(BuildServer|BuildAll)\\]",
# "TriggerMessagePattern": "[(BuildServer|BuildAll)]",
# "GitHubRepo": "${GitHubRepo}", # "GitHubRepo": "${GitHubRepo}",
# "GitHubBranch": "${GitHubBranch}", # "GitHubBranch": "${GitHubBranch}",
# "GitHubToken": "${GitHubToken}",
# "GitHubUser": "${GitHubUser}" # "GitHubUser": "${GitHubUser}"
# } # }
# InputArtifacts: # InputArtifacts:
@ -295,11 +292,9 @@ Resources:
# { # {
# "EnvironmentName": "${EnvironmentName}", # "EnvironmentName": "${EnvironmentName}",
# "ServiceName": "cache", # "ServiceName": "cache",
# "DeploymentType": "${DeploymentType}", # "TriggerPattern": "\\[(BuildCache|BuildAll)\\]",
# "TriggerMessagePattern": "[(BuildCache|BuildAll)]",
# "GitHubRepo": "${GitHubRepo}", # "GitHubRepo": "${GitHubRepo}",
# "GitHubBranch": "${GitHubBranch}", # "GitHubBranch": "${GitHubBranch}",
# "GitHubToken": "${GitHubToken}",
# "GitHubUser": "${GitHubUser}" # "GitHubUser": "${GitHubUser}"
# } # }
# InputArtifacts: # InputArtifacts:
@ -321,18 +316,16 @@ Resources:
{ {
"EnvironmentName": "${EnvironmentName}", "EnvironmentName": "${EnvironmentName}",
"ServiceName": "database", "ServiceName": "database",
"DeploymentType": "${DeploymentType}", "TriggerPattern": "\\[(BuildDatabase|BuildAll)\\]",
"TriggerMessagePattern": "\\[(BuildDatabase|BuildAll)\\]",
"GitHubRepo": "${GitHubRepo}", "GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}", "GitHubBranch": "${GitHubBranch}",
"GitHubToken": "${GitHubToken}",
"GitHubUser": "${GitHubUser}" "GitHubUser": "${GitHubUser}"
} }
InputArtifacts: InputArtifacts:
- Name: Source - Name: Source
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# Role for CodePipeline service # Roles for CodePipeline service
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
CodePipelineServiceRole: CodePipelineServiceRole:
Type: AWS::IAM::Role Type: AWS::IAM::Role
@ -352,8 +345,8 @@ Resources:
Statement: Statement:
# 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
@ -445,7 +438,7 @@ Resources:
- "codepipeline:*" - "codepipeline:*"
- "events:*" - "events:*"
- "ecs:*" - "ecs:*"
- "s3:*" # - "s3:*"
Resource: "*" Resource: "*"
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
@ -463,12 +456,6 @@ Resources:
Name: /microservices/codepipeline_service_role_arn Name: /microservices/codepipeline_service_role_arn
Type: String Type: String
Value: !GetAtt CodePipelineServiceRole.Arn Value: !GetAtt CodePipelineServiceRole.Arn
# SSMCloudFormationDeployRole:
# Type: AWS::SSM::Parameter
# Properties:
# Name: /microservices/cloudformation_deploy_role
# Type: String
# Value: !Ref CloudFormationDeployRole
Outputs: Outputs:
PipelineUrl: PipelineUrl:

View File

@ -3,23 +3,23 @@ Parameters:
Type: String Type: String
GitHubBranch: GitHubBranch:
Type: String Type: String
GitHubToken: # GitHubToken:
Type: String # Type: String
NoEcho: true # NoEcho: true
GitHubUser: GitHubUser:
Type: String Type: String
EnvironmentName: EnvironmentName:
Type: String Type: String
Default: production Default: production
DeploymentType: # DeploymentType:
Type: String # Type: String
Default: fargate # Default: fargate
AllowedValues: [ecs, fargate] # AllowedValues: [ecs, fargate]
ServiceName: ServiceName:
Type: String Type: String
Description: The name of the service Description: The name of the service
AllowedValues: [server, cache, database] AllowedValues: [server, cache, database]
TriggerMessagePattern: TriggerPattern:
Type: String Type: String
Description: A commit message that triggers the build process Description: A commit message that triggers the build process
Default: \[BuildAll\] Default: \[BuildAll\]
@ -29,9 +29,6 @@ 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:
# Type: AWS::SSM::Parameter::Value<String>
# Default: /microservices/cloudformation_deploy_role
Resources: Resources:
@ -46,18 +43,10 @@ Resources:
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# CodeBuild Project # CodeBuild Project
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# SourceCredentials:
# Type: AWS::CodeBuild::SourceCredential
# Properties:
# Token: !Ref GitHubToken
# ServerType: GITHUB
# AuthType: PERSONAL_ACCESS_TOKEN
CodeBuildProject: CodeBuildProject:
Type: AWS::CodeBuild::Project Type: AWS::CodeBuild::Project
# DependsOn: SourceCredentials
Properties: Properties:
Name: !Sub ${EnvironmentName}-${ServiceName}
Artifacts: Artifacts:
Type: S3 Type: S3
Location: !Ref ArtifactBucket Location: !Ref ArtifactBucket
@ -94,7 +83,7 @@ Resources:
Pattern: !Sub ^refs/heads/${GitHubBranch}$ Pattern: !Sub ^refs/heads/${GitHubBranch}$
ExcludeMatchedPattern: false ExcludeMatchedPattern: false
- Type: COMMIT_MESSAGE - Type: COMMIT_MESSAGE
Pattern: !Ref TriggerMessagePattern Pattern: !Ref TriggerPattern
ExcludeMatchedPattern: false ExcludeMatchedPattern: false
# - - Type: EVENT # - - Type: EVENT
# Pattern: PUSH # Pattern: PUSH
@ -125,20 +114,6 @@ Resources:
RoleArn: !GetAtt CloudWatchEventRole.Arn RoleArn: !GetAtt CloudWatchEventRole.Arn
Id: server-pipeline Id: server-pipeline
# PipelineWebhook:
# Type: AWS::CodePipeline::Webhook
# Properties:
# AuthenticationConfiguration:
# SecretToken: !Ref GitHubToken
# Filters:
# - JsonPath: "$.ref"
# MatchEquals: refs/heads/{Branch}
# Authentication: GITHUB_HMAC
# TargetPipeline: !Ref Pipeline
# TargetAction: Code
# TargetPipelineVersion: !GetAtt Pipeline.Version
# RegisterWithThirdParty: false # only manual action
Pipeline: Pipeline:
Type: AWS::CodePipeline::Pipeline Type: AWS::CodePipeline::Pipeline
Properties: Properties:
@ -153,21 +128,6 @@ 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
ActionTypeId: ActionTypeId:
Category: Source Category: Source
@ -182,21 +142,6 @@ Resources:
- Name: Image - Name: Image
RunOrder: 1 RunOrder: 1
# - Name: Code
# ActionTypeId:
# Category: Source
# Owner: ThirdParty
# Version: 1
# Provider: GitHub
# Configuration:
# Owner: !Ref GitHubUser
# Repo: !Ref GitHubRepo
# Branch: !Ref GitHubBranch
# OAuthToken: !Ref GitHubToken
# PollForSourceChanges: false
# OutputArtifacts:
# - Name: Code
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
# Deploy # Deploy
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
@ -216,30 +161,6 @@ Resources:
InputArtifacts: InputArtifacts:
- Name: Image - Name: Image
# - 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
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#