Setup a build process

Jigar R
4 min readJul 15, 2022

--

In previous blog, we looked at repositories at a high level. There are few steps between writing a code and launching it. If you are writing a hello world program or a heavy duty application, certain steps exists.

For example, a normal hello-world program written in java needs to be compiled before you run it. If you have added few classes in your java app, then you would compile them, package it in jar and run it. As the number of features increase, you would need to document your code, add various types of test cases to capture problems before hand, setup static code-analysis and so on. You can do it manually for first few times but it would become little tedious process. I bet after sometime you just want to automate the process. This process helps us to build the code, and is known as build process. There are many tools like Jenkins, TravisCI, CodeBuild and so on helps to build code.

Defining a build process

Apart from usual things that help to define build such as name & description, you need following

  • Where is the code that you want to build?
  • What are the steps to build the code? — Hint: This is defined in a file (In case of Jenkins, it’s jenkinsfile and for CodeBuild — buildspec.yml)
  • Where do you want to build the code? — By default, Jenkins picks one of the available node. In any setup you have upper limit on how many jenkins jobs can run parallely. CodeBuild moves that responsibility to Amazon. There are various options such as running
  • — in a container
  • — — either on an amazon managed container (source can be found on dockerhub)
  • — — or on a custom container
  • — run it locally through CodeBuild agent
  • Do you want to store log in CloudWatch?

CloudWatch is ready-to-use software that can accept logs, important details of ec2 instances can be monitored there too. It’s like a swiss army knife for keeping tabs on your private cloud.

  • Batch configuration —

Samples can be found at use-case-based-samples.html

Consider setting up build process like following:

  • As soon as developer submits a code, build process should kick in
  • If there is a code review then output of the build (success/failures) should be mentioned in the review
  • In case build failure, send an email to X, Y & Z
  • Supply environment variable
  • Supply secrets securily (if needed via using Parameter Store)

On one end, your code repositories may exists on Github, Gitlab or CodeCommit. On the other, build process exists on Jenkins, TravisCI or CodeBuild. Notice that code repository and build tool can be different. Build process needs a notification or trigger that some changes were uploaded to the code repository.

Side note:

In case of CodeBuild, you can take advantage of webhooks for Github & bitbucket. One of the way to trigger a build from a commit on CodeCommit to CodeBuild would be via CloudWatch or CodePipeline.

What is CloudWatch?

CloudWatch can be thought as a guard whose responsibility is to keep an eye on various services in your virtual private cloud. You can store logs of various services in CloudWatch, keep an eye on the health of your virtual-machines by monitoring their CPU/memory usage and so on. You can also configure different scenarios such as when event-A occurs notify event-B. This event matching functionality is a separate product known as EventBridge in AWS. In our case, we would define a rule in EventBridge. The source of the event would be CodeCommit and target would be CodeBuild. There are many events that occur on CodeCommit so you want to trigger a build on some specific event such as change in the state of the repository.

Various CodeCommit events supported by EventBridge

What is CodePipeline?

It’s alright to setup things by hand when we are working with 1 or 2 projects. But as you work with more projects, this task becomes tedious. This is where CodePipeline helps. It would identify changes in code repository, trigger a build, deploy it in test environment. It can also go beyond this and actually deploy it in prod environment in one region, roll it out to second and third and so on.

In this post, we glanced at following services

  • CodeBuild
  • CloudWatch
  • CodePipeline
  • Parameter Store

References:

--

--

Jigar R
Jigar R

Written by Jigar R

DevOps Engineer | feel free to reach out to me | LinkedIn — https://www.linkedin.com/in/jigarrathod/

No responses yet