In this post, I’m going to show you how to automate your build process using the fantastic tool called CodeBuild. It’s very easy to set up the new build process. It’s not needed to set up your whole infrastructure (like provision Linux server, install and configure Jenkins etc.). AWS is managing the whole infrastructure and you can focus solely on your tasks. Finally, you pay only per builds which are very cheap! I hope this convinces you to use CodeBuild, so let’s get started!

codebuild

Let’s automate the build process of RPM packages from my previous post DevOps in AWS – CI/CD - Build RPM. Go to AWS Console and select CodeBuild service. Click on Create project to start the configuration wizard. The first thing to do is to name our project. I will name it as “RPM-Build”. Next, select the source provider which is AWS CodeCommit. Select appropriate repository and leave other options by default.

codebuild

Next go to the section “Environment: How to build”. Select “Use an image managed by AWS CodeBuild”, then operating system “Ubuntu”, Runtime “Base” and Runtime version “ubuntu-base:14.04”. For build specification select “Use the buildspec.yml in the source code root directory”. Other options leave default.

codebuild

It’s time to create our buildspec.yml file and add it to our GIT repository. Please use below code, which is designed for Ubuntu 14.04 environment.

version: 0.2

phases:
  install:
    commands:
       - echo install rpm packages
       - apt-get update 
       - apt-get install rpm tree -y
  pre_build:
    commands:
       - echo check rpmbuild version
       - rpmbuild --version
  build:
    commands:
       - echo start building process
       - rpmbuild -ba -v SPECS/motd.spec
  post_build:
    commands:
       - echo checking content
       - tree RPMS/
artifacts:
  files:
     - RPMS/noarch/*.rpm
  discard-paths: yes
$ cd rpmbuild
$ vi buildspec.yml
### paste the specification

$ git add .
$ git commit -m "buildspec.yml file added"
$ git push origin master

In the artifacts section, select the type “Amazon S3. The name leaves as default. I created folder RPMs inside my S3 bucket to store produced RPMs. Namespace leaves default. Bucket name - select your bucket name which needs to be created to store our RPMs. Artifacts packaging leave default.

codebuild

Other options leave default. Let AWS create custom service role to access resources on behalf of CodeCommit.

codebuild

Press Continue and Save to create your build project.

From the list of your project, select the one you just created and click Start Build. Select the Branch name (in my case it’s master). It will automatically select the latest commit. Finally, click start to build and observe the build process.

codebuild

After 1-2 minutes, you should get the message that the build is accomplished successfully.

codebuild

You can go to S3 bucket and check if your RPM is placed here.

codebuild

I hope all went good and you can see your first successful build. Isn’t it cool?? :)

That’s all for now. In the next post, we will continue with our CI/CD deployment in AWS.

Thank you for your time!