Last active
September 30, 2020 12:17
-
-
Save RollMan/380e294b916e028c539c079b4d1f533b to your computer and use it in GitHub Desktop.
Makefile which monitors docker container creation timestamp
This file contains hidden or 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
| SRC := Dockerfile src1.c src2.c | |
| OBJ := obj.o | |
| IMAGE_NAME := example_container_image | |
| CREATION_TIME := $(shell docker inspect $(IMAGE_NAME) -f {{.Created}} | xargs date +%s -d) | |
| LATEST_MOD_TIME := $(shell echo $(SRC) | xargs -n 1 date +%s -r | awk '{if(m<$$1) m=$$1} END{print m}') | |
| build: | |
| if [ -z $(CREATION_TIME) ] || [ $(LATEST_MOD_TIME) -ge $(CREATION_TIME) ]; then \ | |
| docker build . -t $(IMAGE_NAME); \ | |
| else \ | |
| echo "Docker container image is ready up to date."; \ | |
| fi | |
| $(OBJ): build $(SRC) | |
| echo "arbitrary commands" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment