Using Make For Your Docker Builds

I create, build, publish and maintain a lot of docker images these days and I’m always struggling with a good build system.
Some projects which stand on their own like the Payara project I let build by
the Docker hub itself, but what if you have lots of docker images and don’t want or have the auto build function available?

At first I used shell scripts but they became ugly and unmaintainable fast and finally to my huge surprise my choice of build
tools was make

Problem

You have lots of docker images to maintain for a single project and want a consistent build system but don’t know how.

Solution

Use make and a Makefile.

howto

On a Mac and Linux machine the command-line tool make is standard available which make using it incredibly easy.
What I’ve tried to do is create a way of defining my build targets in such a way that if you adhere to the convention you have a very easy
to use build tool.

In order to maintain images for a project I choose to create a directory structure like the one below.
Essentially a main project directory with the Makefile in it and top level sub-directories with a Dockerfile
and optional extra files needed for the image.

The top level sub-directories represent the name of the image as it should be published as and that combined
with a VERSION and REGISTRY as defined in the makefile.env file it represents the fully qualified name
if the image.

makefile.env:

Below you see the full Makefile and by typing make help you will get the help needed.
What this Makefile makes does is to make it possible to have a consistent build and versioning mechanism for
all the images in the project.
It is also possible to build or release just one of the project images, without having to change the Makefile at all.

Discussion

If you know a better way of doing this please let me know as I am constantly searching for a more efficient way.