Day 51: Your CI/CD pipeline on AWS - Part 2 🚀 ☁(Jan 16, 2024)

Day 51: Your CI/CD pipeline on AWS - Part 2 🚀 ☁(Jan 16, 2024)

🙏 Introduction:

In this blog, we will deploy CI/CD pipeline on AWS using (CodeCommit, CodeBuild, CodeDeploy, CodePipeline & S3) tools, this is the part-2

🔶What is CodeBuild ?

  • AWS CodeBuild is a fully managed build service that compiles source code, runs tests, and produces software packages that are ready to deploy. With CodeBuild, you don’t need to worry about provisioning and managing your own build infrastructure. You simply provide your build project’s source code and build settings, and CodeBuild handles the rest.

  • For example, if you have a web application that you want to deploy, you can use CodeBuild to compile your source code, run unit tests, and produce a deployable package. You can also use CodeBuild to build Docker images, run static code analysis, and more. CodeBuild integrates with other AWS services like CodePipeline, so you can easily automate your entire software release process.

🎯Task: 1

  1. 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.

  2. Create a simple index.html file in CodeCommit Repository

  • Open the AWS Management Console and navigate to the CodeCommit service

  • Select the repository where you want to add the index.html file

  • Click on the Create file button

  • Enter “index.html” as the file name and add the following content in the editor
<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>
  • Click on the Commit changes button to save the changes

  • Clone the repository to your instance and verify the files

  1. You have to build the index.html using nginx server

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

Here’s what each step of the build does:

  • version: 0.2 specifies the version of the Buildspec syntax we’re using.

  • phases contains the build phases for our project.

  • install: Installs nginx on the build environment using the apt-get package manager.

  • build: Copies the index.html file to the default web root directory for nginx.

  • post_build: Performs any additional configuration for nginx, if necessary.

  • artifacts: Specifies the location of the index.html file to be included in the build artifact.

  • Commit the changes to the repository using the git add and git commit

  • Push the local changes to repository

🎯Task: 2

  1. Add buildspec.yaml file to CodeCommit Repository and complete the build process

  • buildspec.yml file added to the CodeCommit repository

  • Go to the CodeBuild service, Click on Build projects button

  • Click on Create build project, Enter project name

  • Go to Source section and select Repo and branch

  • Go to Environment section and enter the details as Operating system, Runtime, Image, Image version

  • Go to Buildspec section & select Use a buildspc file & click on create build project

  • Click on Start build

  • Code build is completed

  • Now go to S3 console create a bucket

  • Bucket is created

  • Go to code build and click on edit-->Artifacts

  • Select type of Artifacts, enter bucket name, give the name of the folder or compressed file in the bucket that will contain your output artifacts, & give the path of that folder.

  • click on Update artifacts

  • Now go to build project and click on start build

  • Go to S3 bucket & go to Index.html file

  • Click on Open