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:
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.
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.
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.
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:
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.
Source Code Integration: CodeBuild integrates with source code repositories like AWS CodeCommit, GitHub, or Bitbucket to retrieve the source code for the build.
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.
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.
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:
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.
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:
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
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
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:
Go to CodeBuild:
- Navigate to the CodeBuild service in your AWS Management Console.
Create a New Build Project:
- Click on the option to create a new build project.
Provide Desired Namings:
- Give your build project a name that makes sense to you.
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.
Provide Build Environment:
- Specify how you want your build environment to be set up. For example, choose the operating system, runtime, and other configurations.
Create a New Service Role:
- If needed, create a new service role for CodeBuild to access AWS resources.
Optional: Select CloudWatch:
- If you want to monitor your build's progress with CloudWatch, select it here.
Click Create Build Project:
- Once you've configured all the settings, click on the button to create your build project.
Start Build:
- 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:
- To add artifacts to your CodeBuild project and store them in an S3 bucket, click on "edit" and select "Artifacts."
Select S3 Bucket:
Choose an existing S3 bucket or create a new one to store your artifacts.
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!