Your CI/CD pipeline on AWS - Part 2

Your CI/CD pipeline on AWS - Part 2

·

3 min read

What is CodeBuild?

AWS CodeBuild is a fully managed build service in the cloud. CodeBuild compiles your source code, runs unit tests, and produces artifacts that are ready to deploy. CodeBuild eliminates the need to provision, manage, and scale your own build servers.

Let's pick up where we left off...

Task-01 :

Read about Buildspec file for Codebuild.

A Buildspec file is a YAML file that defines the build process for your CodeBuild project. It contains a series of commands that CodeBuild will execute to build and package your application.

Create a simple index.html file in CodeCommit Repository.

In the part01 we have already created a repository on CodeCommit. Now let's create this simple index.html on our local and then push it there.

Follow the instructions as shown in the below image. (Commands already repeated in part01)

Task-02 :

  • Add buildspec.yaml file to CodeCommit Repository and complete the build process.(you have to build the index.html using nginx server)

Create a buildspec file

Explanation of the yml file:
version: 0.2: Indicates the version of the pipeline configuration syntax being used. This is important for compatibility and ensuring the correct interpretation of the pipeline steps.

  1. phases: Describes the different stages or phases of the build process.

    • install phase:

      • Installs Nginx by updating the package list (sudo apt-get update) and then installing Nginx (sudo apt-get install nginx -y).
    • build phase:

      • Outputs a message indicating that the build has started along with the current date.

      • Copies an index.html file to the Nginx default web server directory (/var/www/html).

    • post_build phase:

      • Outputs a message indicating that Nginx is being configured.
  2. artifacts: Specifies the files that should be preserved or made available after the build. In this case, it includes the index.html file located in the Nginx web server directory (/var/www/html).

Push it to the repo

Check whether it is showing in the Codecommit

It's time to go to CodeBuild.

Search the CodeBuild service and click on creating a new build project.

Provide your desired namings

Select the source i.e CodeCommit and the Branch, the buildspec will be automatically selected because of its existence in the repo.

Provide the environment of How we want the build.

Create a new service role.

Select CloudWatch if you'd like and then finally click in Create Build project

The project has been successfully created. Click on Start build and monitor the progress

All the phases have been successfully completed.

To add artifacts to a CodeBuild project and store them in an S3 bucket.

Click on 'edit' and select 'Artifacts'.

If you already have a S3 bucket created select it as an artifact, otherwise create one.

Just a default S3 bucket will do.

Now, update your artifact.

Now, build the project again to see how things are stored in the artifact.

After completing the process go to the bucket and inside it the path that we had mentioned in our buildspec file.

Open index.html and in the top right hand corner click on 'Open'.

Here we go


Thankyou for reading until here. Keep learning Keep Exploring.