Creating a continuous deployment pipeline for staging

To create our first deployment pipeline with CodePipeline, we are going to use the AWS console, which offers a very intuitive web interface:

  1. Open the following link in your browser: https://console.aws.amazon.com/codepipeline.
  2. If prompted, click on Get started.
  3. On the next screen, give your pipeline the name helloworld and click on Next Step.
  4. In the next step, for the Source location, select Github as a Source provider and click on Connect to GitHub. If requested, sign into your GitHub account.
  5. This will bring you back to the AWS CodePipeline screen; we can now select a Repository and Branch. We will select the helloworld project and master branch. Click on Next step.
  6. This brings us to Stage 3 of our pipeline where we can select our Build provider. Our application is being written in nodejs; we don't need to build anything. Select No build and click on Next step.
  7. The next step is called Beta; this is essentially our staging deployment step. Under Deployment provider, select AWS CodeDeploy, under Application name, select helloworld, and finally, select staging for the deployment group. Click on Next step.
  8. This brings us to the step where we have to choose our Role Name. Conveniently, AWS also added a Create Role button. Click on it.
  9. On the next screen, select Create a new IAM Role and give it the name AWS-CodePipeline-Service. Use the policy proposed and click on Allow.
  10. Back on the CodePipeline step, make sure that Role name says AWS-CodePipeline-Service and click on Next step.

 

  1. On that last screen, the review screen, make sure everything is correct. Finally, click on Create Pipeline:
Because we are using the web interface, Amazon is automatically creating an S3 bucket on your behalf to store the artifacts produced when the pipeline runs.

The pipeline will be created in a matter of seconds and run for the first time.

For the purposes of illustrating the basic functions of CodeDeploy and CodePipeline, we used the web and command-line interface. This process is very manual and doesn't go through any kind of review process. CloudFormation supports these two services. For a real production system, instead of making changes by hand, it is best to use something like troposphere to programmatically generate the templates to manage those services.

Once both steps have run, you can verify that the code has been deployed by opening in your browser http://<instanceip>:3000. The instance IP can be found in the CloudFormation template, in the EC2 console, or you can even verify the success with the following one-liner:

$ aws cloudformation describe-stacks 
      --stack-name helloworld-staging 
      --query 'Stacks[0].Outputs[0].OutputValue' 
     | xargs -I {} curl {}:3000
Hello World  

We have finished our basic pipeline. By taking advantage of CodePipeline, CodeDeploy, GitHub, and S3, we have built a very elegant solution to handle deploying our web application. Every time a pull request is merged to master, our pipeline will pick up the change, automatically create a new package with our new code, store it on S3, and then deploy it to staging. Thanks to CodeDeploy we can have a basic test in place to verify that the version is working, but if needed, we can roll back to any revisions previously built.

Our pipeline doesn't have to be limited to staging; we can actually do a lot more with our solution. As previously mentioned, CodePipeline can integrate with Jenkins. We can use it to build artifacts, but also to run some extra series of tests. Let's add it to our pipeline before deploying to staging.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset