continuous delivery to amazon ec2 container service

40
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Jay Allen, Curriculum Engineering Manager, AWS Training & Certification October 24 th , 2016 Continuous Delivery to Amazon EC2 Container Service

Upload: amazon-web-services

Post on 16-Apr-2017

167 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Continuous Delivery to Amazon EC2 Container Service

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Jay Allen, Curriculum Engineering Manager, AWS Training & Certification

October 24th, 2016

Continuous Delivery to

Amazon EC2 Container

Service

Page 2: Continuous Delivery to Amazon EC2 Container Service
Page 3: Continuous Delivery to Amazon EC2 Container Service

What is continuous delivery?

• Software development practice where code changes are automatically built, tested, and prepared for a release to production.

• Extends continuous integration by deploying all code changes to a testing environment and/or a production environment after the build stage.

• Developers approve the update to production when they are ready.• Different from continuous deployment, where the push to production

happens automatically without explicit approval.

• Continuous delivery lets developers automate testing beyond just unit tests to verify application updates across multiple dimensions before deploying.

Page 4: Continuous Delivery to Amazon EC2 Container Service

Why use containers?

• Process isolation

• Portable

• Fast

• Efficient

Page 5: Continuous Delivery to Amazon EC2 Container Service

Why use containers for continuous delivery?

• Roll out features as quickly as possible

• Predictable and reproducible environment

• Fast feedback

Page 6: Continuous Delivery to Amazon EC2 Container Service

Development and deployment workflow

Code

repository

Build

environment

Test

environmentDeployment

environment

Source

Page 7: Continuous Delivery to Amazon EC2 Container Service

Stage 1 - Source

Page 8: Continuous Delivery to Amazon EC2 Container Service

Development environment

Code

repository

Source

Page 9: Continuous Delivery to Amazon EC2 Container Service

Docker and Docker Toolbox

• Docker (Linux > 3.10)

• Docker Toolbox or Docker Beta (OS X, Windows)

• Define app environment with Dockerfile

Page 10: Continuous Delivery to Amazon EC2 Container Service

Dockerfile

FROM ruby:2.2.2

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev

RUN mkdir -p /opt/web

WORKDIR /tmp

ADD Gemfile /tmp/

ADD Gemfile.lock /tmp/

RUN bundle install

ADD . /opt/web

WORKDIR /opt/web

Page 11: Continuous Delivery to Amazon EC2 Container Service

Docker Compose

Define and run multi-container applications:

1. Define app environment with Dockerfile

2. Define services that make up your app in docker-

compose.yml

3. Run docker-compose up to start and run entire app

Page 12: Continuous Delivery to Amazon EC2 Container Service

docker-compose.yml

proxy:

build: ./proxy

ports:

- "80:80"

links:

- web

web:

build: ./web

command: bundle exec rails server -b 0.0.0.0

environment:

- SECRET_KEY_BASE=secretkey

expose:

- "3000"

Page 13: Continuous Delivery to Amazon EC2 Container Service

Stage 2 - Build

Page 14: Continuous Delivery to Amazon EC2 Container Service

Build environment

Build

environment

Page 15: Continuous Delivery to Amazon EC2 Container Service

Build environment

Containers can be used in two ways:

• Execution environment for the build jobs

• Output of the build process itself

Page 16: Continuous Delivery to Amazon EC2 Container Service

Containers as build execution environment

Page 17: Continuous Delivery to Amazon EC2 Container Service

Containers as build artifacts

Page 18: Continuous Delivery to Amazon EC2 Container Service

Amazon EC2 Container Registry

• Security

• IAM Resource-based Policies

• CloudTrail Audit Logs

• Images encrypted at transit and at rest

• Easily Manage & Deploy Images

• Tight Integration with ECS

• Integration with Docker Toolset

• Management Console & AWS CLI

• Reliability & Performance

• S3 Backed

Page 19: Continuous Delivery to Amazon EC2 Container Service

Stage 3 - Test

Page 20: Continuous Delivery to Amazon EC2 Container Service

Test environment

Test

environment

Page 21: Continuous Delivery to Amazon EC2 Container Service

Running test inside a container

Usual Docker commands available within your test

environment

Run the container with the commands necessary to

execute your tests, e.g.:

docker run web bundle exec rake test

Page 22: Continuous Delivery to Amazon EC2 Container Service

