Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Continuous Integration Best Practices (DEV319-R1) - AWS re:Invent 2018

1,217 views

Published on

Today, more teams are adopting continuous integration (CI) techniques to enable collaboration, increase agility, and deliver a high-quality product faster. Cloud-based development tools such as AWS CodeCommit and AWS CodeBuild can enable teams to easily adopt CI practices without the need to manage infrastructure. In this session, we showcase best practices for code reviews and continuous integration, drawing on practices used by Amazon engineering teams. We’ll incorporate demos to not just explain the practices but show you how.

Continuous Integration Best Practices (DEV319-R1) - AWS re:Invent 2018

  1. 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Continuous Integration Best Practices Nick Brandaleone Joseph Vusich Senior Solutions Architect Senior Software Development Engineer AWS AWS D E V 3 1 9
  2. 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agenda Introduction to Continuous Integration Continuous Integration Tooling CI best practices and techniques Demo Review
  3. 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Breakout repeats DEV319 - Continuous Integration Best Practices Monday, Nov 26, 4:00 PM - 5:00 PM Venetian, Level 2, Titian 2204 DEV319 - Continuous Integration Best Practices Tuesday, Nov 27, 3:15 PM - 4:15 PM Venetian, Level 5, Palazzo O
  4. 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Related breakouts DEV317 - Advanced Continuous Delivery Best Practices Monday, Nov 26, 1:45 PM - 2:45 PM Tuesday, Nov 27, 2:30 PM - 3:30 PM Venetian, Level 5, Palazzo O. Aria East, Level 1, Joshua 9 DEV309 - CI/CD for Serverless and Containerized Applications Tuesday, Nov 27, 7:00 PM - 8:00 PM. Thursday, Nov 29, 2:30 PM - 3:30 PM Venetian, Level 2, Venetian E. Bellagio, Level 1, Grand Ballroom 2 Thursday, November 29 Leadership Session: Using DevOps, Microservices, and Serverless to Accelerate Innovation (SRV325) 12:15 – 1:15 PM | Venetian Theatre (Level 2)
  5. 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  6. 6. “Continuous Integration is a software development practice where members of a team integrate frequently … verified by an automatic build and test process…” Martin Fowler
  7. 7. “Continuous Integration produces and validates artifacts, while Continuous Deployment deploys them.”
  8. 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is continuous integration? 1. Developers regularly check in code to a shared, central repository 2. Automated checks run regularly against the shared codebase 3. Developers get feedback from the automated checks about their code Developer Shared codebaseAutomated checks Check in code Get feedback Run checks
  9. 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is continuous integration? 1. Developers regularly check in code to a shared, central repository 2. Automated checks run regularly against the shared codebase 3. Developers get feedback from the automated checks about their code Developer Shared codebaseAutomated checks Check in code Get feedback Run checks
  10. 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is continuous integration? 1. Developers regularly check in code to a shared, central repository 2. Automated checks run regularly against the shared codebase 3. Developers get feedback from the automated checks about their code Developer Shared codebaseAutomated checks Check in code Get feedback Run checks
  11. 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is continuous integration? 1. Developers regularly check in code to a shared, central repository 2. Automated checks run regularly against the shared codebase 3. Developers get feedback from the automated checks about their code Developer Shared codebaseAutomated checks Check in code Get feedback Run checks
  12. 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Typical Developer workflow 1) Write code - Cloud9 2) Compile and run unit tests locally - CodeBuild Local 3) Push code to a Git repository - CodeCommit 4) Build the updated images - CodeBuild 5) Run integration tests against new code - CodeBuild 6) Push new images to registry - CodeBuild and Elastic Container Registry 7) Trigger a deployment - CodeBuild or CloudWatch Events + Lambda
  13. 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  14. 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why does continuous integration matter? • Find bugs earlier • Fix bugs faster • Deliver faster • Deliver more often • Unblock developers • Grow developers
  15. 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why does continuous integration matter? • Find bugs earlier • Fix bugs faster • Deliver faster • Deliver more often • Unblock developers • Grow developers Quality: 5x lower change failure rate Source: 2017 State of DevOps Report (Puppet)
  16. 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why does continuous integration matter? • Find bugs earlier • Fix bugs faster • Deliver faster • Deliver more often • Unblock developers • Grow developers Delivery: 440x faster from commit to deploy Source: 2017 State of DevOps Report (Puppet)
  17. 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why does continuous integration matter? • Find bugs earlier • Fix bugs faster • Deliver faster • Deliver more often • Unblock developers • Grow developers Delivery: 46x more frequent deployments Source: 2017 State of DevOps Report (Puppet)
  18. 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why does continuous integration matter? • Find bugs earlier • Fix bugs faster • Deliver faster • Deliver more often • Unblock developers • Grow skills faster Happy teams: 44% more time spent on new features and code Source: 2017 State of DevOps Report (Puppet)
  19. 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Teams that practice CI/CD ship more code faster, and with more confidence 5x Lower change failure rate 440x Faster from commit to deploy 46x More frequent deployments 44% More time spent on new features Source: Puppet 2017 State of DevOps Report
  20. 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Summary
  21. 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  22. 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Continuous integration tools Developer Shared codebaseAutomated checks Check in code Get feedback Run checks Source Code • AWS CodeCommit • GitHub • GitHub Enterprise • Bitbucket • S3
  23. 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Continuous integration tools Developer Shared codebaseAutomated checks Check in code Get feedback Run checks Build & Test • AWS CodeBuild • Jenkins w/ CodeBuild
  24. 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Continuous integration tools Developer Shared codebaseAutomated checks Check in code Get feedback Run checks Glue • Amazon CloudWatch Events • AWS Lambda • Slack integration • SNS (E-mail / Texts) • Any AWS Service
  25. 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. • Fully managed Git service • Hosts private Git repositories • Backed by S3 • Scale with ease • Store anything, anytime AWS CodeCommit
  26. 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeCommit
  27. 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Code* Console - NEW LOOK
  28. 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeCommit Repository - Code
  29. 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeCommit - Visualizer
  30. 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeCommit – Pull Request
  31. 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeCommit PR comments: • Pull Request • Line
  32. 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeCommit – notifications
  33. 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeCommit – notification/trigger
  34. 34. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. • Fully managed build service • Continuous scaling • Pay as you go • Extensible AWS CodeBuild
  35. 35. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. • Build source from CodeCommit, S3, Bitbucket and GitHub/GitHub Enterprise • Webhook support • Multiple input repos and output artifacts • Build inside your VPC • Use secrets from Amazon Parameter Store • S3 build cache • Debug locally with CodeBuild Agent AWS CodeBuild: Features
  36. 36. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. • Ubuntu o .NET Core o Android o Docker o Golang o Java o Node o PHP o Python o Ruby AWS CodeBuild: Supported Environments • Windows Server 2016 o .NET Framework o .NET Core o C# o F# o Visual Basic
  37. 37. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Project
  38. 38. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Project Details
  39. 39. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Project Environment
  40. 40. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  41. 41. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Build history
  42. 42. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Build status
  43. 43. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Phase details
  44. 44. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Logs
  45. 45. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Logs – Streamed to CB & CW
  46. 46. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. version: 0.2 phases: install: commands: - npm install build: commands: - npm test artifacts: files: - '**/*' AWS CodeBuild build spec
  47. 47. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Phase Description Examples install Installation of packages into the environment Install testing frameworks e.g. RSpec, Mocha pre_build Commands to run before the build such as login steps or installation of dependencies Log in to Amazon ECR. run Ruby bundler or npm build Sequence to run the build such as compilation and/or running tests Run go build, sbt, Mocha, RSpec post_build Commands to run after a build on success or failure Build a JAR via Maven or push a Docker image to Amazon ECR
  48. 48. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeBuild build spec for Docker version: 0.2 phases: pre_build: commands: - $(aws ecr get-login --no-include-email) - TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)" - IMAGE_URI="${REPOSITORY_URI}:${TAG}" build: commands: - docker build --tag "$IMAGE_URI" . post_build: commands: - docker push "$IMAGE_URI"
  49. 49. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild Metrics
  50. 50. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeCommit – CW Events
  51. 51. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  52. 52. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. The continuous integration journey 10 mph 65 mph 150 mph
  53. 53. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. The continuous integration journey Nightly checks Branch checks Pull request checks
  54. 54. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Technique #1: Nightly checks 1. Nightly checks 2. Branch checks 3. Pull request checks Run a full build and unit tests every night to make sure that application still compiles and that tests still pass.
  55. 55. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Technique #2: Branch checks 1. Nightly checks 2. Branch checks 3. Pull request checks Run a full build and unit tests every time someone pushes a new change to a branch in the source code repo.
  56. 56. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Technique #3: Pull request checks 1. Nightly checks 2. Branch checks 3. Pull request checks Run a full build and unit tests every time someone creates a pull request to get code reviewed by the team.
  57. 57. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Nightly checks: How to implement CloudWatch Event Schedule Trigger
  58. 58. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodeBuild triggers
  59. 59. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  60. 60. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  61. 61. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Automate codebase maintenance 2. Email notifications Nightly checks: Speed boosts
  62. 62. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Nightly checks: Automate upgrades CloudWatch Event Schedule Trigger Push Upgrade
  63. 63. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. - rm npm-shrinkwrap.json - npm install - npm test - npm shrinkwrap - git add npm-shrinkwrap.json - git commit –m “Update dependencies!” - git push Nightly checks: Automate upgrades
  64. 64. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Nightly Checks: Update Libraries
  65. 65. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Nightly Checks: Update Libraries
  66. 66. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Nightly Checks: Update Libraries
  67. 67. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Automate codebase maintenance 2. Email notifications Nightly checks: Speed boosts
  68. 68. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Speed boost: Email notifications CloudWatch Event SendNotify
  69. 69. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  70. 70. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  71. 71. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Nightly checks summary Implement: Run a build every night at midnight Feedback loop: 16-24 hours Team impact: Broken code can block team for entire days Speed boosts: Automate codebase maintenance; Email notifications
  72. 72. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Technique #2: Branch checks 1. Nightly checks 2. Branch checks 3. Pull request checks Run a full build and unit tests every time someone pushes a new change to a branch in the source code repo.
  73. 73. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch checks: AWS CodeCommit Push Notify Start CloudWatch Event Team Members
  74. 74. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch Checks: CodeCommit Events
  75. 75. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch Checks: CodeCommit Events
  76. 76. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch Checks: CodeCommit Events
  77. 77. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch Checks: CodeCommit Events
  78. 78. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch Checks: CodeCommit Events
  79. 79. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Slack notifications 2. Build badges 3. Caching Branch checks: Speed boosts
  80. 80. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Speed boost: Slack notifications Notify CloudWatch Event PostTrigger Slack Channel
  81. 81. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch Checks: Slack Notifications
  82. 82. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch Checks: Slack Notifications
  83. 83. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Slack notifications 2. Build badges 3. Caching Branch checks: Speed boosts
  84. 84. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  85. 85. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  86. 86. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Slack notifications 2. Build badges 3. Caching Branch checks: Speed boosts
  87. 87. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Speed boost: Caching Update Install Amazon S3 Bucket Download
  88. 88. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. cache: paths: - 'node_modules/**/*' Speed boost: Caching
  89. 89. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  90. 90. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild timing w/o cache
  91. 91. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. CodeBuild timing with cache
  92. 92. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Branch checks summary Implement: Run a build every time new code is pushed to a branch Feedback loop: Time it takes to build the code (minimum) Team impact: Much shorter cycles; broken code still blocks team Speed boosts: Slack notifications; build badges; caching
  93. 93. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Technique #3: Pull request checks 1. Nightly checks 2. Branch checks 3. Pull request checks Run a full build and unit tests every time someone creates a pull request to get code reviewed by the team.
  94. 94. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. PR checks: AWS CodeCommit Propose Notify Start CloudWatch Event NotifyComment Team Members
  95. 95. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  96. 96. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  97. 97. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  98. 98. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  99. 99. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  100. 100. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  101. 101. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Integration tests 2. Parallel builds PR checks: Speed boosts
  102. 102. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Speed boost: Integration tests Test ElasticCache Cluster
  103. 103. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  104. 104. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  105. 105. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1. Integration tests 2. Parallel builds PR checks: Speed boosts
  106. 106. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Speed boost: Parallel builds StartPropose Multiple CodeBuilds Team Members
  107. 107. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  108. 108. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Pull request checks summary Implement: Run a build while code is still in review Feedback loop: Time it takes to build the code Team impact: Broken code doesn’t block the team Speed boosts: Integration tests; parallel builds
  109. 109. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  110. 110. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  111. 111. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1.Automate the boring stuff Library upgrades or automatic tagging 2.Communicate status Email, Slack, build badges 3.Build faster Caching, parallel builds 4.Check more Unit and Integration tests Continuous Integration
  112. 112. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. The continuous integration journey Developer Shared codebaseAutomated checks Check in code Get feedback Run checks
  113. 113. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Samples https://github.com/aws-samples/aws-codebuild- samples
  114. 114. Thank you! © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Nick Brandaleone Joseph Vusich nbrand@amazon.com
  115. 115. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

×