Day 51 - Your CI/CD pipeline on AWS - Part 2 ๐Ÿš€ โ˜

Nilkanth MistryNilkanth Mistry
3 min read

Welcome back, DevOps enthusiasts! In our journey of building a robust CI/CD pipeline on AWS, we've conquered AWS CodeCommit. Today, let's dive deeper into the world of AWS services with CodeBuild, CodeDeploy, CodePipeline, and S3. Exciting times ahead! ๐ŸŽ‰

What is CodeBuild? ๐Ÿ—๏ธ

AWS CodeBuild is like having your own team of builders in the cloud. It automates the process of compiling your source code, running tests, and generating deployment-ready artifacts. Say goodbye to managing build servers - CodeBuild takes care of it all for you! ๐Ÿ› ๏ธ

๐Ÿš€ Task-01: Setting Up CodeCommit and Building with Nginx

  1. Read about Buildspec file for CodeBuild:

    • Understand the purpose and structure of a Buildspec file. ๐Ÿ“š

    • Learn about YAML syntax. ๐Ÿงฉ

  2. Create a CodeCommit Repository:

    • Set up a CodeCommit repository to store your code. ๐Ÿ—๏ธ

  3. Clone Repository to Local Machine:

    • Use Git Bash to clone the repository to your local machine. ๐Ÿ’ป

    • Execute commands:

        git clone <repository-HTTPS-url>
      
  4. Create and Commit index.html:

    • Inside the repository, create an index.html file. ๐Ÿ“„

    • Add and commit the file to the repository:

        git add index.html
        git commit -m "Commit index.html"
        git push origin master
      

๐Ÿ”จ Task-02: Configuring Build Process with Buildspec

  1. Add buildspec.yaml File:

    • Create a buildspec.yaml file with build instructions. ๐Ÿ› ๏ธ

      Sure, here's a sample buildspec.yaml file based on your requirements:

        version: 0.2
      
        phases:
          install:
            runtime-versions:
              nginx: latest
          build:
            commands:
              - cp index.html /usr/share/nginx/html/
          post_build:
            commands:
              - service nginx start
        artifacts:
          files:
            - /usr/share/nginx/html/index.html
      
    • Include commands to install Nginx and configure the build process. โš™๏ธ

  2. Commit Buildspec.yaml:

    • Add and commit the buildspec.yaml file to the repository:

        git add buildspec.yaml
        git commit -m "Add buildspec.yaml"
        git push origin master
      

  1. Create Build Project in CodeBuild:

    • Set up a new build project in the CodeBuild service. ๐Ÿ› ๏ธ

    • Configure source provider as AWS CodeCommit, select repository and branch. ๐Ÿ“ฆ

  2. Define Environment and Buildspec:

    • Choose the operating system, runtime, and image. ๐Ÿ–ฅ๏ธ

    • Select "Use a buildspec file" option and specify the location. ๐Ÿ“‹

  3. Start Build and Verify:

    • Initiate a build and monitor the status. ๐Ÿš€

    • Ensure all phases succeed. โœ…

๐Ÿ“ฆ Adding Artifacts to CodeBuild and Storing in S3

  1. Create S3 Bucket:

    • Set up an S3 bucket to store artifacts. ๐Ÿ—ƒ๏ธ

  2. Configure Artifacts in CodeBuild:

    • Edit the build project settings to specify S3 as the artifact type. ๐Ÿ› ๏ธ

    • Select the previously created S3 bucket. ๐Ÿชฃ

  3. Update Artifacts and Rebuild:

    • Update the artifacts configuration and start a new build. ๐Ÿ”„

    • Verify that artifacts are uploaded to the S3 bucket. ๐Ÿ“ค

  4. Verify Artifacts in S3:

    • Check the S3 bucket to ensure that the index.html file is stored in the specified location. ๐Ÿง

      You can see inside /var/www/html there is index.html file.

      Click on 'index.html' file, below you can see properties of file.

      Click on 'open' on right-hand side.

      Happy Learning! ๐ŸŽ‰

10
Subscribe to my newsletter

Read articles from Nilkanth Mistry directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nilkanth Mistry
Nilkanth Mistry

Embark on a 90-day DevOps journey with me as we tackle challenges, unravel complexities, and conquer the world of seamless software delivery. Join my Hashnode blog series where we'll explore hands-on DevOps scenarios, troubleshooting real-world issues, and mastering the art of efficient deployment. Let's embrace the challenges and elevate our DevOps expertise together! #DevOpsChallenges #HandsOnLearning #ContinuousImprovement