I have a project with multiple Dockerfiles, each located in a named directory that I use as the Docker image tag. I need to build, test, and push each a docker image for each Dockerfile. What do I need to do to make something such as the following work with GNU Make?
# BUILDS needs to be a list of directories, not a list of Dockerfiles
BUILDS := $(wildcard */Dockerfile)
VERSION := $(shell git rev-parse --short=12 --verify HEAD)
DOCKER_REPO_URL := quay.io/reponame
define docker_build =
$(1):
@echo "Building $$@"
docker build -t $$@ --force-rm $$@
endef
define docker_test =
$(1):
@echo "Testing $$@"
docker inspect $$@
docker run --rm $$@ help
endef
define docker_push =
$(1):
@echo "Pushing $$@"
docker tag $$@ $(DOCKER_REPO_URL):$$@-$(VERSION)
docker push $(DOCKER_REPO_URL):$$@-$(VERSION)
docker tag $$@ $(DOCKER_REPO_URL):$$@
docker push $(DOCKER_REPO_URL):$$@
endef
.PHONY: all build test release clean
all: build test release
build: $(BUILDS)
$(foreach build,$(BUILDS),$(eval $(call docker_build,$(build))))
test: $(BUILDS)
$(foreach test,$(BUILDS),$(eval $(call docker_test,$(test))))
release:
$(foreach image,$(BUILDS),$(eval $(call docker_push,$(image))))