- CodeCommit
- CodeBuild
- CodeDeploy
- CodePipeline
- Identity and Access Management (IAM) for creating Service Role
- S3 for artifact storing
- EC2 for Deployment
- After creating a repository on the next page you can see this warning.π
-
Go to IAM and create a User
-
User can not get permission to access AWS CodeCommit, So first gives permissions in IAM. (IAM -> Users -> Security credentials -> HTTPS Git credentials for CodeCommit -> Generate)
-
After this click on the Clone URL button.
-
Also, Add permission to the User get to access this repo on Local. (IAM -> Users -> SelectUser -> Add permissions -> Attach policies directly -> 'AWSCodeCommitPowerUser')
-
After performing some GitHubActions and pushing all files in CodeCommit.
- Master is default branch.
-
GO to IAM and create Service Role for CodeBuild Service Role ("Access Service-Service") (IAM -> Create Role -> AWS service -> Use case -> Create)
-
Create a buildSpec file.
buildspec.yml
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 `data` - cp index.html /var/www/html/ post_build: commands: - echo Configuring NGINX artifacts: files: - '**/*'
- Push this buildspec.yml file in CodeCommi.
- After you can Start to Build CodeBuild Project ss
- In the CodeBuild console Click on Edit button -> Artifacts -> Type:"S3" -> put Uplode Locetion. s3 artifect files ss
- Create Application and Compute platform is EC2/On-premises
- Create Deployment group
- Create Service role (Give permissions -1.AmazonEC2FullAccess 2.AmazonEC2RoleforAWSCodeDeploy 3. AmazonS3FullAccess 4.AWSCodeDeployeFullAccess 5.AWSCodeDeployRole 6.AmazonEC2RoleforAWSCodeDeployLimitaccesstoS3)
- Deployment type - In-place
- Environment configuration - Amazon EC2 instances
- Click Launch Instances
- Ubuntu t2.micro
- Connect to the server and run this command to convert it into a Root user
sudo su
-
First of all select instance -> Actios -> Security -> Modify IAM role -> select relevant role
-
After running this script for setup deployingAgent on the EC2 instance
-
Make sure your Rigeon and Script regions same.(6th line in this script)
#!/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
- Create appspec.yml for App configuretion
appspec.yml
version: 0.0 os: linux files: - source: / destination: /var/www/html hooks: AfterInstall: - location: scripts/install_nginx.sh timeout: 300 runas: root ApplicationStart: - location: scripts/start_nginx.sh timeout: 300 runas: root
-
And Also create scripts folder
-
In scripts folder create two files
- install_nginx.sh
#!/bin/bash sudo apt-get update sudo apt-get install -y nginx
- start_nginx.sh
#!/bin/bash sudo service nginx start
-
Push this file on CodeCommit
-
After Deployment group is create then Create deployment.
-
Step 1: Choose pipeline setting -> PipelineName > Service role
-
Step 2: Add source stage -> CodeCommit > repoName > branchName > Select CodePipeline periodically for changes(For autometion)
-
Step 3: Add build stage -> BuildProvider > Region > ProjectName > Single build
-
Step 4: Add deploy stage -> DeployProvider > Region > AppName > Deployment group
-
Step 5: Review