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

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

ยท

5 min read

This is#90DaysofDevopschallenge under the guidance ofShubham Londhesir.

Congratulations on completing AWS CodeCommit! Now, let's delve into the next steps of your CI/CD journey with AWS.

What is CodeBuild?

AWS CodeBuild is a fully managed continuous integration service provided by Amazon Web Services (AWS). It simplifies the process of building, testing, and packaging code for software projects. Here's a detailed explanation of AWS CodeBuild:

Key Features of AWS CodeBuild:

  1. Fully Managed Service: AWS CodeBuild is a fully managed service, which means AWS takes care of infrastructure provisioning, scaling, and maintenance, allowing developers to focus on writing code and building applications.

  2. Scalability: CodeBuild automatically scales to accommodate your build workload, whether it's a small project or a large enterprise application. It eliminates the need for managing build servers or worrying about infrastructure capacity.

  3. Customizable Build Environments: CodeBuild supports a wide range of programming languages, build tools, and operating systems. You can create custom build environments tailored to your specific requirements using Docker containers or pre-configured build environments provided by AWS.

  4. Integration with AWS Services: CodeBuild seamlessly integrates with other AWS services such as CodeCommit, CodeDeploy, CodePipeline, and Amazon S3. This enables you to build end-to-end continuous integration and continuous deployment (CI/CD) pipelines and automate the software release process.

How AWS CodeBuild Works:

  1. Build Project Configuration: You define a build project in the AWS Management Console or through the AWS CLI. This includes specifying source code location, build environment settings, and build specifications.

  2. Source Code Integration: CodeBuild integrates with source code repositories like AWS CodeCommit, GitHub, or Bitbucket to retrieve the source code for the build.

  3. Build Execution: CodeBuild launches the specified build environment and executes the build commands defined in the Buildspec file. It compiles the source code, runs tests, and generates artifacts based on the build specifications.

  4. Artifact Generation: Once the build is complete, CodeBuild produces build artifacts, such as executable files, libraries, or deployment packages. These artifacts can be stored in Amazon S3 buckets or deployed directly to AWS services like Amazon EC2 or AWS Lambda.

  5. Monitoring and Logging: CodeBuild provides detailed build logs and metrics, allowing you to monitor the progress and outcome of each build. You can view build logs in the AWS Management Console or stream them to Amazon CloudWatch for real-time monitoring and analysis.

Task-01:

  1. Read about Buildspec file for CodeBuild:

    • A Buildspec file is like a recipe for CodeBuild. It tells CodeBuild how to build your project. It's written in YAML, a simple text format.

    • The Buildspec file includes commands that CodeBuild will follow to build and package your application.

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

    • First, create a new file called index.html on your computer. You can use a text editor like Notepad or Visual Studio Code.

    • Add your HTML code to index.html, such as:

    <!DOCTYPE html>
    <html>
    <head>
        <title>My Website</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
    </body>
    </html>

Task-02:

  1. To complete the task, follow these steps:

    Create a Buildspec File: Create a file named buildspec.yaml in your local project directory. Use a text editor to add the following content:

     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)"
           - sudo cp index.html /var/www/html/
       post_build:
         commands:
           - echo "Configuring Nginx"
    
     artifacts:
       files:
         - /var/www/html/index.html
    

  2. Add Buildspec File to CodeCommit Repository: Add the buildspec.yaml file to your CodeCommit repository using the following commands:

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

  3. Complete the Build Process with CodeBuild: With the Buildspec file in your repository, CodeBuild will automatically detect it and execute the build process according to the defined steps. Ensure that you have set up your CodeBuild project to trigger builds when changes are pushed to your repository.

To go to CodeBuild and create a new build project, follow these steps:

  1. Go to CodeBuild:

    • Navigate to the CodeBuild service in your AWS Management Console.

  1. Create a New Build Project:

    • Click on the option to create a new build project.

  1. Provide Desired Namings:

    • Give your build project a name that makes sense to you.

  1. Select Source:

    • Choose CodeCommit as the source and select the branch you want to build from. The buildspec file will be automatically selected from your repository.

  1. Provide Build Environment:

    • Specify how you want your build environment to be set up. For example, choose the operating system, runtime, and other configurations.

  1. Create a New Service Role:

    • If needed, create a new service role for CodeBuild to access AWS resources.

  1. Optional: Select CloudWatch:

    • If you want to monitor your build's progress with CloudWatch, select it here.

  1. Click Create Build Project:

    • Once you've configured all the settings, click on the button to create your build project.

Start Build:

  1. After the project is successfully created, click on "Start build" to begin the build process. Monitor the progress as it runs through the phases.

Add Artifacts:

  1. To add artifacts to your CodeBuild project and store them in an S3 bucket, click on "edit" and select "Artifacts."

  1. Select S3 Bucket:

    Choose an existing S3 bucket or create a new one to store your artifacts.

  1. Update Artifacts:

    Update your artifact settings as needed.

Build the Project Again:

Access Artifacts:

After the build process is complete, go to the S3 bucket and navigate to the path specified in your buildspec file.

Open index.html:

Inside the bucket, locate the index.html file and click on "Open" in the top right-hand corner to view it.

Congratulations! You've successfully completed the process. Keep learning and exploring!

๐Ÿ’ก
If you have any questions or need help, feel free to ask in the comments section! ๐Ÿค” I would be happy to answer them!
๐Ÿ’ก
If you found the content helpful, please consider giving it a thumbs up ๐Ÿ‘ and following for more useful information. Your support is greatly appreciated!

Thanks for taking the time to read! ๐Ÿ’œ

Did you find this article valuable?

Support Akash Dhengale by becoming a sponsor. Any amount is appreciated!

ย