Logo

dev-resources.site

for different kinds of informations.

6-part series - (4) Create, clone a CodeCommit Repo, move-push the Dockerfile and index.html to remote repository master branch

Published at
2/16/2023
Categories
codepipeline
codecommit
docker
ecr
Author
awsmine
Author
7 person written this
awsmine
open
6-part series - (4) Create, clone a CodeCommit Repo, move-push the Dockerfile and index.html to remote repository master branch

In this 6-part series on configuring a CI/CD pipeline using Customized Docker image on an Apache Web Server, Application Load Balancer, ECS, ECR, CodeCommit, CodeBuild, CodeDeply services -

In the 4th article, We will create a CodeCommit Repository, and with proper permissions to IAM User, Using SSH public keys we will authenticate access to AWS CodeCommit, then Clone the repository and we will move the Dockerfile and index.html inside the repo and push them to remote repository master branch.

1st article

2nd article

3rd article

Let’s get started!

Please visit my GitHub Repository for Docker/ECS/ECR articles on various topics being updated on constant basis.

Objectives:

1. Create a CodeCommit repository called "my-codecommit-repo"

2. Assign permissions to IAM User to access CodeCommit

3. Use SSH public keys to authenticate access to AWS CodeCommit

4. Clone the repository

5. Move the Dockerfile and index.html inside the repo and push them to remote repository master branch

Pre-requisites:

  • AWS user account with admin access, not a root account.
  • AWS CLI.

Resources Used:

CodeCommit

AWS CodePipeline

Steps for implementation to this project

1. Create a CodeCommit repository called "my-codecommit-repo"

  • On the Codecommit dashboard, Repositories, Create repository, my-codecommit-repo, Description - my-codecommit-repo, Tags, Name, Value - my-codecommit-repo

  • Create

Image description

  • On the connection steps page

  • There are 3 types of connections, HTTPS, SSH and HTTPS (GRC)

  • I am going to be working with SSH connection

Image description

2. Assign permissions to IAM User to access CodeCommit

  • On IAM Dashboard, Users, goti2, Permissions tab, Add permissions, Attach policies directly, Search and select AWSCodeCommitPowerUser, Next, Review and Add permissions

3. Use SSH public keys to authenticate access to AWS CodeCommit

  • SSH into the EC2 Instance thru Putty

  • Go to the docker folder using the command

sudo su
cd /opt/docker
Enter fullscreen mode Exit fullscreen mode
  • Install git
yum install git -y
Enter fullscreen mode Exit fullscreen mode

Image description

  • Generate the public and private keys for Git and CodeCommit
ssh-keygen
Enter fullscreen mode Exit fullscreen mode

Image description

  • Go to the SSH keys location
cd ~/.ssh/
Enter fullscreen mode Exit fullscreen mode
  • command "ll" to check.

Image description

  • In order to access the CodeCommit through SSH, we need to copy and paste the SSH public key in IAM User

  • Use the following command to copy the public key content

cat id_rsa.pub

Enter fullscreen mode Exit fullscreen mode
  • On the IAM console, Users, click on the user - goti2, Go to the Security credentials tab and under SSH Keys for AWS CodeCommit, Click on Upload SSH public key

Make sure to paste it properly to avoid errors in the future

  • Once pasted, click on Upload SSH public key, you can see the SSH Key ID

  • Copy the SSH Key ID for future reference.

APKAT7SS6ZVXC6LRIFXL
Enter fullscreen mode Exit fullscreen mode

Image description

  • Back to the CodeCommit, SSH connection page, Linux, Step 3, Copy the 3 lines of code in step 3
Step 3: Edit Local SSH Configuration

Edit your SSH configuration file named "config" in your local ~/.ssh directory. Add the following lines to the file, where the value for User is the SSH Key ID you copied in Step 2.

Host git-codecommit.*.amazonaws.com
User Your-IAM-SSH-Key-ID-Here
IdentityFile ~/.ssh/Your-Private-Key-File-Name-Here

Once you have saved the file, make sure it has the right permissions by running the following command in the ~/.ssh directory.

chmod 600 config
Enter fullscreen mode Exit fullscreen mode
  • In the .ssh directory, Create a file - name it config
Host git-codecommit.*.amazonaws.com
User APKAT7SS6ZVXC6LRIFXL
IdentityFile ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode
  • To change the permissions for the config file
