Commit 581ef7c5 authored by Thong Kuah's avatar Thong Kuah

Merge branch '208132-add-ecs-to-autodeploy' into 'master'

Moved Deploy template content into its own Kubernetes yaml

Closes #208132

See merge request gitlab-org/gitlab!29971
parents 796a4f4c 50e70f47
......@@ -30,7 +30,7 @@
.card-footer.js-extra-settings{ class: auto_devops_enabled || 'hidden' }
- if @project.all_clusters.empty?
%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
%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 }
......
---
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
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.
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
Auto DevOps provides features often included in an application
......@@ -110,7 +113,9 @@ Auto DevOps.
## 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),
[Auto Deploy](stages.md#auto-deploy), and [Auto Monitoring](stages.md#auto-monitoring))
......@@ -202,6 +207,31 @@ are skipped.
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
The Auto DevOps base domain is required to use
......
......@@ -5,6 +5,9 @@ stages:
- deploy
- production
variables:
AUTO_DEVOPS_PLATFORM_TARGET: ECS
include:
- template: Jobs/Build.gitlab-ci.yml
- template: Jobs/Deploy/ECS.gitlab-ci.yml
.auto-deploy:
image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image:v0.15.0"
include:
- template: Jobs/Deploy/ECS.gitlab-ci.yml
review:
extends: .auto-deploy
stage: review
......
.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:
- ecs update-task-definition
review:
review_ecs:
extends: .deploy_to_ecs
stage: review
environment:
name: review/$CI_COMMIT_REF_NAME
only:
refs:
- branches
- tags
except:
refs:
- master
rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
when: never
- if: '$CI_KUBERNETES_ACTIVE'
when: never
- if: '$REVIEW_DISABLED'
when: never
- if: '$CI_COMMIT_BRANCH != "master"'
production:
production_ecs:
extends: .deploy_to_ecs
stage: production
environment:
name: production
only:
refs:
- master
rules:
- if: '$AUTO_DEVOPS_PLATFORM_TARGET != "ECS"'
when: never
- if: '$CI_KUBERNETES_ACTIVE'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
......@@ -3569,6 +3569,9 @@ msgstr ""
msgid "CI/CD settings"
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"
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."
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"
msgstr ""
......
......@@ -20,23 +20,101 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
allow(project).to receive(:default_branch).and_return(default_branch)
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
expect(build_names).to include('build', 'test')
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
it 'only creates a build and a test stage' do
expect(pipeline.stages_names).to eq(%w(build test))
end
it 'does not create any 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
it_behaves_like 'no Kubernetes deployment job'
end
context 'when the project has an active cluster' do
......
......@@ -13,7 +13,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do
it 'shows a warning message about Kubernetes cluster' do
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
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