Day 51: Your CI/CD Pipeline on AWS - Part 2 🚀 ☁

Day 51: Your CI/CD Pipeline on AWS - Part 2 🚀 ☁

Day#51 Of 90 Days Of DevOps Challenge

👋Introduction

Welcome back to the second part of our journey to building a robust CI/CD pipeline on AWS.💥

In the previous part, we explored AWS CodeCommit, a fully managed source control service.

Today, we'll delve into the next set of tools and services that will help us enhance our CI/CD pipeline:

CodeBuild is a cloud-based, fully managed build service.

CodeDeploy automates application deployments to different compute services.

CodePipeline is a service that facilitates continuous integration and continuous delivery (CI/CD).

Amazon S3 provides scalable storage for hosting websites and storing artifacts.

In this blog post, our main emphasis will be on AWS CodeBuild, where we will delve into its purpose and guide you through the process of creating a basic CI/CD pipeline step by step.

♻What is CodeBuild?

AWS CodeBuild is a versatile, fully managed build service in the cloud.

It plays a pivotal role in your CI/CD pipeline by compiling your source code, running unit tests, and generating deployable artifacts.

One of the key benefits of CodeBuild is that it eliminates the need to provision, manage, and scale your build servers.

Let's dive into our hands-on tasks to explore its capabilities further.

📌Task-01: Understanding Buildspec and Building an HTML Page

Step 1: Read about the Buildspec File for CodeBuild

Before we start using AWS CodeBuild, let's familiarize ourselves with the buildspec.yaml file.

This file is crucial as it defines the build process for CodeBuild, specifying what actions need to be taken during the build phase. You can think of it as a recipe for your build process.

$ cat buildspec.yaml
version: 0.2
phases:
  build:
    commands:
      - echo "Building HTML page"
      - npm install
      - npm run build
artifacts:
  files: index.html

In this example, we're using Node.js to build our HTML page.

We first echo a message, install the necessary dependencies, and then run a build script.

The artifacts section specifies that we want to keep the index.html file as a result of the build.

Step 2: Create a Simple index.html File in CodeCommit Repository

Now, let's create a basic index.html file in your CodeCommit repository. You can use your preferred text editor or an integrated development environment (IDE).

# Command Line Display
<html>
  <head>
    <title>My Website</title>
  </head>
  <body>
    <h1>Welcome to my website</h1>
    <p>This is a simple website hosted on AWS CodeCommit.</p>
  </body>
</html>

This creates a simple HTML file with a "Hello, AWS CodeBuild!" message.

  • Navigate to the CodeCommit service.

  • Create and select the repository where you want to add the index.html file.

  • Click on "Commit Changes" to save the changes.

  • Clone the repository to your instance and verify the files.

📌Task-02: Adding buildspec.yaml and Completing the Build Process

Now that we've successfully built our HTML page, it's time to integrate this process into our CodeCommit repository.

Step 1: Add buildspec.yaml file to CodeCommit Repository

  • To make the build process automatic, we need to commit the buildspec.yaml file to our CodeCommit repository.

  • Push this file to our repository.

      version: 0.2
    
      phases:
        install:
          commands:
            - echo Installing NGINX
            - sudo apt-get update
            - sudo apt-get install nginx -y
        build:
          commands:
            - echo Build started on 'date'
            - cp index.html /var/www/html/
        post_build:
          commands:
            - echo Configuring NGINX
    
      artifacts:
        files:
          - /var/www/html/index.html
    
      # Command Line Display
      $ git add .
      $ git commit -m "Commit Message"
      $ git push <branch-name>
    

Step 2: Complete the Build Process

Once the buildspec.yaml file is in your repository, AWS CodeBuild will automatically pick it up when you push changes to your repository.

It will execute the build process as defined and generate the index.html file.

  • Create a CodeBuild project in AWS Console

  • Create a CodeBuild Project

  • Select the source provider, repository, and branch.

  • Select your environment and operating system & create the codeBuild Project

  • Now, start the build by clicking on Start Build & wait to complete it

  • Store the build details in the artifacts

    Before that, create an S3 bucket. Navigate to the S3 bucket in the AWS console and provide the bucket name and create the bucket.

  • Click on edit and select artifact. Provide all the details and create an artifact.

  • Now if you rebuild the project you can see the UPLOAD_ARTIFACTS section.

  • Navigate to the S3 bucket and you can see the build.

  • Click on the Open URL to open the nginx & see the output of the index.html file.

Congratulations!🎊 You've successfully set up AWS CodeBuild to automate the build process of your HTML page.

This is a fundamental step in building a robust CI/CD pipeline on AWS.

🌈Conclusion

Within this leg of our AWS CI/CD expedition, we delved into AWS CodeBuild and its crucial role in streamlining the building process.

We acquired knowledge on crafting a buildspec.yaml file, constructing an HTML page, and seamlessly integrating the build workflow into our CodeCommit repository.

Stay connected for the forthcoming segments of this series, where we will explore AWS CodeDeploy, CodePipeline, Amazon S3, and the art of harmonizing all these elements to construct a fully operational CI/CD pipeline on AWS.

Your voyage toward becoming a proficient AWS CI/CD practitioner persists! 🚀 ☁

Happy learning🎉& may your cloud journey be filled with exciting discoveries!🎊

Thank you for joining us on this exciting Day 51 of the 90 Days of DevOps challenge. I hope you found the information helpful and insightful.💥

So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on :

Hashnode: vishaltoyou.hashnode.dev

LinkedIn: linkedin.com/in/vishalphadnis