Your CI/CD pipeline on AWS-Part 2

Your CI/CD pipeline on AWS-Part 2

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 build servers.

Task-01 :

  • Read about the Buildspec file for Codebuild.

The buildspec.yaml file in AWS CodeBuild is used to define the build process for your project. It specifies the various phases of the build, including commands to install dependencies, build artifacts, and perform other tasks. The buildspec.yaml file is written in YAML format.

  • Create a simple index.html file in the CodeCommit Repository

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

Go to the AWS Management Console, open the CodeCommit console

Click "Create Repository" to create a new repository

You need to set up GitCredentials in your AWS IAM.

Go to the IAM console and select an IAM user with programmatic access.

In the "Security credentials" tab, scroll down to the HTTPS Git credentials for AWS CodeCommit. Then, click "Generate credentials" to get a username and password, then note them down.

Use those credentials in your local and then clone the repository from CodeCommit.

Go to the CodeCommit console and select your repository. Click on "Clone URL" to get the repository URL.

Then, in the terminal, run:

git clone <repository-url>

You will be prompted for your git credentials i.e. your username and password.

Create a simple index.html file in the CodeCommit Repository

With git add and git commit command, save the file and commit the changes made to the repository

Then push them to the origin master branch.

Task-02 :

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

Create a Buildspec file

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

With git add and git commit command, save the file and commit the changes made to the repository. Then push the changes to the repository.

Create a CodeBuild Project: Go to the AWS CodeBuild service, navigate to the "Codebuild" section and create a new build project.

Then, click on "Start build"

Now, to include artifacts and store them in an S3 bucket as part of a CodeBuild project.

Create an S3 bucket.

Click on your project and in the "Edit" dropdown, choose "Artifacts"

Under Artifacts 1 - Primary, choose "Amazon S3" as the type and provide your bucket name. Click on "Update artifacts"

After updating the artifacts, start a new build

In buildspec.yml file, the path of the file, which is /var/www/html/index.yml, is specified. You can verify if the S3 bucket has the folder and the index.html file.

Click on the "index.html" to see the properties of the file. Then click on "Open"

Thank you