From 4edbc050981c5c6b689b84679f7bca4ae352eff3 Mon Sep 17 00:00:00 2001 From: ebosas Date: Sat, 6 Nov 2021 14:25:48 +0200 Subject: [PATCH] Separate pipelines for each service --- deployments/buildspec/service.yml | 16 ---------- deployments/buildspec/services-all.yml | 22 ------------- deployments/pipeline-services.yml | 24 +++++++++++--- deployments/pipeline.yml | 38 ++++++++++++++++++++--- deployments/resources.yml | 6 ++-- deployments/services-ecs/cache.yml | 4 +-- deployments/services-ecs/database.yml | 4 +-- deployments/services-ecs/server.yml | 4 +-- deployments/services-fargate/cache.yml | 4 +-- deployments/services-fargate/database.yml | 4 +-- deployments/services-fargate/server.yml | 4 +-- 11 files changed, 69 insertions(+), 61 deletions(-) delete mode 100644 deployments/buildspec/service.yml delete mode 100644 deployments/buildspec/services-all.yml diff --git a/deployments/buildspec/service.yml b/deployments/buildspec/service.yml deleted file mode 100644 index 5f9dd49..0000000 --- a/deployments/buildspec/service.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 0.2 -phases: - pre_build: - commands: - - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com - - TAG=$(echo $GIT_COMMIT_ID | head -c 8) - - IMAGE_URI=$REPO_URI:$TAG - build: - commands: - - docker build -t $IMAGE_URI -f server.Dockerfile . - post_build: - commands: - - docker push $IMAGE_URI - - printf '{"ImageUri":"%s"}' $IMAGE_URI > build.json -artifacts: - files: build.json \ No newline at end of file diff --git a/deployments/buildspec/services-all.yml b/deployments/buildspec/services-all.yml deleted file mode 100644 index a1426d7..0000000 --- a/deployments/buildspec/services-all.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: 0.2 -phases: - pre_build: - commands: - - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com - - TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8) - - IMAGE_SERVER_URI=$REPO_SERVER_URI:$TAG - - IMAGE_CACHE_URI=$REPO_CACHE_URI:$TAG - - IMAGE_DB_URI=$REPO_DB_URI:$TAG - build: - commands: - - docker build -t $IMAGE_SERVER_URI -f server.Dockerfile . - - docker build -t $IMAGE_CACHE_URI -f cache.Dockerfile . - - docker build -t $IMAGE_DB_URI -f database.Dockerfile . - post_build: - commands: - - docker push $IMAGE_SERVER_URI - - docker push $IMAGE_CACHE_URI - - docker push $IMAGE_DB_URI - - printf '{"ImageServerUri":"%s", "ImageCacheUri":"%s", "ImageDatabaseUri":"%s"}' $IMAGE_SERVER_URI $IMAGE_CACHE_URI $IMAGE_DB_URI > build.json -artifacts: - files: build.json \ No newline at end of file diff --git a/deployments/pipeline-services.yml b/deployments/pipeline-services.yml index ca3e2f9..bd523b2 100644 --- a/deployments/pipeline-services.yml +++ b/deployments/pipeline-services.yml @@ -170,15 +170,31 @@ Resources: Properties: Artifacts: Type: CODEPIPELINE - ServiceRole: !Ref CodeBuildServiceRole + Source: + Type: CODEPIPELINE + BuildSpec: | + version: 0.2 + phases: + pre_build: + commands: + - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com + - TAG=$(echo $GIT_COMMIT_ID | head -c 8) + - IMAGE_URI=$REPO_URI:$TAG + build: + commands: + - docker build -t $IMAGE_URI -f server.Dockerfile . + post_build: + commands: + - docker push $IMAGE_URI + - printf '{"ImageUri":"%s"}' $IMAGE_URI > build.json + artifacts: + files: build.json Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 Type: LINUX_CONTAINER PrivilegedMode: true - Source: - Type: CODEPIPELINE - BuildSpec: deployments/buildspec/service.yml + ServiceRole: !Ref CodeBuildServiceRole # Create three pipelines for the three services # Server pipeline diff --git a/deployments/pipeline.yml b/deployments/pipeline.yml index 86daa5a..753fd94 100644 --- a/deployments/pipeline.yml +++ b/deployments/pipeline.yml @@ -19,14 +19,20 @@ Resources: # Create ECR respositories to hold built docker images ServerRepository: Type: AWS::ECR::Repository + DeletionPolicy: Retain + UpdateReplacePolicy: Retain Properties: RepositoryName: !Sub ${EnvironmentName}-server CacheRepository: Type: AWS::ECR::Repository + DeletionPolicy: Retain + UpdateReplacePolicy: Retain Properties: RepositoryName: !Sub ${EnvironmentName}-cache DatabaseRepository: Type: AWS::ECR::Repository + DeletionPolicy: Retain + UpdateReplacePolicy: Retain Properties: RepositoryName: !Sub ${EnvironmentName}-database @@ -161,6 +167,8 @@ Resources: # While the build is in progress we need a place to store artifacts ArtifactBucket: Type: AWS::S3::Bucket + DeletionPolicy: Retain + UpdateReplacePolicy: Retain Properties: BucketName: !Sub ${EnvironmentName}-${AWS::AccountId} @@ -170,15 +178,37 @@ Resources: Properties: Artifacts: Type: CODEPIPELINE - ServiceRole: !Ref CodeBuildServiceRole + Source: + Type: CODEPIPELINE + BuildSpec: | + version: 0.2 + phases: + pre_build: + commands: + - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com + - TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8) + - IMAGE_SERVER_URI=$REPO_SERVER_URI:$TAG + - IMAGE_CACHE_URI=$REPO_CACHE_URI:$TAG + - IMAGE_DB_URI=$REPO_DB_URI:$TAG + build: + commands: + - docker build -t $IMAGE_SERVER_URI -f server.Dockerfile . + - docker build -t $IMAGE_CACHE_URI -f cache.Dockerfile . + - docker build -t $IMAGE_DB_URI -f database.Dockerfile . + post_build: + commands: + - docker push $IMAGE_SERVER_URI + - docker push $IMAGE_CACHE_URI + - docker push $IMAGE_DB_URI + - printf '{"ImageServerUri":"%s", "ImageCacheUri":"%s", "ImageDatabaseUri":"%s"}' $IMAGE_SERVER_URI $IMAGE_CACHE_URI $IMAGE_DB_URI > build.json + artifacts: + files: build.json Environment: ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 Type: LINUX_CONTAINER PrivilegedMode: true - Source: - Type: CODEPIPELINE - BuildSpec: deployments/buildspec/services-all.yml + ServiceRole: !Ref CodeBuildServiceRole # This pipeline defines the steps to build, deploy, and release the application Pipeline: diff --git a/deployments/resources.yml b/deployments/resources.yml index 7af4c1a..ef470c2 100644 --- a/deployments/resources.yml +++ b/deployments/resources.yml @@ -151,7 +151,7 @@ Resources: RabbitURLParameter: Type: AWS::SSM::Parameter Properties: - Name: !Sub /microservices/${EnvironmentName}/rabbiturl + Name: /Microservices/RabbitUrl Type: String Description: A connection string for RabbitMQ Value: @@ -162,7 +162,7 @@ Resources: PostgresURLParameter: Type: AWS::SSM::Parameter Properties: - Name: !Sub /microservices/${EnvironmentName}/postgresurl + Name: /Microservices/PostgresUrl Type: String Description: A connection string for Postgres Value: @@ -173,7 +173,7 @@ Resources: RedisURLParameter: Type: AWS::SSM::Parameter Properties: - Name: !Sub /microservices/${EnvironmentName}/redisurl + Name: /Microservices/RedisUrl Type: String Description: A connection string for Redis Value: !Sub ${Redis.RedisEndpoint.Address}:${Redis.RedisEndpoint.Port} diff --git a/deployments/services-ecs/cache.yml b/deployments/services-ecs/cache.yml index df5121f..d9651a5 100644 --- a/deployments/services-ecs/cache.yml +++ b/deployments/services-ecs/cache.yml @@ -68,9 +68,9 @@ Resources: awslogs-stream-prefix: !Ref 'ServiceName' Environment: - Name: RABBIT_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/rabbiturl}}' + Value: '{{resolve:ssm:/Microservices/RabbitUrl}}' - Name: REDIS_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/redisurl}}' + Value: '{{resolve:ssm:/Microservices/RedisUrl}}' # The service. The service is a resource which allows you to run multiple # copies of a type of task, and gather up their logs and metrics, as well diff --git a/deployments/services-ecs/database.yml b/deployments/services-ecs/database.yml index 78e8c4f..4aa0500 100644 --- a/deployments/services-ecs/database.yml +++ b/deployments/services-ecs/database.yml @@ -68,9 +68,9 @@ Resources: awslogs-stream-prefix: !Ref 'ServiceName' Environment: - Name: RABBIT_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/rabbiturl}}' + Value: '{{resolve:ssm:/Microservices/RabbitUrl}}' - Name: POSTGRES_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/postgresurl}}' + Value: '{{resolve:ssm:/Microservices/PostgresUrl}}' # The service. The service is a resource which allows you to run multiple # copies of a type of task, and gather up their logs and metrics, as well diff --git a/deployments/services-ecs/server.yml b/deployments/services-ecs/server.yml index a9ba40c..16e4b5c 100644 --- a/deployments/services-ecs/server.yml +++ b/deployments/services-ecs/server.yml @@ -86,9 +86,9 @@ Resources: awslogs-stream-prefix: !Ref 'ServiceName' Environment: - Name: RABBIT_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/rabbiturl}}' + Value: '{{resolve:ssm:/Microservices/RabbitUrl}}' - Name: REDIS_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/redisurl}}' + Value: '{{resolve:ssm:/Microservices/RedisUrl}}' - Name: SERVER_ADDR Value: 0.0.0.0:80 diff --git a/deployments/services-fargate/cache.yml b/deployments/services-fargate/cache.yml index df7a318..d1affd1 100644 --- a/deployments/services-fargate/cache.yml +++ b/deployments/services-fargate/cache.yml @@ -73,9 +73,9 @@ Resources: awslogs-stream-prefix: !Ref 'ServiceName' Environment: - Name: RABBIT_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/rabbiturl}}' + Value: '{{resolve:ssm:/Microservices/RabbitUrl}}' - Name: REDIS_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/redisurl}}' + Value: '{{resolve:ssm:/Microservices/RedisUrl}}' # The service. The service is a resource which allows you to run multiple # copies of a type of task, and gather up their logs and metrics, as well diff --git a/deployments/services-fargate/database.yml b/deployments/services-fargate/database.yml index f1849b3..9285c18 100644 --- a/deployments/services-fargate/database.yml +++ b/deployments/services-fargate/database.yml @@ -73,9 +73,9 @@ Resources: awslogs-stream-prefix: !Ref 'ServiceName' Environment: - Name: RABBIT_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/rabbiturl}}' + Value: '{{resolve:ssm:/Microservices/RabbitUrl}}' - Name: POSTGRES_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/postgresurl}}' + Value: '{{resolve:ssm:/Microservices/PostgresUrl}}' # The service. The service is a resource which allows you to run multiple # copies of a type of task, and gather up their logs and metrics, as well diff --git a/deployments/services-fargate/server.yml b/deployments/services-fargate/server.yml index 4bea386..c944240 100644 --- a/deployments/services-fargate/server.yml +++ b/deployments/services-fargate/server.yml @@ -91,9 +91,9 @@ Resources: awslogs-stream-prefix: !Ref 'ServiceName' Environment: - Name: RABBIT_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/rabbiturl}}' + Value: '{{resolve:ssm:/Microservices/RabbitUrl}}' - Name: REDIS_URL - Value: !Sub '{{resolve:ssm:/microservices/${EnvironmentName}/redisurl}}' + Value: '{{resolve:ssm:/Microservices/RedisUrl}}' - Name: SERVER_ADDR Value: 0.0.0.0:80