Part 2 — HumanGov Application — Git-GitHub-2: Implementation of Git Repositories for Application and Infrastructure Code Using AWS CodeCommit and Proof of Concept (PoC) Process of Commit, Push, and Revert Code Changes

Cansu Tekin
8 min readMay 4, 2023

--

HumanGov is a software-as-a-service (SaaS) cloud company that will create a Human Resources Management SaaS application for the Department of Education across all 50 states in the US and host the application files and databases in the cloud. Whenever a new employee is hired, a new registry will be created for this employee inside this application.

In this following project series, we are going to transition the architecture from a traditional virtual machine architecture to a modern container-based architecture using Docker containers and Kubernetes running on AWS. In addition, we will also be responsible for automating the complete software delivery process using Pipelines CI/CD using AWS services such as AWS CodeCommit, AWS CodePipeline, AWS CodeBuild, and AWS CodeDeploy. Finally, we will learn how to monitor and observe the cloud environment in real-time using tools such as Prometheus, Grafana, and automate one-off cloud tasks using Python and the AWS SDK.

In this section, we are going to introduce Git and GitHub and practice with cloud provider AWS before using them in the implementation of the HumanGov application. This is the 2nd part of a project series. Check Part 1 to follow up.

HumanGov is a software services company that has human resources application that is going to serve to Department of Education helping them to store their employees' data. As a DevOps Engineer, the responsibility is maintaining Git repositories that the software developer team can store and update the application source code collaboratively. Additionally, whether everything related to the cloud infrastructure is working properly should be monitored. You are also required to store the configuration files you created to automate the provisioning process of the application in the remote Git repository.

We are going to store Git repositories for the HumanGov application and infrastructure code using the AWS-managed Git repository service called AWS CodeCommit instead of GitHub and its integration with other AWS DevOps services. You will also create a Proof of Concept (PoC) to validate the common tasks software developers do on a daily basis while committing the software changes, pushing the local repository to a remote repository, and reverting code changes.

This project consists of 2 parts:

Part 1: Implementation of Git Repositories

Part 2: Proof of Concept (PoC) Process of Commit, Push, and Revert Code Changes

We are going to use Cloud 9 environment for this project. Please visit the link below for the first introduction part of this project before starting implementation.

Part 1: Implementation of Git Repositories

AWS CodeCommit is a fully-managed source control service that hosts secure and highly scalable private Git repositories. Cloud9 can integrate with CodeCommit.

We are going to store Git repositories inside the AWS us-east-1 region.

Step 1: Create an AWS CodeCommit Repository to store HumanGov application files

Step 2: Create an AWS CodeCommit Repository to store the infrastructure configuration Files (.tf, .yaml, Dockerfile) for the HumanGov application

Step 3: Open Cloud9 to configure the AWS CLI credential helper on the AWS Cloud9 EC2 development environment to connect the Git repositories inside CodeCommit

On the AWS Cloud9 EC2 development environment, you can write code and build, run, test, debug, and release software using the CodeCommit repository. The AWS Cloud9 EC2 development environment is generally preconfigured with the AWS CLI, an Amazon EC2 role, and Git.

# Configure a user name and email to be associated with Git commits for the DevOps Engineer
git config --global user.name "Cansu - DevOps Engineer"
git config --global user.email <your email>

We will be able to synchronize the CodeCommit repository with Cloud9 without using a password with the following configuration.

# Configure the AWS CLI credential helper for HTTPS connections
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

Step 4: Clone CodeCommit repositories human-gov-application and human-gov-infrastructure into your AWS Cloud9 EC2 development environment

In the terminal, run the git clone command, specifying the HTTPS clone URL of the repository. You can find the Clone URL for your repository in the CodeCommit console by choosing Clone URL.

It is not going to ask for any password because Git is pre-authenticated with GitCommit inside Cloud9 from the previous step.

git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/human-gov-infrastructure
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/human-gov-application

You can now see empty folders for these repositories inside Cloud9 with the hidden .git repository that came from CodeCommit.

Part 2: Proof of Concept (PoC) Process of Commit, Push, and Revert Code Changes

Step 1: Create a Cloud9 environment for Software Developer 1 and Software Developer 2

The humangov environment we created before belongs to us as DevOps Engineer. We need new environments for the software developers working on the same project.

Software Developer 1 is responsible for developing the HumanGov application inside the human-gov-application local repository and pushing it to the AWS CodeCommit remote repository.

Software Developer 2 is responsible for debugging and correcting bugs made by Software Developer 1.

In PoC, developers would have their own AWS account and Cloud9 environment. We are going to do a simulation here.

Step 2: Configure the Cloud9 environment for Software Developer 1

Open the Cloud9 environment for Software Developer 1 and do a configuration similar to the configuration of the humangov environment.

git config --global user.name "Software Developer 1"
git config --global user.email ctekin22@gmail.com

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

# Clone the Code Commit repository human-gov-application
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/human-gov-application

Step 3: Create a file index.html inside the human-gov-application repository under the humangov-developer1 Cloud9 repository with the first version of the HumanGov application

Step 4: Create and push the first commit to PoC

# Add index.html to the staging area
git add .
# Commit the changes to the git repository
git commit -m "first commit to PoC"
# check the commit
git log

The commit is inside our local Cloud9 repository now. We need to push this repository to the remote repository CodeCommit. We already cloned the human-gov-application environment from CodeCommit to Cloud9 and it has the configuration inside for the origin to send files to CodeCommit. Unlike GitHub, it is not going to ask for a password for this because CodeCommit and Git are fully integrated inside Cloud9.

git push -u origin master

You can go and check CodeCommit remote repository human-gov-application to see if the commit for the index.html is pushed.

You can also see the commit history and details here.

Step 5: Create a typo in the Header, commit, and push the change

Let's say Software Developer 1 will make a mistake in the index.html and pushed this to the remote repository with this mistake. Software Developer 2 will correct it.

Step 6: Configure the Software Developer 2 Cloud9 environment

Open Cloud9 IDE for humangov-developer2 for Software Developer 2 we created before. Appy very similar steps as you did for Software Developer 1 Cloud9 environment configuration.

git config --global user.name "Software Developer 2"
git config --global user.email <email address>

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

Software Developer 2 needs to clone the CodeCommit repository human-gov-application to be able to access, upload and change the application file inside the Cloud9 environment.

git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/human-gov-application

Step 7: Revert the last commit

Check the last changes first so you can figure out how you can fix the issue without affecting users and the application in the production environment before completely fixing the problem.

git log

We have 2 commits for now and the last one is related to the header. Reverting this commit may solve the issue.

Rollback to the last commit reverting the changes in it all way back to the previous commit using its hash.

git revert 6762a193c78e89b797df41b60be7042d375c0b94

Once we run that, it is going to open a nano text editor asking for a confirmation and a description for the revert. Git will put the description inside the git log. We are going to keep it as default for now and exit.

It is going to add a new commit showing revert.

Check the index.html preview if the issue is fixed.

It is fixed!

Step 8: In addition to fixing the issue, make a change

For example, change the header from h1 to h2, commit the changes, and push changes to the remote repository.

git add index.html
git commit -m "fixed header size"
git status
git push -u origin master

Now we have the latest version of the source code. You can see all the commits we executed until now inside CodeCommit.

We are going to provision the HumanGov application using infrastructure as code in the following project.

CONGRATULATIONS!!!

--

--

Cansu Tekin

AWS Community Builder | Full Stack Java Developer | DevOps | AWS | Microsoft Azure | Google Cloud | Docker | Kubernetes | Ansible | Terraform