Skip to content

Templates for EC2 deployment and provisioning via CF

Etienne Baqué requested to merge 201742-ec2-templates into master

What does this MR do?

This MR introduces a new template named AWS/CF_Provision_and_Deploy_EC2.gitlab-ci.yml that allows for the creation of a new stack on AWS CloudFormation and the deployment of an application to EC2, following what's described in this diagram:

Screenshot_from_2020-09-25_17-08-12

Scripts can be found in this CloudDeploy's MR: cloud-deploy!25 (merged)

Manual testing and screenshots

We'll be using a Jekyll sample application to test the new template. Jekyll websites can be deployed out-of-the-box with GitLab Pages. For the sake of testing, we removed everything related to GitLab Pages from the project's .gitlab-ci.yml file, and added our own build and review stages.

The template has not merged in yet, so I copy-pasted its content directly in the project's .gitlab-ci.yml (diffs in the original template -for comparison).

1. First commit, provisioning and application deployment

Commit: ebaque/jekyll-demo@8f2abbb3

manual-1-diffs

Pipeline:

Screenshot_from_2020-09-25_10-19-09

(Additional test: 3 stage pipeline):

Screenshot_from_2020-09-28_13-45-37

The review_ec2 job: https://gitlab.com/ebaque/jekyll-demo/-/jobs/757019607 It does the following:

  1. it creates the EC2 stack (via CloudFormation)

manual-3-create-stack

  1. it pushes the code to S3

manual-4-push-s3

  1. it deploys to EC2

manual-5-ec2

Checking the website now:

manual-6-website

2. Second commit and deployment to update application

New commit: ebaque/jekyll-demo@86415f0e

manual-7-diffs

Pipeline: https://gitlab.com/ebaque/jekyll-demo/-/pipelines/194396250

review_ec2 job skips the creation of the stack (fix: removed "Existing job now" here):

manual-8-log

Website:

manual-9-screenshot

3. Trying to provision with an incorrect value in template.

CloudFormation JSON template has an incorrect value:

manual-10-incorrect

review_ec2 job fails when creating new stack:

manual-11-job-failed

manual-12-stack-failed

3. Deploying with incorrect deployment JSON input

We're using now a deployment template that has an incorrect S3 bucket name:

manual-12-incorrect-S3

The review_ec2 job fails, when trying to deploy:

manual-13-log-failed

On CodeDeploy:

manual-14-bucket-failed

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Closes #201742 (closed)

Edited by Etienne Baqué

Merge request reports

Loading