Commit 50e70f47 authored by Etienne Baqué's avatar Etienne Baqué Committed by Thong Kuah

Add Deployment to ECS process to AutoDevOps

Adds ECS deployment jobs
to Jobs/Deploy template.
parent 7e18aef5
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
.card-footer.js-extra-settings{ class: auto_devops_enabled || 'hidden' } .card-footer.js-extra-settings{ class: auto_devops_enabled || 'hidden' }
- if @project.all_clusters.empty? - if @project.all_clusters.empty?
%p.settings-message.text-center %p.settings-message.text-center
= s_('CICD|You must add a %{kubernetes_cluster_link_start}Kubernetes cluster integration%{link_end} to this project with a domain in order for your deployment strategy to work correctly.').html_safe % { kubernetes_cluster_link_start: kubernetes_cluster_link_start, link_end: link_end } = s_('CICD|Add a %{kubernetes_cluster_link_start}Kubernetes cluster integration%{link_end} with a domain or create an AUTO_DEVOPS_PLATFORM_TARGET CI variable.').html_safe % { kubernetes_cluster_link_start: kubernetes_cluster_link_start, link_end: link_end }
- elsif !has_base_domain - elsif !has_base_domain
%p.settings-message.text-center %p.settings-message.text-center
= s_('CICD|You must add a %{base_domain_link_start}base domain%{link_end} to your %{kubernetes_cluster_link_start}Kubernetes cluster%{link_end} in order for your deployment strategy to work.').html_safe % { base_domain_link_start: base_domain_link_start, kubernetes_cluster_link_start: kubernetes_cluster_link_start, link_end: link_end } = s_('CICD|You must add a %{base_domain_link_start}base domain%{link_end} to your %{kubernetes_cluster_link_start}Kubernetes cluster%{link_end} in order for your deployment strategy to work.').html_safe % { base_domain_link_start: base_domain_link_start, kubernetes_cluster_link_start: kubernetes_cluster_link_start, link_end: link_end }
......
---
title: Add Deployment to ECS process to AutoDevOps
merge_request: 29971
author:
type: added
...@@ -53,6 +53,9 @@ If you use a self-managed instance of GitLab, you must configure the ...@@ -53,6 +53,9 @@ If you use a self-managed instance of GitLab, you must configure the
configuring a cluster on GKE. After configuring the provider, you can follow configuring a cluster on GKE. After configuring the provider, you can follow
the steps in the [quick start guide](quick_start_guide.md) to get started. the steps in the [quick start guide](quick_start_guide.md) to get started.
In [GitLab 13.0](https://gitlab.com/gitlab-org/gitlab/-/issues/208132) and later, it is
possible to leverage Auto DevOps to deploy to [AWS ECS](#aws-ecs).
## Comparison to application platforms and PaaS ## Comparison to application platforms and PaaS
Auto DevOps provides features often included in an application Auto DevOps provides features often included in an application
...@@ -110,7 +113,9 @@ Auto DevOps. ...@@ -110,7 +113,9 @@ Auto DevOps.
## Requirements ## Requirements
To make full use of Auto DevOps, you need: ### Kubernetes
To make full use of Auto DevOps with Kubernetes, you need:
- **Kubernetes** (for [Auto Review Apps](stages.md#auto-review-apps), - **Kubernetes** (for [Auto Review Apps](stages.md#auto-review-apps),
[Auto Deploy](stages.md#auto-deploy), and [Auto Monitoring](stages.md#auto-monitoring)) [Auto Deploy](stages.md#auto-deploy), and [Auto Monitoring](stages.md#auto-monitoring))
...@@ -202,6 +207,31 @@ are skipped. ...@@ -202,6 +207,31 @@ are skipped.
After all requirements are met, you can [enable Auto DevOps](#enablingdisabling-auto-devops). After all requirements are met, you can [enable Auto DevOps](#enablingdisabling-auto-devops).
### AWS ECS
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/208132) in GitLab 13.0.
You can choose to target [AWS ECS](../../ci/cloud_deployment/index.md) as a deployment platform instead of using Kubernetes.
To get started on Auto DevOps to ECS, you'll have to add a specific Environment
Variable. To do so, follow these steps:
1. In your project, go to **Settings > CI / CD** and expand the **Variables**
section.
1. Specify which AWS platform to target during the Auto DevOps deployment
by adding the `AUTO_DEVOPS_PLATFORM_TARGET` variable.
1. Give this variable the value `ECS` before saving it.
When you trigger a pipeline, if you have AutoDev Ops enabled and if you have correctly
[entered AWS credentials as environment variables](../../ci/cloud_deployment/index.md#deploy-your-application-to-aws-elastic-container-service-ecs),
your application will be deployed to AWS ECS.
NOTE: **Note:**
If you have both a valid `AUTO_DEVOPS_PLATFORM_TARGET` variable and a Kubernetes cluster tied to your project,
only the deployment to Kubernetes will run.
## Auto DevOps base domain ## Auto DevOps base domain
The Auto DevOps base domain is required to use The Auto DevOps base domain is required to use
......
...@@ -5,6 +5,9 @@ stages: ...@@ -5,6 +5,9 @@ stages:
- deploy - deploy
- production - production
variables:
AUTO_DEVOPS_PLATFORM_TARGET: ECS
include: include:
- template: Jobs/Build.gitlab-ci.yml - template: Jobs/Build.gitlab-ci.yml
- template: Jobs/Deploy/ECS.gitlab-ci.yml - template: Jobs/Deploy/ECS.gitlab-ci.yml
.auto-deploy: .auto-deploy:
image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image:v0.15.0" image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image:v0.15.0"
include:
- template: Jobs/Deploy/ECS.gitlab-ci.yml
review: review:
extends: .auto-deploy extends: .auto-deploy
stage: review stage: review
......
.deploy_to_ecs: .deploy_to_ecs:
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-ecs:latest image: 'registry.gitlab.com/gitlab-org/cloud-deploy/aws-ecs:latest'
script: script:
- ecs update-task-definition - ecs update-task-definition
review: review_ecs:
extends: .deploy_to_ecs extends: .deploy_to_ecs
stage: review stage: review
environment: environment:
name: review/$CI_COMMIT_REF_NAME name: review/$CI_COMMIT_REF_NAME
only: rules:
refs: - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
- branches when: never
- tags - if: '$CI_KUBERNETES_ACTIVE'
except: when: never
refs: - if: '$REVIEW_DISABLED'
- master when: never
- if: '$CI_COMMIT_BRANCH != "master"'
production: production_ecs:
extends: .deploy_to_ecs extends: .deploy_to_ecs
stage: production stage: production
environment: environment:
name: production name: production
only: rules:
refs: - if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
- master when: never
- if: '$CI_KUBERNETES_ACTIVE'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
...@@ -3569,6 +3569,9 @@ msgstr "" ...@@ -3569,6 +3569,9 @@ msgstr ""
msgid "CI/CD settings" msgid "CI/CD settings"
msgstr "" msgstr ""
msgid "CICD|Add a %{kubernetes_cluster_link_start}Kubernetes cluster integration%{link_end} with a domain or create an AUTO_DEVOPS_PLATFORM_TARGET CI variable."
msgstr ""
msgid "CICD|Auto DevOps" msgid "CICD|Auto DevOps"
msgstr "" msgstr ""
...@@ -3599,9 +3602,6 @@ msgstr "" ...@@ -3599,9 +3602,6 @@ msgstr ""
msgid "CICD|You must add a %{base_domain_link_start}base domain%{link_end} to your %{kubernetes_cluster_link_start}Kubernetes cluster%{link_end} in order for your deployment strategy to work." msgid "CICD|You must add a %{base_domain_link_start}base domain%{link_end} to your %{kubernetes_cluster_link_start}Kubernetes cluster%{link_end} in order for your deployment strategy to work."
msgstr "" msgstr ""
msgid "CICD|You must add a %{kubernetes_cluster_link_start}Kubernetes cluster integration%{link_end} to this project with a domain in order for your deployment strategy to work correctly."
msgstr ""
msgid "CICD|group enabled" msgid "CICD|group enabled"
msgstr "" msgstr ""
......
...@@ -20,23 +20,101 @@ describe 'Auto-DevOps.gitlab-ci.yml' do ...@@ -20,23 +20,101 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
allow(project).to receive(:default_branch).and_return(default_branch) allow(project).to receive(:default_branch).and_return(default_branch)
end end
shared_examples 'no Kubernetes deployment job' do
it 'does not create any Kubernetes deployment-related builds' do
expect(build_names).not_to include('production')
expect(build_names).not_to include('production_manual')
expect(build_names).not_to include('staging')
expect(build_names).not_to include('canary')
expect(build_names).not_to include('review')
expect(build_names).not_to include(a_string_matching(/rollout \d+%/))
end
end
it 'creates a build and a test job' do it 'creates a build and a test job' do
expect(build_names).to include('build', 'test') expect(build_names).to include('build', 'test')
end end
context 'when the project is set for deployment to AWS' do
let(:platform_value) { 'ECS' }
before do
create(:ci_variable, project: project, key: 'AUTO_DEVOPS_PLATFORM_TARGET', value: platform_value)
end
shared_examples 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do |job_name|
context 'when AUTO_DEVOPS_PLATFORM_TARGET is nil' do
let(:platform_value) { nil }
it 'does not trigger the job' do
expect(build_names).not_to include(job_name)
end
end
context 'when AUTO_DEVOPS_PLATFORM_TARGET is empty' do
let(:platform_value) { '' }
it 'does not trigger the job' do
expect(build_names).not_to include(job_name)
end
end
end
it_behaves_like 'no Kubernetes deployment job'
it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do
let(:job_name) { 'production_ecs' }
end
it 'creates an ECS deployment job for production only' do
expect(build_names).not_to include('review_ecs')
expect(build_names).to include('production_ecs')
end
context 'and we are not on the default branch' do
let(:platform_value) { 'ECS' }
let(:pipeline_branch) { 'patch-1' }
before do
project.repository.create_branch(pipeline_branch)
end
it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do
let(:job_name) { 'review_ecs' }
end
it 'creates an ECS deployment job for review only' do
expect(build_names).to include('review_ecs')
expect(build_names).not_to include('production_ecs')
expect(build_names).not_to include('review')
expect(build_names).not_to include('production')
end
end
context 'and when the project has an active cluster' do
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
before do
allow(cluster).to receive(:active?).and_return(true)
end
context 'on default branch' do
it 'triggers the deployment to Kubernetes, not to ECS' do
expect(build_names).not_to include('review')
expect(build_names).to include('production')
expect(build_names).not_to include('production_ecs')
expect(build_names).not_to include('review_ecs')
end
end
end
end
context 'when the project has no active cluster' do context 'when the project has no active cluster' do
it 'only creates a build and a test stage' do it 'only creates a build and a test stage' do
expect(pipeline.stages_names).to eq(%w(build test)) expect(pipeline.stages_names).to eq(%w(build test))
end end
it 'does not create any deployment-related builds' do it_behaves_like 'no Kubernetes deployment job'
expect(build_names).not_to include('production')
expect(build_names).not_to include('production_manual')
expect(build_names).not_to include('staging')
expect(build_names).not_to include('canary')
expect(build_names).not_to include('review')
expect(build_names).not_to include(a_string_matching(/rollout \d+%/))
end
end end
context 'when the project has an active cluster' do context 'when the project has an active cluster' do
......
...@@ -13,7 +13,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do ...@@ -13,7 +13,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do
it 'shows a warning message about Kubernetes cluster' do it 'shows a warning message about Kubernetes cluster' do
render render
expect(rendered).to have_text('You must add a Kubernetes cluster integration to this project with a domain in order for your deployment strategy to work correctly.') expect(rendered).to have_text('Add a Kubernetes cluster integration with a domain or create an AUTO_DEVOPS_PLATFORM_TARGET CI variable')
end end
context 'when the project has an available kubernetes cluster' do context 'when the project has an available kubernetes cluster' do
......
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