1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-07-12 22:41:13 +02:00

Adjust pipeline stages, simplify build project

This commit is contained in:
ebosas
2021-11-02 20:19:30 +02:00
parent 1158d3ba06
commit 3f2256e38b

View File

@ -174,28 +174,21 @@ Resources:
pre_build: pre_build:
commands: commands:
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $REGISTRY - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $REGISTRY
- IMAGE_SERVER=${REPO_SERVER}:${IMAGE_TAG}
- IMAGE_CACHE=${REPO_CACHE}:${IMAGE_TAG}
- IMAGE_DB=${REPO_DB}:${IMAGE_TAG}
build: build:
commands: commands:
- docker build -t $IMAGE_SERVER -f server.Dockerfile . - docker build -t $IMAGE_SERVER_URI -f server.Dockerfile .
- docker build -t $IMAGE_CACHE -f cache.Dockerfile . - docker build -t $IMAGE_CACHE_URI -f cache.Dockerfile .
- docker build -t $IMAGE_DB -f database.Dockerfile . - docker build -t $IMAGE_DB_URI -f database.Dockerfile .
- docker tag $IMAGE_SERVER $REGISTRY/$IMAGE_SERVER
- docker tag $IMAGE_CACHE $REGISTRY/$IMAGE_CACHE
- docker tag $IMAGE_DB $REGISTRY/$IMAGE_DB
post_build: post_build:
commands: commands:
- docker push $REGISTRY/$IMAGE_SERVER - docker push $IMAGE_SERVER_URI
- docker push $REGISTRY/$IMAGE_CACHE - docker push $IMAGE_CACHE_URI
- docker push $REGISTRY/$IMAGE_DB - docker push $IMAGE_DB_URI
- printf '{"ImageServer":"%s", "ImageCache":"%s", "ImageDatabase":"%s"}' $REGISTRY/$IMAGE_SERVER $REGISTRY/$IMAGE_CACHE $REGISTRY/$IMAGE_DB > build.json - printf '{"ImageServerUri":"%s", "ImageCacheUri":"%s", "ImageDatabaseUri":"%s"}' $IMAGE_SERVER_URI $IMAGE_CACHE_URI $IMAGE_DB_URI > build.json
artifacts: artifacts:
files: build.json files: build.json
Environment: Environment:
ComputeType: BUILD_GENERAL1_SMALL ComputeType: BUILD_GENERAL1_SMALL
# Image: aws/codebuild/docker:17.09.0
Image: aws/codebuild/standard:5.0 Image: aws/codebuild/standard:5.0
Type: LINUX_CONTAINER Type: LINUX_CONTAINER
PrivilegedMode: true PrivilegedMode: true
@ -206,14 +199,12 @@ Resources:
# Value: !Ref AWS::AccountId # Value: !Ref AWS::AccountId
- Name: REGISTRY - Name: REGISTRY
Value: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com Value: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com
- Name: REPO_SERVER - Name: IMAGE_SERVER_URI
Value: !Ref ServerRepository Value: !Sub ${ServerRepository.RepositoryUri}:latest
- Name: REPO_CACHE - Name: IMAGE_CACHE_URI
Value: !Ref CacheRepository Value: !Sub ${CacheRepository.RepositoryUri}:latest
- Name: REPO_DB - Name: IMAGE_DB_URI
Value: !Ref DatabaseRepository Value: !Sub ${DatabaseRepository.RepositoryUri}:latest
- Name: IMAGE_TAG
Value: latest
Name: !Ref AWS::StackName Name: !Ref AWS::StackName
ServiceRole: !Ref CodeBuildServiceRole ServiceRole: !Ref CodeBuildServiceRole
@ -246,7 +237,7 @@ Resources:
RunOrder: 1 RunOrder: 1
# Now we deploy the network resources: VPC, subnets, etc. # Now we deploy the network resources: VPC, subnets, etc.
- Name: NetworkResources - Name: Network
Actions: Actions:
- Name: Deploy - Name: Deploy
ActionTypeId: ActionTypeId:
@ -257,7 +248,7 @@ Resources:
Configuration: Configuration:
ActionMode: CREATE_UPDATE ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-NetworkResources StackName: !Sub ${EnvironmentName}-Network
TemplatePath: Source::deployments/network.yml TemplatePath: Source::deployments/network.yml
Capabilities: CAPABILITY_IAM Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | ParameterOverrides: !Sub |
@ -267,12 +258,14 @@ Resources:
InputArtifacts: InputArtifacts:
- Name: Source - Name: Source
OutputArtifacts: OutputArtifacts:
- Name: NetworkResources - Name: Network
# Deploy the base resources: RabbitMQ, Redis, and Postgres # Deploy the base resources: databases, the load balancer,
# and the Fargate cluster
- Name: BaseResources - Name: BaseResources
Actions: Actions:
- Name: Deploy # Deploy the resources: Rabbit, Redis, and Postgres
- Name: DeployResources
ActionTypeId: ActionTypeId:
Category: Deploy Category: Deploy
Owner: AWS Owner: AWS
@ -281,7 +274,7 @@ Resources:
Configuration: Configuration:
ActionMode: CREATE_UPDATE ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-BaseResources StackName: !Sub ${EnvironmentName}-Resources
TemplatePath: Source::deployments/resources.yml TemplatePath: Source::deployments/resources.yml
Capabilities: CAPABILITY_IAM Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | ParameterOverrides: !Sub |
@ -291,12 +284,10 @@ Resources:
InputArtifacts: InputArtifacts:
- Name: Source - Name: Source
OutputArtifacts: OutputArtifacts:
- Name: BaseResources - Name: Resources
# Deploy the application load balancer # Deploy the application load balancer
- Name: LoadBalancerResources - Name: DeployLoadBalancer
Actions:
- Name: Deploy
ActionTypeId: ActionTypeId:
Category: Deploy Category: Deploy
Owner: AWS Owner: AWS
@ -305,7 +296,7 @@ Resources:
Configuration: Configuration:
ActionMode: CREATE_UPDATE ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-LoadBalancerResources StackName: !Sub ${EnvironmentName}-LoadBalancer
TemplatePath: Source::deployments/alb.yml TemplatePath: Source::deployments/alb.yml
Capabilities: CAPABILITY_IAM Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | ParameterOverrides: !Sub |
@ -315,13 +306,10 @@ Resources:
InputArtifacts: InputArtifacts:
- Name: Source - Name: Source
OutputArtifacts: OutputArtifacts:
- Name: LoadBalancerResources - Name: LoadBalancer
# And deploy the cluster resources
- Name: ClusterResources
Actions:
# Deploy the Fargate cluster # Deploy the Fargate cluster
- Name: Deploy - Name: DeployCluster
ActionTypeId: ActionTypeId:
Category: Deploy Category: Deploy
Owner: AWS Owner: AWS
@ -330,7 +318,7 @@ Resources:
Configuration: Configuration:
ActionMode: CREATE_UPDATE ActionMode: CREATE_UPDATE
RoleArn: !GetAtt CloudFormationDeployRole.Arn RoleArn: !GetAtt CloudFormationDeployRole.Arn
StackName: !Sub ${EnvironmentName}-ClusterResources StackName: !Sub ${EnvironmentName}-Cluster
TemplatePath: Source::deployments/cluster-fargate.yml TemplatePath: Source::deployments/cluster-fargate.yml
Capabilities: CAPABILITY_IAM Capabilities: CAPABILITY_IAM
ParameterOverrides: !Sub | ParameterOverrides: !Sub |
@ -340,9 +328,11 @@ Resources:
InputArtifacts: InputArtifacts:
- Name: Source - Name: Source
OutputArtifacts: OutputArtifacts:
- Name: ClusterResources - Name: Cluster
# Now we build the service images # Now we build the service images
- Name: ServiceImages
Actions:
- Name: Build - Name: Build
ActionTypeId: ActionTypeId:
Category: Build Category: Build
@ -377,7 +367,7 @@ Resources:
{ {
"EnvironmentName": "${EnvironmentName}", "EnvironmentName": "${EnvironmentName}",
"ImageUrl": { "ImageUrl": {
"Fn::GetParam" : ["BuildOutput", "build.json", "ImageServer"] "Fn::GetParam" : ["BuildOutput", "build.json", "ImageServerUri"]
} }
} }
InputArtifacts: InputArtifacts:
@ -401,7 +391,7 @@ Resources:
{ {
"EnvironmentName": "${EnvironmentName}", "EnvironmentName": "${EnvironmentName}",
"ImageUrl": { "ImageUrl": {
"Fn::GetParam" : ["BuildOutput", "build.json", "ImageCache"] "Fn::GetParam" : ["BuildOutput", "build.json", "ImageCacheUri"]
} }
} }
InputArtifacts: InputArtifacts:
@ -425,7 +415,7 @@ Resources:
{ {
"EnvironmentName": "${EnvironmentName}", "EnvironmentName": "${EnvironmentName}",
"ImageUrl": { "ImageUrl": {
"Fn::GetParam" : ["BuildOutput", "build.json", "ImageDatabase"] "Fn::GetParam" : ["BuildOutput", "build.json", "ImageDatabaseUri"]
} }
} }
InputArtifacts: InputArtifacts: