ci/cd on aws: deploy everything all the time
TRANSCRIPT
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Leo ZhadanovskyPrincipal Solutions Architect, AWS
April 12th, 2016
CI/CD on AWSDeploy Everything All Of The Time
Why does DevOps matter?
• High-performing IT organizations deploy 30x more frequently with 200x shorter lead times;; they have 60xfewer failures and recover 168x faster.
• Lean management and continuous delivery practices create the conditions for delivering value faster, sustainably.
• High performance is achievable whether your apps are greenfield, brownfield, or legacy.
(source: puppet labs 2015 State of Devops Report)https://puppetlabs.com/sites/default/files/2015-state-of-devops-report.pdf
What are CI and CD?
• Continuous Delivery• A software engineering approach in which teams keep producing valuable software in short cycles and ensure that the software can be reliably released at any time
• Continuous Integration• The practice, in software engineering, of merging all developer working copies to a shared mainline several times a day
What are CI and CD?
• Changes to code automatically deployed to mainline branch• After passing unit and mock tests
• Makes changes to code and deployments iterative, not monolithic
• Bugs are detected quickly• Helps automate deployments• Allows rapid development and deployment
SOURCE CODEREPOSITORY
PROJECT MANAGEMENTSERVER
CONTINUOUS INTEGRATION SERVER
DEVELOPER
PICKTASKS
SUBMITCODE
SCHEDULEBUILD
RECURRENTBUILDS
CODEFETCHCODE QUALITY
TESTS
TESTRESULTS
BUILD OUTPUT
DOCS
BINARIES& PACKAGES
DEV FACING NOTIFICATIONS
CLOUDFORMATION
AMIS or CONTAINERS
Components of traditional CI/CD on AWS
Git RepositoryEC2 Instance
CI SoftwareEC2 Instance
Project Management Software
EC2 Instance
Build ArtifactsS3 Bucket
DeploymentSoftwareOn Laptop
AWS code services
AWS CodeCommit AWS CodePipeline AWS CodeDeploy
Cloud software development lifecycle
MonitorProvisionDeployTestBuildCode
AWS Elastic Beanstalk
AWS OpsWorks
Amazon CloudWatch
AWS CloudFormation
?
CodeCommit: source controlPrivate Git repositories hosted on Amazon S3
Full Git compatibility (use with existing tools)All the benefits of the cloud(scalable, durable, reliable, low pay-as-you-go pricing)No size limits on repositories (store binary files)Online web console
CodeCommit: same Git experience
$ git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/aws-cli
Cloning into 'aws-cli'...
Receiving objects: 100% (16032/16032), 5.55 MiB | 1.25 MiB/s, done.
Resolving deltas: 100% (9900/9900), done.
Checking connectivity... done.
$ nano README.rst
$ git commit -am 'updated README'
[master 4fa0318] updated README
1 file changed, 1 insertion(+)
$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 297 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote:
To https://git-codecommit.us-east-1.amazonaws.com/v1/repos/aws-cli
4dacd6d..4fa0318 master -> master
CodePipeline: continuous deliveryCustomizable release automation, with integrated build and test
Model and visualize custom release workflow(source è build è beta è gamma è prod)Automate builds, tests, and deploymentsIntegrate with third-party and custom tools
DeploymentCoordinate software updates to fleets of EC2 instances
Rolling updates for no downtimeDeployment health checks and easy rollbackAuto Scaling integrationWorks with any applicationReuse existing setup tools(Bash, Powershell, Chef, Puppet…)
Cloud software development lifecycle
MonitorProvisionDeployTestBuildCode
AWS Elastic Beanstalk
AWS OpsWorks
CloudWatchCloudFormationCodeDeploy
CodeCommit CodePipeline
Components of CI/CD with AWS Code Services
CI Software*EC2 Instance
Project Management Software
EC2 Instance
Build ArtifactsS3 Bucket
Git RepositoryCodeCommit
AWS CodePipeline
AWS CodeDeploy
DevOps Partner SolutionsSolutions vetted by the AWS Partner Competency Program
Continuous Integration & Delivery
Rapidly and reliably build, test and release your applications, while improving quality and reducing time to market
Configuration Management
Treat your infrastructure as code, manage container, operating system, and application configurations
https://aws.amazon.com/solutions/partners/dev-ops /
Today’s demo
Develop
Commit
Build
Test
Deploy
Monitor
AWS CodeCommit
AWS CodePipeline
AWS CodeDeploy
AmazonCloudWatch
Application architecture
Jenkins (on EC2 instance)
WordPress servers
Availability Zone A Availability Zone B
WordPress servers
Auto Scaling group
RDS MySQL primary RDS MySQL standby
ELB load balancer
Developer S3 bucket
Jenkins (on EC2 instance)
1. Push code to remote repository
2. CodePipeline polls GitHub for new commits
3. CodePipelinepulls new commitsinto ZIP file in S3
5. Jenkins runs tests on code and notifies CodePipelineof results
7. Servers download and install
AWS CodeDeploy
6. Servers are notified of deployment
4. Jenkins polls CodePipeline for new activity
WordPress servers(Auto Scaled)
8. CodeDeploy is notified of success or failure
AWS CodePipeline
Deployment overview9. Load test is run on the staging Auto Scaling group, production deploy is triggered
10. Deployment is marked in NewRelic
CodeDeploy lifecycle events
AWS CodeDeploy
Elastic Load Balancer
Target Instance
S3 bucket1. ApplicationStop
• Deregister from load balancer
• Stop server
3. BeforeInstall• Delete old version• Install dependencies• Install New Relic
agents
2. DownloadBundle
4. Install
5. AfterInstall• Update permissions• Download config/creds• Mark deployment in New
Relic
6. ApplicationStart• Start server• Register with load
balancer
0. Instance is notified of new deployment
7. ValidateServiceCodeDeploy is notified of successful deployment
CodeDeploy default deployment configs
AllAtOnce
OneAtATime
HalfAtATime
CodeDeploy custom deployment configs
HOST_COUNT FLEET_PERCENT = 80No less than 80% of hosts should be healthy during deployment
No less than 10 hosts should be healthy during deployment, regardless of the number of instances
= 10
Failed deployments in CodeDeploy
Deploy version 1.5
Deployto
OK?
Yes
Deployment failed
Deployto
OK?
YesDeployto
OK?
Yes
No No No
Done
version 1.4
Recover from a failed or canceled deployment by creating a new
deployment of the previous version
Live demo