Create nice dependency of tasks#

Imagine that you need to work on complex task which has many dependencies in actions. And you would like to know what to work on first and what to work on next.

It is important to have a way how to detect dependencies and how to run only tasks which are necessary.

Example scenario#

Expected scenario is following:

  • You need to setup web server with proper domain and SSL certificate.

  • You know required steps (based on you past experience).

  • You are owning all infrastructure components - so you can do whatever you want.

  • You may not know all dependencies in actions - this can be added during work.

Now you can use Makefile to help you to know order of actions which are required.

  • This is possible by defining dependencies in Makefile (Make is doing great job for detecting dependencies).

  • This can be first step for automation - which can be added later.

Code#

Following example shows power of Makefile for detecting dependencies.

Code:

# ============================================================================
# Simple example of power from Makefile.
#
# Create list of steps which should be run (in valid order based
# dependencies).
#
# First step is target to achieve - then others tasks are based on
# dependencies.
# ============================================================================

conf_sec_page: conf_dns conf_web_srv conf_web_ssl
	@echo "STEP: Configure Secure Page"

conf_dns: have_srv inst_bind
	@echo "STEP: Configure DNS zones"

have_srv:
	@echo "STEP: Setup server"

inst_bind:
	@echo "STEP: Install and start BIND"

conf_web_srv: inst_nginx
	@echo "STEP: Configure page in WEB server"

inst_nginx: have_srv
	@echo "STEP: Install and start NGINX"

conf_web_ssl: data_csr conf_web_srv
	@echo "STEP: Configure CSR details (auto by LetsEncrypt)"

data_csr: inst_nginx
	@echo "STEP: Use LestEncrypt"

Result#

This section shows result when make is running without any arguments.

STEP: Setup server
STEP: Install and start BIND
STEP: Configure DNS zones
STEP: Install and start NGINX
STEP: Configure page in WEB server
STEP: Use LestEncrypt
STEP: Configure CSR details (auto by LetsEncrypt)
STEP: Configure Secure Page

Summary#

Result section above shows that Makefile is able to detect dependencies in actions and present them in order which one should follow to finish task mentioned in Example scenario.

In short:

  • To setup secure page, one need to first

    • setup web server

    • create domain

    • create SSL certificate

This is very powerful feature of Makefile which can be used in many scenarios.