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/cod epipeline.
  2. If prompted, click on Get started.
  3. On the next screen, give your pipeline the name helloworld and click on Next Step.
  1. For the source location, select GitHub as a Source provider and click on Connect to Github. If requested, sign into your GitHub account.
  2. 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 the master branch. Click on Next step.
If you don't see the organization name/repository name (that is, yogeshrahejahelloworld/helloworld) then, as a workaround, clone/copy the organization name/repository name to your global Github repository (that is, yogeshrahejahelloworld/helloworld  to yogeshraheja/hellworld in my case).
  1. This brings us to stage three of our pipeline where we can select our Build provider. Our application is being written in Node.js so we don't need to build anything. Select No build and click on Next step.
  2. The next step is called Beta. This is essentially our staging deployment step. Under Deployment provider, select AWS CodeDeploy. Under Application name, select helloworld. Finally, select staging for the Deployment group. Click on Next step.
  3. This brings us to a step in which we have to choose our Role Name. Conveniently, AWS have also added a Create Role button. Click on this.
  4. 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.
  5. Go back to the CodePipeline step and make sure that role name says AWS- CodePipeline-Service. Click on Next step.
  6. On the review screen, make sure everything is correct. Finally, click on Create Pipeline.
Because we are using the web interface, Amazon automatically creates an S3 bucket on your behalf to store the artifacts that are produced when the pipeline runs.

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

To illustrate the basic functions of CodeDeploy and CodePipeline, we have 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 generate the templates programmatically to manage the 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 or the EC2 console. 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 the deployment our web application. Every time a pull request is merged to the master, our pipeline will pick up the change, automatically create a new package with the 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. If needed, we can also roll back to any revisions that were built previously.

Our pipeline doesn't have to be limited to staging; we can actually do a lot more. As we mentioned previously, CodePipeline can integrate with Jenkins. We can use CodePipeline 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
52.15.163.239