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

Test pipeline

This commit is contained in:
ebosas
2021-11-12 05:43:53 +02:00
parent 5d43f92224
commit e3986a98d7
7 changed files with 248 additions and 271 deletions

View File

@@ -12,4 +12,7 @@ phases:
post_build:
commands:
- docker push $REPO_URI:latest
- docker push $REPO_URI:$TAG
- docker push $REPO_URI:$TAG
- printf '[{"name":"%s","imageUri":"%s"}]' $SERVICE $REPO_URI:$TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json

View File

@@ -17,19 +17,6 @@ Parameters:
AllowedValues: [ecs, fargate]
Resources:
# # Create ECR respositories to hold built docker images
# ServerRepository:
# Type: AWS::ECR::Repository
# DeletionPolicy: Retain
# UpdateReplacePolicy: Retain
# CacheRepository:
# Type: AWS::ECR::Repository
# DeletionPolicy: Retain
# UpdateReplacePolicy: Retain
# DatabaseRepository:
# Type: AWS::ECR::Repository
# DeletionPolicy: Retain
# UpdateReplacePolicy: Retain
# Role used to give CodePipeline to release a build.
CodePipelineServiceRole:
@@ -58,7 +45,6 @@ Resources:
- s3:GetObject
- s3:GetObjectVersion
- s3:GetBucketVersioning
- s3:PutObjectAcl # for codestar connection
# Allow codepipeline to build code builds
- Resource: "*"
Effect: Allow
@@ -79,13 +65,6 @@ Resources:
- cloudformation:ValidateTemplate
- cloudformation:ExecuteChangeSet
Resource: "*"
# Allow codepipeline use codestar connections
- Effect: Allow
Action:
- codestar-connections:GetConnection
- codestar-connections:UseConnection
- codestar-connections:ListConnections
Resource: "*"
# CloudFormation deployment role. This role is passed by CodeBuild to
# CloudFormation to use when setting up the application resources
@@ -128,26 +107,20 @@ Resources:
Properties:
BucketName: !Sub microservices-infrastructure-${AWS::AccountId}
CodeStarConnection:
Type: AWS::CodeStarConnections::Connection
# A Webhook for the pipeline which is set for manual action only
PipelineWebhook:
Type: AWS::CodePipeline::Webhook
Properties:
ConnectionName: MyGitHubConnection
ProviderType: GitHub
# # A Webhook for the pipeline which is set for manual action only
# PipelineWebhook:
# Type: AWS::CodePipeline::Webhook
# Properties:
# AuthenticationConfiguration:
# SecretToken: !Ref GitHubToken
# Filters:
# - JsonPath: "$.ref"
# MatchEquals: refs/heads/{Branch}
# Authentication: GITHUB_HMAC
# TargetPipeline: !Ref Pipeline
# TargetAction: Source
# TargetPipelineVersion: !GetAtt Pipeline.Version
# RegisterWithThirdParty: false # only manual action
AuthenticationConfiguration:
SecretToken: !Ref GitHubToken
Filters:
- JsonPath: "$.ref"
MatchEquals: refs/heads/{Branch}
Authentication: GITHUB_HMAC
TargetPipeline: !Ref Pipeline
TargetAction: Source
TargetPipelineVersion: !GetAtt Pipeline.Version
RegisterWithThirdParty: false # only manual action
# This pipeline defines the steps to build, deploy, and release the application
Pipeline:
@@ -165,33 +138,18 @@ Resources:
- Name: Source
ActionTypeId:
Category: Source
Owner: AWS
Owner: ThirdParty
Version: 1
Provider: CodeStarSourceConnection
# https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CodestarConnectionSource.html
Provider: GitHub
Configuration:
ConnectionArn: !Ref CodeStarConnection
BranchName: !Ref GitHubBranch
FullRepositoryId: !Sub ${GitHubUser}/${GitHubRepo}
DetectChanges: false # only manually
Owner: !Ref GitHubUser
Repo: !Ref GitHubRepo
Branch: !Ref GitHubBranch
OAuthToken: !Ref GitHubToken
PollForSourceChanges: false
OutputArtifacts:
- Name: Source
RunOrder: 1
# - Name: Source
# 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: Source
# RunOrder: 1
# Now we deploy the network resources: VPC, subnets, etc.
- Name: Network
@@ -217,75 +175,75 @@ Resources:
OutputArtifacts:
- Name: Network
# # Deploy the base resources: databases, the load balancer,
# # and the ECS/Fargate cluster
# - Name: BaseResources
# Actions:
# # Deploy the resources: Rabbit, Redis, and Postgres
# - Name: DeployResources
# 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
# OutputArtifacts:
# - Name: Resources
# Deploy the base resources: databases, the load balancer,
# and the ECS/Fargate cluster
- Name: BaseResources
Actions:
# Deploy the resources: Rabbit, Redis, and Postgres
- Name: DeployResources
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
OutputArtifacts:
- Name: Resources
# # Deploy the application load balancer
# - Name: DeployLoadBalancer
# 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
# OutputArtifacts:
# - Name: LoadBalancer
# Deploy the application load balancer
- Name: DeployLoadBalancer
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
OutputArtifacts:
- Name: LoadBalancer
# # Deploy the ECS/Fargate cluster
# - Name: DeployCluster
# ActionTypeId:
# Category: Deploy
# Owner: AWS
# Version: 1
# Provider: CloudFormation
# Configuration:
# ActionMode: CREATE_UPDATE
# RoleArn: !GetAtt CloudFormationDeployRole.Arn
# StackName: !Sub ${EnvironmentName}-Cluster
# TemplatePath: !Sub Source::deployments/cluster-${DeploymentType}.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}"
# }
# InputArtifacts:
# - Name: Source
# OutputArtifacts:
# - Name: Cluster
# Deploy the ECS/Fargate cluster
- Name: DeployCluster
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-Cluster
TemplatePath: !Sub Source::deployments/cluster-${DeploymentType}.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}"
}
InputArtifacts:
- Name: Source
OutputArtifacts:
- Name: Cluster
Outputs:
PipelineUrl:

View File

@@ -83,6 +83,7 @@ Resources:
Repo: !Ref GitHubRepo
Branch: !Ref GitHubBranch
OAuthToken: !Ref GitHubToken
PollForSourceChanges: false
OutputArtifacts:
- Name: Source
RunOrder: 1
@@ -179,47 +180,47 @@ 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}-Service-Server
TemplatePath: !Sub Source::deployments/services-${DeploymentType}/server.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}",
"ServiceName": "server",
"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}-Service-Server
# TemplatePath: !Sub Source::deployments/services-${DeploymentType}/server.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}",
# "ServiceName": "server",
# "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}-Service-Cache
TemplatePath: !Sub Source::deployments/services-${DeploymentType}/cache.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"EnvironmentName": "${EnvironmentName}",
"ServiceName": "cache",
"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}-Service-Cache
# TemplatePath: !Sub Source::deployments/services-${DeploymentType}/cache.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "EnvironmentName": "${EnvironmentName}",
# "ServiceName": "cache",
# "ImageUrl": "amazon/amazon-ecs-sample"
# }
# InputArtifacts:
# - Name: Source
- Name: Database
ActionTypeId:
@@ -249,57 +250,57 @@ 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}-Pipeline-Server
TemplatePath: Source::deployments/pipeline-service.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"ServiceName": "server",
"EnvironmentName": "${EnvironmentName}",
"DeploymentType": "${DeploymentType}",
"TriggerMessagePattern": "[(BuildServer|BuildAll)]",
"GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}",
"GitHubToken": "${GitHubToken}",
"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}-Pipeline-Server
# TemplatePath: Source::deployments/pipeline-service.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "ServiceName": "server",
# "EnvironmentName": "${EnvironmentName}",
# "DeploymentType": "${DeploymentType}",
# "TriggerMessagePattern": "[(BuildServer|BuildAll)]",
# "GitHubRepo": "${GitHubRepo}",
# "GitHubBranch": "${GitHubBranch}",
# "GitHubToken": "${GitHubToken}",
# "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}-Pipeline-Cache
TemplatePath: Source::deployments/pipeline-service.yml
Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub |
{
"ServiceName": "cache",
"EnvironmentName": "${EnvironmentName}",
"DeploymentType": "${DeploymentType}",
"TriggerMessagePattern": "[(BuildCache|BuildAll)]",
"GitHubRepo": "${GitHubRepo}",
"GitHubBranch": "${GitHubBranch}",
"GitHubToken": "${GitHubToken}",
"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}-Pipeline-Cache
# TemplatePath: Source::deployments/pipeline-service.yml
# Capabilities: CAPABILITY_IAM
# ParameterOverrides: !Sub |
# {
# "ServiceName": "cache",
# "EnvironmentName": "${EnvironmentName}",
# "DeploymentType": "${DeploymentType}",
# "TriggerMessagePattern": "[(BuildCache|BuildAll)]",
# "GitHubRepo": "${GitHubRepo}",
# "GitHubBranch": "${GitHubBranch}",
# "GitHubToken": "${GitHubToken}",
# "GitHubUser": "${GitHubUser}"
# }
# InputArtifacts:
# - Name: Source
- Name: Database
ActionTypeId:

View File

@@ -103,21 +103,21 @@ Resources:
#-----------------------------------------------------------------------------#
# CodePipeline
#-----------------------------------------------------------------------------#
CloudWatchEventRule:
Type: AWS::Events::Rule
Properties:
EventPattern:
detail:
action-type: [PUSH]
image-tag: [latest]
repository-name: [!Ref Repository]
result: [SUCCESS]
detail-type: [ECR Image Action]
source: [aws.ecr]
Targets:
- Arn: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}
RoleArn: !GetAtt CloudWatchEventRole.Arn
Id: server-pipeline
# CloudWatchEventRule:
# Type: AWS::Events::Rule
# Properties:
# EventPattern:
# detail:
# action-type: [PUSH]
# image-tag: [latest]
# repository-name: [!Ref Repository]
# result: [SUCCESS]
# detail-type: [ECR Image Action]
# source: [aws.ecr]
# Targets:
# - Arn: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}
# RoleArn: !GetAtt CloudWatchEventRole.Arn
# Id: server-pipeline
PipelineWebhook:
Type: AWS::CodePipeline::Webhook
@@ -148,19 +148,19 @@ Resources:
- Name: Source
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
# Namespace: ImageVariables
# ActionTypeId:
# Category: Source
# Owner: AWS
# Version: 1
# Provider: ECR
# Configuration:
# RepositoryName: !Ref Repository
# ImageTag: latest
# OutputArtifacts:
# - Name: Image
# RunOrder: 1
- Name: Code
ActionTypeId:
@@ -178,6 +178,21 @@ Resources:
- Name: Code
RunOrder: 1
- Name: Build
Actions:
- Name: Build
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: !Ref CodeBuildProject
InputArtifacts:
- Name: Code
OutputArtifacts:
- Name: Image
#-----------------------------------------------------------------------------#
# Deploy
#-----------------------------------------------------------------------------#
@@ -197,7 +212,7 @@ Resources:
# 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: imageDetail.json
FileName: imagedefinitions.json
InputArtifacts:
- Name: Image
@@ -270,25 +285,25 @@ Resources:
#-----------------------------------------------------------------------------#
# Role for CloudWatch service
#-----------------------------------------------------------------------------#
CloudWatchEventRole:
Type: AWS::IAM::Role
Properties:
Path: /
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: events.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: cwe-pipeline-execution
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: codepipeline:StartPipelineExecution
Resource: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}
# CloudWatchEventRole:
# Type: AWS::IAM::Role
# Properties:
# Path: /
# AssumeRolePolicyDocument:
# Version: 2012-10-17
# Statement:
# - Effect: Allow
# Principal:
# Service: events.amazonaws.com
# Action: sts:AssumeRole
# Policies:
# - PolicyName: cwe-pipeline-execution
# PolicyDocument:
# Version: 2012-10-17
# Statement:
# - Effect: Allow
# Action: codepipeline:StartPipelineExecution
# Resource: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}
Outputs:
PipelineUrl:

View File

@@ -23,7 +23,7 @@ Parameters:
Description: How much memory in megabytes to give the container
DesiredCount:
Type: Number
Default: 2
Default: 1
Description: How many copies of the service task to run
Role:
Type: String

View File

@@ -23,7 +23,7 @@ Parameters:
Description: How much memory in megabytes to give the container
DesiredCount:
Type: Number
Default: 2
Default: 1
Description: How many copies of the service task to run
Role:
Type: String

View File

@@ -39,7 +39,7 @@ Parameters:
assigned to different paths on the load balancer.
DesiredCount:
Type: Number
Default: 2
Default: 1
Description: How many copies of the service task to run
Role:
Type: String