github.com/weaveworks/common@v0.0.0-20230728070032-dd9e68f319d5/tools/build/Makefile (about) 1 .PHONY: all clean images 2 .DEFAULT_GOAL := all 3 4 # Boiler plate for bulding Docker containers. 5 # All this must go at top of file I'm afraid. 6 IMAGE_PREFIX := weaveworks/build- 7 IMAGE_TAG := $(shell ../image-tag) 8 GIT_REVISION := $(shell git rev-parse HEAD) 9 UPTODATE := .uptodate 10 11 # Every directory with a Dockerfile in it builds an image called 12 # $(IMAGE_PREFIX)<dirname>. Dependencies (i.e. things that go in the image) 13 # still need to be explicitly declared. 14 %/$(UPTODATE): %/Dockerfile %/* 15 $(SUDO) docker build --build-arg=revision=$(GIT_REVISION) -t $(IMAGE_PREFIX)$(shell basename $(@D)) $(@D)/ 16 $(SUDO) docker tag $(IMAGE_PREFIX)$(shell basename $(@D)) $(IMAGE_PREFIX)$(shell basename $(@D)):$(IMAGE_TAG) 17 touch $@ 18 19 # Get a list of directories containing Dockerfiles 20 DOCKERFILES := $(shell find . -name tools -prune -o -name vendor -prune -o -type f -name 'Dockerfile' -print) 21 UPTODATE_FILES := $(patsubst %/Dockerfile,%/$(UPTODATE),$(DOCKERFILES)) 22 DOCKER_IMAGE_DIRS := $(patsubst %/Dockerfile,%,$(DOCKERFILES)) 23 IMAGE_NAMES := $(foreach dir,$(DOCKER_IMAGE_DIRS),$(patsubst %,$(IMAGE_PREFIX)%,$(shell basename $(dir)))) 24 images: 25 $(info $(IMAGE_NAMES)) 26 @echo > /dev/null 27 28 # Define imagetag-golang, etc, for each image, which parses the dockerfile and 29 # prints an image tag. For example: 30 # FROM golang:1.8.1-stretch 31 # in the "foo/Dockerfile" becomes: 32 # $ make imagetag-foo 33 # 1.8.1-stretch 34 define imagetag_dep 35 .PHONY: imagetag-$(1) 36 $(patsubst $(IMAGE_PREFIX)%,imagetag-%,$(1)): $(patsubst $(IMAGE_PREFIX)%,%,$(1))/Dockerfile 37 @cat $$< | grep "^FROM " | head -n1 | sed 's/FROM \(.*\):\(.*\)/\2/' 38 endef 39 $(foreach image, $(IMAGE_NAMES), $(eval $(call imagetag_dep, $(image)))) 40 41 all: $(UPTODATE_FILES) 42 43 clean: 44 $(SUDO) docker rmi $(IMAGE_NAMES) >/dev/null 2>&1 || true 45 rm -rf $(UPTODATE_FILES) 46 47