Hello, my Followers. It’s time to demonstrate the true power of DevOps which is Continous Integration and Continous Delivery. Whenever you heard these words and you’re quite familiar with the terminology, your first thought comes with Jenkins. This is a good way of thinking. Jenkins is one of the most popular automation service, widely spread across the world of DevOps. However, in this post, I’d like to show you how to set up similar build server using AWS service called CodeBuild. This is also a powerful tool for CI/CD, easy to set up and manage. And what is most important, it eliminates the need to set up, patch, update and manage your own build server. All of these things are managed by AWS. Are you interested in learning about this tool? If yes, then let’s get started!

In this example, we will automate the build of the RPM package. In a brief, RPM is Red Hat Package Manager used to install the software under Red Hat Enterprise Linux and its derivatives.

The first step is to create a GIT repository, from which our build server will pull the source code. Let’s use CodeCommit for this purpose.

! Make sure you have configured the AWS programmatic access before you run these commands

$ aws codecommit create-repository --repository-name=rpmbuild

This command will create a repository called rpm-builds. It will output for you some of the important information about this repository, like URL. Please refer to my previous article to configure the access from your computer to this repository DevOps in AWS – GIT.

In this scenario, I’m using my CentOS 7 Linux. All the next commands will work only on this particular distribution.

Let’s install some of the necessary tools and initialize our project. Next, we need to set up our GIT repository.

$ sudo yum install rpm-build rpmdevtools git -y
$ cd ~
$ rpmdev-setuptree
$ cd rpmbuild
$ git init
$ git remote add origin https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/rpmbuild

Time to create our sample RPM. In this scenario, we will build RPM, which will install our custom /etc/motd - Message of The Day.

$ mkdir motd-1.0
$ echo "THIS IS MY CUSTOM MOTD" > motd-1.0/motd
$ tar -czvf SOURCES/motd-1.0.tar.gz motd-1.0

Next, create the SPEC file which is going to inform our build process on how to set up new RPM.

$ rpmdev-newspec SPEC/motd.spec
$ vi SPEC/motd.spec

## Adjust the template to below example
Name:           motd
Version:        1.0
Release:        1
Summary:        My Custom MOTD

License:        GPL
Source0:        motd-%{version}.tar.gz
BuildArch:      noarch
%define _topdir %(echo $PWD)/

%description
This is my custom MOTD config

%prep
%setup -q

%install
rm -rf $RPM_BUILD_ROOT
install -d $RPM_BUILD_ROOT/etc
install motd $RPM_BUILD_ROOT/etc/motd

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
/etc/motd
%doc

%changelog

Now we are ready to build our custom RPM and install it.

$ rpmbuild -ba -v SPECS/motd.spec
$ rpm -ivh RPMS/noarch/motd-1.0-1.noarch.rpm --force
$ cat /etc/motd

You should see your newly installed MOTD. Let’s commit and push our code to CodeCommit repository

$ git add .
$ git commit -m "Our fist RPM"
$ git push origin master

When you log in to AWS Console, you should see below code in your rpm-builds repository:

access config

In the next post, we will setup CodeBuild to use this code for automation builds.