-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·86 lines (73 loc) · 3.39 KB
/
Makefile
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
75
76
77
78
79
80
81
82
83
84
85
86
##
# Running `act` uses the defined github actions to build and push the images
# We should be able to build locally for DEV, and to pull from remote
# We can have a local repo to store images and that way we only leverage GHA
##
DOCKER_ORGANIZATION ?= lostlink
DOCKER_TAG ?= dev
ENVIRONMENT = docker.env
.EXPORT_ALL_VARIABLES:
sinclude $(ENVIRONMENT)
DOCKERFILES = $(shell find * -type f -name Dockerfile)
NAMES=$(subst /,\:,$(subst /Dockerfile,,$(subst docker/,,$(DOCKERFILES))))
EXISTING_IMAGES=$(shell docker images -a | grep $(DOCKER_ORGANIZATION) | awk '{print $$3}')
PLATFORMS ?= linux/arm/v7,linux/arm64,linux/amd64
BUILD_ARGS = $(shell cat $(ENVIRONMENT) | grep -v "\#\#" | grep "\S" | awk -F "=" '{ print "--build-arg " $$1"="$$2;}' | xargs)
.PHONY: all clean push pull run exec check checkrebuild pull-base ci dev $(NAMES) $(DOCKERFILES)
help:
@echo "A WIP 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 octane ; build octane image"
@echo "make push all ; build and push all images"
@echo "make push octane ; build and push octane image"
# @echo "make run nginx ; build and run nginx image (for testing)"
# @echo "make exec nginx ; build and start interactive shell in nginx image (for debugging)"
# @echo "make checkrebuild all ; build and check if image has update availables (using https://github.com/philpep/duuh)
# @echo " and rebuild with --no-cache is image has updates"
@echo "make pull-base ; pull base images from docker hub used to bootstrap other images"
# @echo "make ci ; alias to make pull-base 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."
all: $(NAMES)
clean:
ifeq ($(EXISTING_IMAGES),)
@echo "No images to remove in the $(DOCKER_ORGANIZATION) namespace"
else
docker rmi --force $(EXISTING_IMAGES)
endif
# TODO: Allow to pass in versions from .env
pull-base:
docker pull redis:$(REDIS_TAG)
docker pull getmeili/meilisearch:$(MEILISEARCH_TAG)
docker pull mysql:$(MYSQL_TAG)
docker pull php:$(PHP_TAG)
$(NAMES): %: %/Dockerfile
#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)))
# duuh $<
#endif
## TODO: Read GithubActions when building locally
$(DOCKERFILES): %:
ifeq (pull,$(filter pull,$(MAKECMDGOALS)))
docker pull $(addprefix $(subst :,\:,$(DOCKER_ORGANIZATION)/),$(subst /,\:,$(subst /Dockerfile,,$(subst docker/,,$@))))
endif
ifeq (push,$(filter push,$(MAKECMDGOALS)))
act -j $(subst /Dockerfile,,$@)
endif
ifeq (dev,$(filter dev,$(MAKECMDGOALS)))
docker buildx build --load --platform linux/arm64 --tag $(addprefix $(subst :,\:,$(DOCKER_ORGANIZATION)/),$(subst /,\:,$(subst /Dockerfile,,$@))):$(DOCKER_TAG) $(BUILD_ARGS) -f $@ ./$(subst /Dockerfile,,$@)/.
else
docker buildx build --platform $(PLATFORMS) --tag $(addprefix $(subst :,\:,$(DOCKER_ORGANIZATION)/),$(subst /,\:,$(subst /Dockerfile,,$@))):$(DOCKER_TAG) $(BUILD_ARGS) -f $@ ./$(subst /Dockerfile,,$@)/.
endif