Commit e3135392 authored by Etienne Baqué's avatar Etienne Baqué

Added Fargate related jobs

Extended Deploy/ECS template.
Added rspecs accordingly.
Updated documentation.
parent d20e41ca
---
title: Extend ECS Deploy template with Fargate jobs
merge_request: 35173
author:
type: added
...@@ -112,9 +112,9 @@ Variable. To do so, follow these steps: ...@@ -112,9 +112,9 @@ Variable. To do so, follow these steps:
section. section.
1. Specify which AWS platform to target during the Auto DevOps deployment 1. Specify which AWS platform to target during the Auto DevOps deployment
by adding the `AUTO_DEVOPS_PLATFORM_TARGET` variable. by adding the `AUTO_DEVOPS_PLATFORM_TARGET` variable with one of the following values:
- `FARGATE` if the service you're targeting must be of launch type FARGATE.
1. Give this variable the value `ECS` before saving it. - `ECS` if you're not enforcing any launch type check when deploying to ECS.
When you trigger a pipeline, if Auto DevOps is enabled and if you've correctly When you trigger a pipeline, if Auto DevOps is enabled and if you've correctly
[entered AWS credentials as environment variables](../../ci/cloud_deployment/index.md#deploy-your-application-to-the-aws-elastic-container-service-ecs), [entered AWS credentials as environment variables](../../ci/cloud_deployment/index.md#deploy-your-application-to-the-aws-elastic-container-service-ecs),
......
...@@ -13,11 +13,20 @@ ...@@ -13,11 +13,20 @@
script: script:
- ecs update-task-definition - ecs update-task-definition
review_ecs: .review_ecs_base:
extends: .deploy_to_ecs
stage: review stage: review
extends: .deploy_to_ecs
environment: environment:
name: review/$CI_COMMIT_REF_NAME name: review/$CI_COMMIT_REF_NAME
.production_ecs_base:
stage: production
extends: .deploy_to_ecs
environment:
name: production
review_ecs:
extends: .review_ecs_base
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
when: never when: never
...@@ -29,11 +38,21 @@ review_ecs: ...@@ -29,11 +38,21 @@ review_ecs:
when: never when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
review_fargate:
extends: .review_ecs_base
rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"'
when: never
- if: '$CI_KUBERNETES_ACTIVE'
when: never
- if: '$REVIEW_DISABLED'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
production_ecs: production_ecs:
extends: .deploy_to_ecs extends: .production_ecs_base
stage: production
environment:
name: production
rules: rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"' - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
when: never when: never
...@@ -42,3 +61,14 @@ production_ecs: ...@@ -42,3 +61,14 @@ production_ecs:
- if: '$CI_COMMIT_BRANCH != "master"' - if: '$CI_COMMIT_BRANCH != "master"'
when: never when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
production_fargate:
extends: .production_ecs_base
rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "FARGATE"'
when: never
- if: '$CI_KUBERNETES_ACTIVE'
when: never
- if: '$CI_COMMIT_BRANCH != "master"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
...@@ -37,6 +37,7 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do ...@@ -37,6 +37,7 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do
context 'when the project is set for deployment to AWS' do context 'when the project is set for deployment to AWS' do
let(:platform_value) { 'ECS' } let(:platform_value) { 'ECS' }
let(:review_prod_build_names) { build_names.select {|n| n.include?('review') || n.include?('production')} }
before do before do
create(:ci_variable, project: project, key: 'AUTO_DEVOPS_PLATFORM_TARGET', value: platform_value) create(:ci_variable, project: project, key: 'AUTO_DEVOPS_PLATFORM_TARGET', value: platform_value)
...@@ -67,8 +68,15 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do ...@@ -67,8 +68,15 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do
end end
it 'creates an ECS deployment job for production only' do it 'creates an ECS deployment job for production only' do
expect(build_names).not_to include('review_ecs') expect(review_prod_build_names).to contain_exactly('production_ecs')
expect(build_names).to include('production_ecs') end
context 'with FARGATE as a launch type' do
let(:platform_value) { 'FARGATE' }
it 'creates a FARGATE deployment job for production only' do
expect(review_prod_build_names).to contain_exactly('production_fargate')
end
end end
context 'and we are not on the default branch' do context 'and we are not on the default branch' do
...@@ -79,15 +87,22 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do ...@@ -79,15 +87,22 @@ RSpec.describe 'Auto-DevOps.gitlab-ci.yml' do
project.repository.create_branch(pipeline_branch) project.repository.create_branch(pipeline_branch)
end end
%w(review_ecs review_fargate).each do |job|
it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do
let(:job_name) { 'review_ecs' } let(:job_name) { job }
end
end end
it 'creates an ECS deployment job for review only' do it 'creates an ECS deployment job for review only' do
expect(build_names).to include('review_ecs') expect(review_prod_build_names).to contain_exactly('review_ecs')
expect(build_names).not_to include('production_ecs') end
expect(build_names).not_to include('review')
expect(build_names).not_to include('production') context 'with FARGATE as a launch type' do
let(:platform_value) { 'FARGATE' }
it 'creates an FARGATE deployment job for review only' do
expect(review_prod_build_names).to contain_exactly('review_fargate')
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment