Skip to content

Instantly share code, notes, and snippets.

@rbuckland
Last active March 3, 2016 11:34
Show Gist options
  • Save rbuckland/6372fcbec49552d97d1c to your computer and use it in GitHub Desktop.
Save rbuckland/6372fcbec49552d97d1c to your computer and use it in GitHub Desktop.
a dockerfile makefile experiemtn
#
#
#
#
DOCKER_IDENTITY_FILE = .docker-identity
# this makes a list of all the "docker directories" eg: image1 image2
docker_images := $(shell find . -maxdepth 2 -mindepth 2 -type f -name Dockerfile | xargs -L1 dirname | xargs -L1 basename )
# this makes a list of image1/Dockerfile image2/Docerfile
docker_files := $(docker_images:%=%/Dockerfile)
# this makes a list of image1/.docker-identity image2/.docker-identity
docker_identities := $(docker_files:%Dockerfile=%$(DOCKER_IDENTITY_FILE))
$(docker_images): $(docker_identities)
%/$(DOCKER_IDENTITY_FILE): %/Dockerfile
$(info :: Creating docker $<)
@imagename=$(shell dirname $<) ; \
(cd $$imagename && docker build -t $$imagename .) && \
docker inspect -f '{{.Id}}' $$imagename > $$imagename/$(DOCKER_IDENTITY_FILE)
.PHONY: $(docker_images) clean all
all : build
build : $(docker_images)
clean:
find . -type f -name $(DOCKER_IDENTITY_FILE) -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment