-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
73 lines (65 loc) · 1.8 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
define get_docker_server_os
$(shell docker version -f "{{.Server.Os}}" | sed "s/./\U&/")
endef
ifeq ($(OS),Windows_NT)
export PLATFORM=Windows
ORIGINAL_DOCKER_SERVER_OS := $(call get_docker_server_os)
else
export PLATFORM=Linux
ORIGINAL_DOCKER_SERVER_OS := Linux
endif
.PHONY: image
image: image-$(PLATFORM)
.PHONY: image-Linux
image-Linux:
$(MAKE) switchToLinux
docker buildx build . \
--target runtime-Linux \
--platform Linux \
--tag wyarde/cert-bootstrapper:latest
$(MAKE) switchBack ORIGINAL_DOCKER_SERVER_OS=${ORIGINAL_DOCKER_SERVER_OS}
.PHONY: image-Windows
image-Windows: bin
$(MAKE) switchToWindows
docker build . \
--target runtime-Windows \
--tag wyarde/cert-bootstrapper:latest
$(MAKE) switchBack ORIGINAL_DOCKER_SERVER_OS=${ORIGINAL_DOCKER_SERVER_OS}
image-%:
@echo "Invalid platform specified: '$*'. Use either 'Linux' or 'Windows' (case sensitive!)"
.PHONY: bin
bin:
$(MAKE) switchToLinux
docker buildx build . \
--target bin \
--platform $(PLATFORM) \
--output bin/
$(MAKE) switchBack ORIGINAL_DOCKER_SERVER_OS=${ORIGINAL_DOCKER_SERVER_OS}
switchTo%:
ifeq ($(OS),Windows_NT)
$(if $(subst $(call get_docker_server_os),,$*),\
@echo Switching Docker engine to $*... && \
'C:\Program Files\Docker\Docker\DockerCli.exe' -Switch$*Engine && \
sleep 1\
,\
@echo No need to switch\
)
else
$(if $(subst $(call get_docker_server_os),,$*),\
$(error Please switch Docker Engine to $* first) \
)
@echo
endif
switchBack:
ifeq ($(OS),Windows_NT)
$(if $(subst $(ORIGINAL_DOCKER_SERVER_OS),,$(call get_docker_server_os)),\
@echo Switching back Docker engine to $(ORIGINAL_DOCKER_SERVER_OS)... && \
'C:\Program Files\Docker\Docker\DockerCli.exe' -Switch$(ORIGINAL_DOCKER_SERVER_OS)Engine && \
sleep 1\
,\
@echo No need to switch back\
)
else
# Do nothing in Linux
@echo
endif