AWS CodeDeploy and CodePipeline with Github Integration guide





Concepts:
  • Continuous Delivery - Automates the entire software release process up to production.
  • Continuous Integration - Focused on automatically building and testing code.
AWS Code Pipeline:-

AWS CodePipeline is a continuous delivery service you can use to model, visualize, and automate the steps required to release your software. AWS CodePipeline automates the steps required to release your software changes continuously.

When Developers Commit changes to a source repository and a specified branch, AWS CodePipeline automatically detects the changes. Those changes are built and tested. AWS CodePipeline can deploy applications to Amazon EC2 instances by using AWS CodeDeploy.
AWS CodeDeploy

Each Pipeline has 3 parts:
  • Source Provider, where you can choose from:
    • GitHub
    • AWS CodeCommit
    • AWS S3
  • Build Provider, your choices are:
    • AWS CodeBuild
    • Jenkins CI
  • Deploy Provider, using one of:
    • AWS CodeDeploy
    • AWS ElasticBeanstalk
So you see that there are multiple ways you can setup a CodePipeline pipeline. The last part (deploy provider) is necessarily an AWS-backed service because, after all, AWS isn't about to launch a product to help you deploy to its cloud competitors.
Code Pipeline = Source Provider + Build provider + Deploy Provider
You can, for instance, have a full AWS-based pipeline, with CodeCommit -> CodeBuild -> CodeDeploy.
Or you can choose external providers for the first two providers, with GitHub -> Jenkins CI -> AWS ElasticBeanstalk.
All Examples will use a Scala App, such as the one here: Packaging an Akka-Http Application using SBT and Docker: Simple Example
On this post, we'll explain how to define a pipeline consisting of the following 3 parts:
Source providerBuild ProviderDeploy Provider
GitHubAWS CodeBuildAWS ElasticBeanstalk


AWS CodeDeploy:-

Works with various systems for configuration management, source control, continuous integration, continuous delivery, and continuous deployment.

You do not need to make changes to your existing code to use AWS CodeDeploy. You can use AWS CodeDeploy to control the pace of deployment across Amazon EC2 instances and to define the actions to be taken at each stage.

Step 1 - AWS Service Role Creation:
  • Go to the AWS IAM in the Console 
  • For AWS CodeDeploy --> Role name --> select service as CodeDeploy --> Attach AWSCodePipelineFullAccess policy as well in the Role.
  • For AWS EC2 Role --> Role name --> select service as EC2 --> Create new policy with below json --> attach.

Step 2 - AWS EC2 Instance
  • Create EC2 instance or update existing instance with EC2 Role created in the above step.
  • Install the AWS CodeDeploy agent on the EC2 instance by following commands
    • sudo apt-get update 
    • sudo apt-get install python-pip ruby wget 
    • cd /home/ubuntu 
    • wget https://aws-codedeploy-<<bucket region>>.s3.amazonaws.com/latest/install
        • chmod +x ./install 
        • sudo ./install auto 
        • sudo service codedeploy-agent start 
        • sudo systemctl enable codedeploy-agent
                    {                     "Version": "2012-10-17",
                                           "Statement": [
                                                               { "Action":
                                                                          [ "s3:Get*", "s3:List*" ],                                                                       "Effect": "Allow", "Resource": "*"                                            }
                                                           ]            } 
      Step 3 - CodeDeploy Integration
      • Go to the AWS CodeDeploy Service in console
      • Click Create Application and give application name and deployment group name. 
      • Deployment type as 
        • In-place Deployment - if you just want to update instance 
        • Blue/green Deployment - if you want to replace instance with the new one. 
      • Environment Configuration --> select EC2 instance on which you want to configure it.Choose the deployment configuration. More Information
      • Select Service Role created above for the CodeDeploy.
      Step 4 - CodePipeline Integration
      • Go to the AWS CodePipeline Service in console.
      • Name - Give Pipeline Name.
      • Source Provider - Choose the GitHub repository you want to use as the source location for your pipeline. In Branch, from the drop-down list, choose the branch you want to use, and then choose Next step. More Information in GitHub Integration.
      Note: You have to be Admin of Repo you want to deploy/use.
      • Build: No Build to skip the configuration of a build stage.
      • Deployment Provider: Choose AWS CodeDeploy, type or choose the name of an existing AWS CodeDeploy application in Application name and the name of a deployment group for that application in Deployment group.
      • Service Role: type or choose the name of an existing role setup for AWS CodePipeline. If you do not have a service role, choose Create role, and then on the IAM console page that describes the role that will be created for you, choose Allow.
      NOTE : Without an AppSpec file, AWS CodeDeploy cannot map the source files in your application revision to their destinations or run scripts at various stages of the deployment. If health_check error comes while deployment during codedeploy process, make sure to reboot the ec2 server if you have attached the IAM policy after the instance is created. You can check the logs of the codeDeploy using = tail -f /var/log/aws/codedeploy-agent/codedeploy-agent.log
    Previous
    Next Post »

    statistics