chmod 600 config
Enter fullscreen mode Exit fullscreen mode

Image description

  • Go to the docker folder
cd /opt/docker

Enter fullscreen mode Exit fullscreen mode

4. Clone the repository

  • Clone command from the SSH page in CodeCommit
Clone your repository to your local computer and start working on code. Run the following command

git clone ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-codecommit-repo
Enter fullscreen mode Exit fullscreen mode

Image description

5. Move the Dockerfile and index.html inside the repo and push them to remote repository master branch

  • Go to the docker folder
sudo su
cd /opt/docker
Enter fullscreen mode Exit fullscreen mode
  • Move the dockerfile and index.html file to my-codecommit-repo
mv dockerfile index.html my-codecommit-repo/

cd my-codecommit-repo

ls -lt
Enter fullscreen mode Exit fullscreen mode

Image description

  • to add all the files to the git
git add .

Enter fullscreen mode Exit fullscreen mode
  • Check the status
git status
Enter fullscreen mode Exit fullscreen mode

Image description

  • Commit the files

Image description

  • Pushing the files into the remote repository’s master branch
git push

Enter fullscreen mode Exit fullscreen mode

Image description

  • to the CodeCommit repository and check the files.

Image description

What we have done so far

  • We have successfully created a CodeCommit Repository, authenticated using SSH public keys, cloned the repository, and moved the Dockerfile and index.html inside the repo and pushed them to remote repository master branch.
codepipeline Article's
30 articles in total
Favicon
Streamlining CI/CD with AWS CodePipeline and GitHub Actions: A DevOps Perspective
Favicon
New Free CI/CD Platform Enhances Mobile App Deployment: A Comprehensive Solution for Developers
Favicon
AWS CodePipeline introduces the Commands action that enables customer to easily run shell commands as part of pipeline execution
Favicon
AWS CodePipeline V2 type pipelines supports to automatically retry a stage if there is a failure in the stage.
Favicon
Automate Application Deployment to AWS Elastic Beanstalk with Terraform and CodePipeline
Favicon
Say Goodbye to Extra CodeBuild Projects: AWS CodePipeline’s New Commands Action Explained
Favicon
AWS CodePipeline V2 type pipelines introduces pipeline variable check rule
Favicon
Deploying Flutter Web to S3 with CodeCommit, Codepipeline, Codebuild, and CodeDeploy
Favicon
Update Github token in Codepipeline with Cloudformation
Favicon
Setting up CI/CD in AWS with CodeCommit, CodeDeploy, CodePipeline, ECR, and ECS
Favicon
Creating a Continuous Delivery Pipeline in AWS (Hands-On)
Favicon
Deploy NodeJS REST API on ECS Fargate using AWS CodePipeline
Favicon
Automatizando infraestructura tecnolĂłgica con DevOps
Favicon
Review of Elastic beanstalk, CodeDeploy, CodePipeline, CodeBuild
Favicon
Despliega tu Asistente de IA Generativa en AWS
Favicon
UI Devs on AWS Should Start with Amplify
Favicon
Blue-Green deployment with GitLab CI and CodePipeline on an AWS ECS cluster
Favicon
Part 1: Pipeline fun with AWS
Favicon
Extending CloudFormation's Power: Creating Custom Resources for Enhanced AWS Resource Management
Favicon
ÂżQue es la cultura DevOps?
Favicon
Receive Slack Notification of CodePipeline with SNS and Lambda
Favicon
Deploy S3 hosted application using CodePipeline
Favicon
Continuous Cloning of CodeCommit Repo in Multiple Regions Using CodeBuild and CodePipeline
Favicon
Cross account deployments using a Customer Managed KMS key
Favicon
3-part series - (3) Create a CodePipeline pipeline and deploy the application on the instance
Favicon
3-part series - (1) Launch an EC2 Instance, Install CodeDeploy Agent and upload App_Linux.zip file to version enabled S3 bucket
Favicon
6-part series - (5) Create a CodeBuild Project, upload the code and push it to the master repository
Favicon
6-part series - (4) Create, clone a CodeCommit Repo, move-push the Dockerfile and index.html to remote repository master branch
Favicon
Sexiest way to manage your AWS resources
Favicon
Building applications with pipelines

Featured ones: