Working with branches, commits, and triggers

With your CodeCommit repo created, it's now time to go ahead and use this repository as our source control repository. To do so, we will first push a standard WordPress application from our local development server to the AWS CodeCommit repository using simple Git commands and later run a few more Git commands as well as AWS actions to branch and commit our code.

You can obtain a WordPress application ZIP file by downloading it from here:
https://github.com/WordPress/WordPress

To begin with, first we will need to copy the WordPress application contents over to our local repository that was cloned earlier:

  1. Once the WordPress application is downloaded to your local development server, simply unzip and copy its contents over to the local repository. Your local repository should now show a folder structure similar to the following screenshot:
  1. With the code in place, simply use the following Git commands to commit and push the code over to your AWS CodeCommit repository. First up, stage the files using the git add command:
# git add *
  1. Next, commit the changes using the git commit command:
# git commit -m "First Commit!!"
  1. And, finally, push the commit over to the AWS CodeCommit repository. Here, the keyword origin is the default remote name used by Git for your AWS CodeCommit repository, whereas master is the default branch name:
# git push -u origin master
  1. You should see the code get uploaded to your AWS CodeCommit repository, as shown in the following image. You can cross-verify this by refreshing and checking the Code page on your AWS CodeCommit dashboard as well:

Similarly, you and your fellow developers can edit and commit the code back to the AWS CodeCommit repository. You can also create multiple branches of your repository so that developers can work independently on the code without affecting the master branch. Once the features are all thoroughly tested and verified, the individual developer branches can be merged into a more stable master branch of the software.

Creating a branch in CodeCommit is an extremely easy process! You can use the CodeCommit dashboard, the Git command line, or even the AWS CLI to create one of your own:

  1. To create a branch using the AWS CodeCommit dashboard, simply select the Branches option from the navigation pane.
  2. Next, select the Create branch option to bring up the Create branch page. Here, provide a suitable Branch name and also select where you would like this new branch to Branch from. In this case, since you only have the master branch created, you can select that for now. Click on Create once done.
  3. You can also use the Git command line itself to achieve the same result. In this case, from the development server, type in the following command to create a new branch:
# git checkout -b <NEW_BRANCH_NAME>

With the new branch created, you can also use the Compare functionality provided by CodeCommit to compare the changes made to the branch against another branch. To do so, we first need to perform some changes in the application so that it can get reflected as a change.

Without changing the current branch of the repository, simply update any one of the WordPress files by adding or removing a comment. In my case, I simply made a few comment changes in the WordPress application's index.php file; however, feel free to modify any other file as you see fit. Once the changes are made, we once again need to stage, commit, and push the changes over to the new branch of our repository:

  1. Stage the changes by using the git add command. You can either add all the files for staging by using * or even specify the filename you wish to stage as well:
# git add *
  1. Next, commit the changes using the git commit command:
# git commit -m "<SOME_NEW_COMMIT_MESSAGE>"
  1. And, finally, push the changes over to the branch using the following command:
# git push origin <NEW_BRANCH_NAME>
  1. With the changes pushed, use the Compare option provided under the Commits section in the CodeCommit dashboard. Here, select the master as the source branch and the branch that you created using the Git command line as the Destination branch. Click on Compare once done. You should see the changes compared, as shown in the following screenshot:

You can use the Go to file drop-down list to toggle between different files, if you have made changes in them. Alternatively, you can also use the Unified and Split views to change the visual comparison as you see fit.

CodeCommit also provides an additional feature called triggers that you can use to either send notifications to or run some other external code build or process. You can assign up to 10 triggers per repository that you create, however, at the time of writing this book, CodeCommit only supports AWS SNS and AWS Lambda as its trigger mechanisms:

  1. To create a simple trigger, using the CodeCommit dashboard, select the Settings tab from the navigation pane. Here, select the Triggers tab to create as well as view the list of existing triggers, if any.
  2. Select the Create trigger option to bring up the Create trigger page. Here, you can configure triggers in response to certain repository events, such as Push to an existing branch, Create branch or tag, Delete branch or tag, or All repository events.
  3. Provide a Trigger name and select the appropriate Events and Branch name that you wish to associate the trigger with. Once done, you can configure the trigger to either use an existing SNS topic or a Lambda function as its Service. You can even test the functioning of the trigger by selecting the Test trigger option. This will simulate a trigger based on the event that you would have selected earlier.

In this way, you can configure triggers for sending notifications to your developers as well as trigger-specific Lambda functions based on your repository's requirements.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset