On your journey of making a CI/CD pipeline on AWS with these tools, you completed AWS CodeCommit.
Next few days you'll learn these tools/services:
CodeBuild
CodeDeploy
CodePipeline
S3
What is CodeBuild?
AWS CodeBuild is a fully managed build service in the cloud. CodeBuild compiles your source code, runs unit tests, and produces artefacts 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.
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.
Create a simple index.html file in CodeCommit Repository
You have to build the index.html using the nginx server
CodeCommit
Log in to the AWS console and navigate to Codecommit > Create a repository
As we already created a repo in part 1, I am using the same repo and cloning it.
Connect to the instance and use the Git clone command
$ git clone <your-codecommit-repo-clone-https-url>
Enter the HTTPS GIT Credentials that you created and downloaded from the code commit
Now create an index.html file inside the repo and commit it to repo
Now check the repository on the CodeCommit, we should see the index.html file
Task-02 :
CodeBuild
Codebuild will be built from the CodeCommit repo files only.
Click on Build Projects> Create Build project
- Provide the source details AWS CodeCommit and Repo/branch details
We need to create a service role so that CodeBuild can communicate with CodeCommit, CodeDeploy, S3, artifact and other resources
Select New service role and the Role name will be automatically provided
We are using Use a buildspec file to run the CodeBuild, so connect to the instance and write a buildspec
Buidspec is like a configuration file that specifies a set of commands to run
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
https://github.com/rjthapaa/AWS-DevOps-Project/blob/main/buildspec.yml
Artifacts are the storage location of our S3 bucket.
Now push this buildspec.yml from local to a CodeCommit.
Review the push changes in CodeCommit
Batch configuration and Artifacts / Cloud are optional
Leave the rest to defaults and Click on Create Build project
- Our build project for Nginx is ready
- Now click on Start build and check the status
- You can check every phase in Phase details
- Add the project source code to S3 Bucket using artifacts
Select the Build project and click on Edit > Artifacts
Create an s3 bucket of your choice
Type will be the storage location - Amazon S3 and provide the Bucket name of S3.
Give an output folder in the name section to store the buildspec
Select Packaging as None
Click on Update artifacts and start build again
The build got successful and the buildspec.yml will be updated in the selected s3 bucket
Let's move to the S3 bucket and check the directory of index.html
Index.html file is copied to the specified S3 bucket from the Code build.
Select the index.html file in the S3 bucket and click on open to access the server
For more details watch this video.