Automation using GitHub Events
Before starting with GitHub events I would like to explain two important terms in short which makes up the base for this Automation practice with GitHub events.
Continuous Integration is the practice of testing each change done to your code automatically and as early as possible.
Continuous Deployment follows the testing that happens during Continuous Integration and pushes changes to a staging or production system. This makes sure a version of your code is accessible at all times.
To enable Continuous Integration and Continuous Deployment with your Git Repository, let’s explore about integrating GitHub events with two major resources i.e. with Docker and Amazon SNS. GitHub provides us with many more options to integrate with.
Let’s dive deeper into how these integrations can help us in automating the Build process. Docker is a popular name when it comes to Containerization technology. Dockerizing an application is the process of converting an application to run within a Docker container. Dockerfile is what makes your application easy to Build, Ship and Run. Many times, your application requires changes which leads to changing of the Dockerfile. The Build process can be automated through GitHub events. Upload your Dockerfile and other essentials for its Build to a GitHub Repo. Now you can configure GitHub Events for youre Repository. The GitHub events when integrated with your Docker Hub Registry initiate a Build process for your Docker image for every commit in the Repository.
Sign in to your Docker Hub account and go to Settings. Click on Linked Accounts & Services
Next, click on Link GitHub and then you can easily link your GitHub Account.
Under Create, click on Create Automated Build and choose the Repository containing Dockerfile for your Docker Image. After configuring your Git Repo, let’s add a trigger for automated Build. Go to Build settings and add the trigger along with specifying the Branch and Tag for your image. Click on trigger and Save changes. This will start a Build for your Docker image by using the Dockerfile you specified in the earlier step.
Now for every commit pushed to the Git Repo will automate a new Build so that your Docker image can remain updated. By this, there is no worry to rebuild the image manually and then push to the docker hub. As changes are committed, the docker image changes and hence one can pull the updated image directly with latest tag.
Let’s move to the second integration and explore about more possibilities through Amazon SNS.
Amazon Simple Notification Service:
Amazon Simple Notification Service (SNS) is a flexible, fully managed pub/sub messaging and mobile notifications service for coordinating the delivery of messages to subscribing endpoints and clients. Github events publish to SNS Topic
Go to AWS SNS console, Click on Create new topic. Give Topic name and Display name of your choice.
In order to receive Events from Git for your Repository through Amazon SNS topic which we created in the earlier step, head over to Git repo Settings.
1. Go to settings of your Git Repository and under Integration & Services, click on Add Service and Select Amazon SNS. Pass your AWS user credentials and SNS topic ARN.
Now, again for every commit in the repo, a notification through SNS will be initiated containing particular information about the commit. To get familiar with what information Events provide to us, follow the below link and find out which information suits your needs.
Play intelligently with the GitHub event details the SNS provides us with to automate the GitHub Repo related events. Amazon SNS being Instantaneous, push-based delivery is a versatile option for building and integrating loosely-coupled, distributed applications. Further, SNS can be integrated with Amazon SQS, Lambda and many other AWS Service. Lambda being a major game player for Serverless Computing can be triggered in response of SNS Events received. As changes are committed one can use Lambda or SQS to perform further processing and can even compare the new code quality by launching tasks through Lambda to evaluate the code before pushing it into Deployment.
If you found the post helpful then please do Recommend :)