-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
74 lines (62 loc) · 2.59 KB
/
Makefile
File metadata and controls
74 lines (62 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Based on https://github.com/philpep/dockerfiles/blob/a2c3a858cb08427149875d40e085f701e62e160d/Makefile
DOCKERFILES=$(shell find * -type f -name Dockerfile)
NAMES=$(subst /,\:,$(subst /Dockerfile,,$(DOCKERFILES)))
REGISTRY?=ghcr.io/maxmilton
IMAGES=$(addprefix $(subst :,\:,$(REGISTRY))/,$(NAMES))
DEPENDS=.depends.mk
MAKEFLAGS += -rR
export DOCKER_BUILDKIT=1
.PHONY: all clean push pull run exec check checkrebuild ci $(NAMES) $(IMAGES)
all: $(NAMES)
help:
@echo "A smart Makefile for your dockerfiles"
@echo ""
@echo "Read all Dockerfile within the current directory and generate dependendies automatically."
@echo ""
@echo "make all ; build all images"
@echo "make chromium ; build chromium image"
@echo "make push all ; build and push all images"
@echo "make push chromium ; build and push chromium image"
@echo "make run chromium ; build and run chromium image (for testing)"
@echo "make exec chromium ; build and start interactive shell in chromium image (for debugging)"
@echo "make checkrebuild all ; build and check if image has update availables (using apk or apt-get)"
@echo " and rebuild with --no-cache if image has updates"
@echo "make ci ; alias to make checkrebuild all"
@echo "make publish ; alias to make checkrebuild push all"
@echo ""
@echo "You can chain actions, typically in CI environment you want make checkrebuild push all"
@echo "which rebuild and push only images having updates availables."
clean:
rm -f $(DEPENDS)
ci:
$(MAKE) checkrebuild all
publish:
$(MAKE) checkrebuild push all
.PHONY: $(DEPENDS)
$(DEPENDS): $(DOCKERFILES)
grep '^FROM \$$REGISTRY/' $(DOCKERFILES) | \
awk -F '/Dockerfile:FROM \\$$REGISTRY/' '{ print $$1 " " $$2 }' | \
sed 's@[:/]@\\:@g' | awk '{ print "$(subst :,\\:,$(REGISTRY))/" $$1 ": " "$(subst :,\\:,$(REGISTRY))/" $$2 }' > $@
sinclude $(DEPENDS)
$(NAMES): %: $(REGISTRY)/%
ifeq (push,$(filter push,$(MAKECMDGOALS)))
docker push $<
endif
ifeq (run,$(filter run,$(MAKECMDGOALS)))
docker run --rm -it $<
endif
ifeq (exec,$(filter exec,$(MAKECMDGOALS)))
docker run --entrypoint sh --rm -it $<
endif
ifeq (check,$(filter check,$(MAKECMDGOALS)))
./check_update.sh $<
endif
$(IMAGES): %:
ifeq (pull,$(filter pull,$(MAKECMDGOALS)))
docker pull $@
else
docker build --build-arg REGISTRY=$(REGISTRY) -t $@ $(subst :,/,$(subst $(REGISTRY)/,,$@))
endif
ifeq (checkrebuild,$(filter checkrebuild,$(MAKECMDGOALS)))
./check_update.sh $@ || (docker build --build-arg REGISTRY=$(REGISTRY) --no-cache -t $@ $(subst :,/,$(subst $(REGISTRY)/,,$@)) && ./check_update.sh $@)
endif