-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile.build
98 lines (85 loc) · 2.32 KB
/
Makefile.build
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
87
88
89
90
91
92
93
94
95
96
97
98
# Copyright (c) 2016-2025 Crave.io Inc. All rights reserved
# This template must only be included by the actual image building makefile
CONTEXT_DIR?=.
DOCKERFILE?=$(CONTEXT_DIR)/Dockerfile
DOCKER_BUILD_FLAGS:=
DOCKER_RUN_FLAGS:=
DOCKER_RUN_CMD:=
# These are the default platforms. Update this when you decide to publish more platforms.
IMGVER_TARGETS?=aarch64 s390x x86_64 ppc64le
define platform_for_uname
$(shell python3 $(shell git rev-parse --show-toplevel)/functions.py platform_for_uname $(1))
endef
ifdef SQUASH
DOCKER_BUILD_FLAGS+=--squash
endif
ifndef NOPULL
DOCKER_BUILD_FLAGS+=--pull
endif
ifdef WINDOWS
DOCKER:=docker.exe
ifdef USE_POWERSHELL
SHELL:=powershell.exe
endif
ifndef WIN_NO_ISOLATION
DOCKER_BUILD_FLAGS += --isolation=hyperv
DOCKER_RUN_FLAGS += --isolation=hyperv
endif
DOCKER_RUN_CMD+=powershell.exe
DOCKER_INT_CTR_NAME=$(shell echo '$(IMGTAG)_$(IMGVER)' | sed 's|/|_|g' | sed 's|:|_|g')
else
DOCKER:=docker
DOCKER_RUN_FLAGS+=-v ~/:/tmp/home
DOCKER_RUN_CMD+=/bin/bash
DOCKER_BUILD_FLAGS += --progress=plain
endif
ifdef NOCACHE
CACHE_FLAG:=--no-cache
else
CACHE_FLAG:=
endif
chk_pre_build:
@${MAKE} -n --no-print-directory pre_build 1>/dev/null 2>/dev/null ; if [ "$$?" = "0" ] ; then ${MAKE} pre_build ; else exit 0 ; fi
build_%: chk_pre_build
${DOCKER} buildx build \
${CACHE_FLAG} \
${DOCKER_BUILD_FLAGS} \
-f $(DOCKERFILE) \
--platform $(call platform_for_uname,$*) \
${DOCKER_EXTRA_ARGS} \
-t $(IMGTAG):$(IMGVER_BASE)_$* \
$(CONTEXT_DIR)
ifdef IMGVER_BASE
build: $(foreach var,$(IMGVER_TARGETS),build_$(var))
else
build: chk_pre_build
ifdef dockerfile_git
${DOCKER} build \
${CACHE_FLAG} \
${DOCKER_BUILD_FLAGS} \
-f $(DOCKERFILE) \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VCS_REF=$(dockerfile_git) \
${DOCKER_EXTRA_ARGS} \
-t $(IMGTAG):$(IMGVER) \
$(CONTEXT_DIR)
else
${DOCKER} build \
${CACHE_FLAG} \
${DOCKER_BUILD_FLAGS} \
-f $(DOCKERFILE) \
${DOCKER_EXTRA_ARGS} \
-t $(IMGTAG):$(IMGVER) \
$(CONTEXT_DIR)
endif
ifdef WINDOWS
${DOCKER} rm -f ${DOCKER_INT_CTR_NAME}
${DOCKER} run -i \
--name ${DOCKER_INT_CTR_NAME} \
$(IMGTAG):$(IMGVER) \
sfc /scannow
${DOCKER} commit ${DOCKER_INT_CTR_NAME} $(IMGTAG):$(IMGVER)
${DOCKER} rm -f ${DOCKER_INT_CTR_NAME}
endif
endif
include $(shell git rev-parse --show-toplevel)/Makefile.cleanpushpull