Running test against a container

Start a container running in detached mode with an

exposed port serving your app

Run browser tests or other black box tests against the

container, e.g. headless browser tests

Page 23: Continuous Delivery to Amazon EC2 Container Service

Stage 4 - Deploy

Page 24: Continuous Delivery to Amazon EC2 Container Service

Deployment environment

Deployment

environment

Page 25: Continuous Delivery to Amazon EC2 Container Service

Amazon EC2 Container Service

• Highly scalable container management service

• Easily manage clusters for any scale

• Flexible container placement

• Integrated with other AWS services

• Extensible

• Amazon ECS concepts

• Cluster and container instances

• Task definition and task

Page 26: Continuous Delivery to Amazon EC2 Container Service

AWS Elastic Beanstalk

• Deploy and manage applications without worrying about

the infrastructure

• AWS Elastic Beanstalk manages your database, Elastic

Load Balancing (ELB), Amazon ECS cluster, monitoring

and logging

• Docker support

• Single container (on Amazon EC2)

• Multi container (on Amazon ECS)

Page 27: Continuous Delivery to Amazon EC2 Container Service

Amazon ECS CLI

• Easily create Amazon ECS clusters & supporting

resources such as EC2 instances

• Run Docker Compose configuration files on Amazon

ECS

• Available today – http://amzn.to/1jBf45a

Page 28: Continuous Delivery to Amazon EC2 Container Service

Configuring the ECS CLI

# Configure the CLI using environment variables

> export AWS_ACCESS_KEY_ID=<my_access_key>

> export AWS_SECRET_ACCESS_KEY=<my_secret_key>

> ecs-cli configure --region us-east-1 --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --cluster ecs-cli-demo

# Configure the CLI using an existing AWS CLI profile

> ecs-cli configure --region us-west-2 --profile ecs-profile --cluster ecs-cli-demo

Page 29: Continuous Delivery to Amazon EC2 Container Service

Deploy and scale Compose app with ECS CLI

# Deploy a Compose app as a Task or as a Service

> ecs-cli compose up

> ecs-cli compose ps

> ecs-cli compose service create

> ecs-cli compose service start

# Scale a Compose app deployed as a Task or as a Service

> ecs-cli compose scale n

> ecs-cli compose service scale n

Page 30: Continuous Delivery to Amazon EC2 Container Service

Continuous Delivery

Workflows

Page 31: Continuous Delivery to Amazon EC2 Container Service

Continuous delivery to ECS with Jenkins

4. Push image to

Docker registry

2. Build image from

sources 3. Run test on image

1. Code push

triggers build

5. Update Service

6. Pull image

Page 32: Continuous Delivery to Amazon EC2 Container Service

Continuous delivery to ECS with Jenkins

Easy Deployment

Developers – Merge into master, done!

Jenkins Build Steps

Trigger via Webhooks, Monitoring, Lambda

Build Docker image via Build and Publish plugin

Push Docker image into Registry

Register Updated Job with ECS API

Page 33: Continuous Delivery to Amazon EC2 Container Service

Continuous delivery to ECS with CodePipeline

1. Code push

triggers pipeline

2. ECS Service polls

CodePipeline for jobs

3. The Docker image

is build and pushed to

ECR

5. ECS pulls newly built

image from ECR

4. Lambda function

deploy new task

revision to ECS

Page 34: Continuous Delivery to Amazon EC2 Container Service

Continuous delivery to ECS with CodePipeline

• ECS Service polls CodePipeline for pending jobs

• When a job is found, it pulls the code and builds the

Docker image and pushes it to ECR

• Lambda custom action updates ECS task definition with

latest image

Page 35: Continuous Delivery to Amazon EC2 Container Service

Amazon ECS continuous delivery partners

Page 36: Continuous Delivery to Amazon EC2 Container Service

Continuous delivery to ECS with Shippable

Page 37: Continuous Delivery to Amazon EC2 Container Service

Demo

Page 38: Continuous Delivery to Amazon EC2 Container Service

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

All attendees will receive a special giveaway gift!

Please join us for the

AWS DevDay Networking Reception

5:00 - 6:30 PM

JW Grand Foyer

Page 39: Continuous Delivery to Amazon EC2 Container Service

Thank You!

Page 40: Continuous Delivery to Amazon EC2 Container Service

Don’t Forget Evaluations!