- Created a codecommit repository .
- After entering git credentials , i successfully cloned the repository .
- Created a index.html file and pushed the ffile into codecommit repository .
- CodeBuild stage needs a buildspec.yml file . So created a buildspec.yml file and pushed it to codecommit repo .
version : 0.2
phases:
install:
commands:
- echo Start with NGINX install
- sudo apt-get update
- sudo apt-get install nginx -y
build:
commands:
- echo Building...
- cp index.html /var/www/html/
artifacts:
files:
- /var/www/html/index.html
- Then created a build .
codebuild.1.mp4
10 . After this i have to store artifacts , so i created a s3 bucket . Then attached the artifacts to the codebuild stage .
- Then started building .
- Created an application on CodeDeploy
- Created an EC2 insatnce with ssh,http,https added in security group . As the ec2 insatnce needs to interact with s3 bucket , codedeploy , ec2 ,so attached the policies .
create.deployment.group.1.mp4
- Then connected the ec2 instance to create codedeploy agent .
#!/bin/bash
# This installs the CodeDeploy agent and its prerequisites on Ubuntu 22.04.
sudo apt-get update
sudo apt-get install ruby-full ruby-webrick wget -y
cd /tmp
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/releases/codedeploy-agent_1.3.2-1902_all.deb
mkdir codedeploy-agent_1.3.2-1902_ubuntu22
dpkg-deb -R codedeploy-agent_1.3.2-1902_all.deb codedeploy-agent_1.3.2-1902_ubuntu22
sed 's/Depends:.*/Depends:ruby3.0/' -i ./codedeploy-agent_1.3.2-1902_ubuntu22/DEBIAN/control
dpkg-deb -b codedeploy-agent_1.3.2-1902_ubuntu22/
sudo dpkg -i codedeploy-agent_1.3.2-1902_ubuntu22.deb
systemctl list-units --type=service | grep codedeploy
sudo service codedeploy-agent status
- Like CodeBuild stage , CodeDeploy also needs a appspec.yml for configuration and in buildspec.yml changed the artifacts files . After making all these changes then pushed the code to the codecoommit repository .
appspec.yml
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html
hooks:
AfterInstall:
- location: scripts/install_nginx_service.sh
timeout: 300
runas: root
ApplicationStart:
- location: scripts/start_nginx_service.sh
timeout: 300
runas: root
install_nginx_service.sh
#!/bin/bash
sudo apt-get update
sudo apt-get install -y nginx
start_nginx_service.sh
#!/bin/bash
sudo service nginx start
- Then created a deployment using revise location as s3 bucket's URL .
- After this i have checked whether all the files present in CodeCommit repo or not . Then again started the code build stage . Then started the deployment .
- After successful deployment then accessed the Public IP of ec2 instance to access the webpage .
- Created a pipeline
- Added the code source and choosed "AWS CodePipeline" in "change detection option" to
23.Here mentioned the build provider and project name .
- Now mentioned the AWS CodeDeploy as deploy provider and also give the application name .
- Now after all these configuartion , here i started the AWS CodePipeline . And all the stages are successfully executed.
- Then accessed webpage using public ip of ec2 instance .
- Then made some changes in the index.html and pushed the changes into codecommit repo .
- Then pipeline is automatically started .
- Then accessed the updated webpage from the public IP of ec2 instance .