Created
October 9, 2018 10:44
-
-
Save stephenc/550de8d71c2742504764ae94515f035a to your computer and use it in GitHub Desktop.
How to have a makefile only rebuild a docker image when needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOCKER_TAG = ... | |
.PHONY: build-image touch.build-image | |
build-image: touch.build-image .build-image | |
touch.build-image: | |
$(eval timestamp=$(shell docker inspect -f '{{ range $$i, $$e := split .Metadata.LastTagTime "T" }}{{if eq $$i 0}}{{range $$j, $$v := split $$e "-"}}{{$$v}}{{end}}{{else}}{{$$f := printf "%.8s" $$e}}{{range $$j, $$g := split $$f ":"}}{{if lt $$j 2}}{{$$g}}{{else}}.{{$$g}}{{end}}{{end}}{{end}}{{end}}' $(DOCKER_TAG) 2>/dev/null )) | |
@if [ "A$(timestamp)A" = "AA" ] ; then rm -f .build-image ; else touch -t $(timestamp) .build-image ; fi | |
.build-image: Dockerfile rootfs/* | |
docker build --tag $(DOCKER_TAG):latest . | |
@touch .build-image | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment