Skip to content

Instantly share code, notes, and snippets.

@RollMan
Last active September 30, 2020 12:17
Show Gist options
  • Select an option

  • Save RollMan/380e294b916e028c539c079b4d1f533b to your computer and use it in GitHub Desktop.

Select an option

Save RollMan/380e294b916e028c539c079b4d1f533b to your computer and use it in GitHub Desktop.
Makefile which monitors docker container creation timestamp
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