It might be difficult to find a software engineer who does not know ‘Make’ utility. ‘GNU Make’ is a tool which controls the generation of executables and other stuff related to the application code building.
Capabilities of ‘Make’ are many ranging from simple code compilation and installation to collection of all the dependencies of an application. It is designed so nicely that we can even use it for implementing the deployment pipeline for your solution. Let us see how we can achieve this.
One of our recent needs was to automate the deployment of our services onto the cloud. Since our system is central to many other products and services, we ended up needing multiple environments to be used for distinct purposes such as functional testing, performance testing, integration, etc.
To cater to this demand for a dedicated environment, we thought of using ‘Make’ utility instead of any other cloud-specific tools. And we are so happy that our technology choice worked well. Let us walk you through the details.
We had decided to keep the number of new tools and technologies minimum and stick to the opensource technologies only, as keeping the cost of operation to the minimum was one of the constraints. We were already using the ‘Make’ tool for building our components written in ‘Go’ language. The next step for us was to use it for triggering docker image build operation, pushing the image to the private repository, and for launching/creating all cloud services required for the functioning of our services.
Makefile target rule helped us to divide the entire flow into smaller independent modules. We wrote separate target rules for each step such as building a docker image, pushing image and launching clusters, etc.
Code build and Docker image creation
build:
@echo “Code compilation …”
# Language specific build commands go here.
docker-build: build
@echo “Building docker image …”
$(DOCKERBUILD) . -t $(ENV)$(BINARY_NAME) -f $(PROJBASE)/Dockerfile
Pushing the docker image to the private repository
docker-push:
@echo “Pushing docker image to cloud hub …”
# This contains, cloud service-provider specific commands to push the docker image to the respective repository
Deploy the application to the respective cloud
deploy:
@echo “Deploying application to the environment …”
# This contains, cloud service-provider specific commands to deploy the application to the cluster.
# For example, for the AWS cloud, this will contain a cloudformation command to create a stack.
# Likewise, Terraform can also be used to deploy the application to the respective cloud.
Initiate table creation
create-table:
# This contains, creation of all the application tables.
@sh deployment/table_creation.sh
Initiate end to end deployment
e2e-deploy: docker-build docker-push create-table deploy
That is it. Isn’t it a simple yet effective approach to trigger application deployment? Moreover, it enables one to achieve application deployment to any cloud in a cost-effective manner. And, it is a cloud-agnostic way of deployment, so nothing is tightly coupled.