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 own build servers.
Task-01 :
- Read about 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
Add a new file from local and commit to your local branch
- Push the local changes to CodeCommit repository.
Add the new file to your local branch using the following command:
git add <filename>
git commit -m "added new file"git push -fu origin main
Verify that the changes have been pushed to the CodeCommit repository:
Go to the code commit repository that you created earlier, you should see the new file listed in the repository’s files.
- You have to build the index.html using nginx server , so below is buildspec.yml 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
Here’s what each step of the build does:
version: 0.2 specifies the version of the Buildspec syntax we’re using.
phases contains the build phases for our project.
install: Installs nginx on the build environment using the apt-get package manager.
build: Copies the index.html file to the default web root directory for nginx.
post_build: Performs any additional configuration for nginx, if necessary.
artifacts: Specifies the location of the index.html file to be included in the build artifact.
Save the file and commit the changes to the repository using the git add and git commit commands.
git add <filename>
git commit -m "added spec file"
git push -fu origin main
Task-02 :
Add buildspec.yaml file to CodeCommit Repository and complete the build process.
Go to CodeBuild:
Terms you should know about:
version: 0.2 specifies the version of the Buildspec syntax we're using.
phases contains the build phases for our project.
install: Installs nginx on the build environment using the apt-get package manager.
build: Copies the index.html file to the default web root directory for nginx.
post_build: Performs any additional configuration for nginx, if necessary.
artifacts: Specifies the location of the index.html file to be included in the build artifact.
Save the file and commit the changes to the repository using the git add and git commit commands.
Push Buildspec.yml file to main repo:
Create code Build now:
In source section, select source provider AWS CodeCommit, select Repository that you created earlier and select branch main.
Click on build project:
Edit Artifacts i.e.output can be saved in same.
Create S3 bucket and provide the name in Artifact like below.