forked from eclipse/cloe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.docker
150 lines (123 loc) · 5.36 KB
/
Makefile.docker
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Makefile.docker
#
# This file defines all Docker targets.
PROJECT_ROOT := $(dir $(abspath $(lastword ${MAKEFILE_LIST})))
PROJECT_VERSION := $(shell make --no-print-directory -C ${PROJECT_ROOT} -f Makefile.package info-version)
UBUNTU_NAME := ubuntu
UBUNTU_VERSIONS := 18.04 20.04 22.04
DOCKER := DOCKER_BUILDKIT=1 docker
DOCKER_IMAGE_NAME := cloe/cloe-engine
DOCKER_IMAGE_VERSION := ${PROJECT_VERSION}
DOCKER_IMAGE := ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}
DOCKER_CONTEXT := ${PROJECT_ROOT}
DOCKER_USER_ARGS +=
DOCKER_BUILD_ARGS += --build-arg PROJECT_VERSION=${PROJECT_VERSION}
DOCKER_RUN_ARGS += --rm
ifndef (${https_proxy},)
DOCKER_NETWORK := host
DOCKER_BUILD_ARGS += --network=host \
--build-arg https_proxy="${https_proxy}" \
--build-arg http_proxy="${http_proxy}" \
--build-arg no_proxy="${no_proxy}"
DOCKER_RUN_ARGS += --network=host \
--env https_proxy="${https_proxy}" \
--env http_proxy="${http_proxy}" \
--env no_proxy="${no_proxy}"
else
DOCKER_NETWORK := internal
endif
ifeq ($(shell [ -f ${PROJECT_ROOT}/setup.sh ] && echo "true"),true)
DOCKER_BUILD_ARGS += --secret id=setup,src=${PROJECT_ROOT}/setup.sh
DOCKER_RUN_ARGS += -v "${PROJECT_ROOT}/setup.sh:/root/setup.sh"
endif
ifneq (${CONAN_PROFILE},)
DOCKER_BUILD_ARGS += --build-arg CONAN_PROFILE="${CONAN_PROFILE}"
endif
ifneq (${VENDOR_TARGET},)
DOCKER_BUILD_ARGS += --build-arg VENDOR_TARGET="${VENDOR_TARGET}"
endif
ifneq (${PACKAGE_TARGET},)
DOCKER_BUILD_ARGS += --build-arg PACKAGE_TARGET="${PACKAGE_TARGET}"
endif
ifeq (${KEEP_SOURCES},1)
DOCKER_BUILD_ARGS += --build-arg KEEP_SOURCES=1
endif
# -----------------------------------------------------------------------------
include ${PROJECT_ROOT}/Makefile.help
.PHONY: help
.SILENT: help
help::
$(call print_help_usage)
echo
$(call print_help_section, "Available Docker targets")
$(call print_help_target, all, "build and test all Ubuntu versions")
$(call print_help_target, ubuntu-VERSION, "build and test the Ubuntu VERSION image")
$(call print_help_target, build-all, "build all Ubuntu versions")
$(call print_help_target, build-ubuntu-VERSION, "build the Ubuntu VERSION image")
$(call print_help_target, test-all, "build all Ubuntu versions")
$(call print_help_target, test-ubuntu-VERSION, "test the Ubuntu VERSION image")
$(call print_help_target, run-ubuntu-VERSION, "run the Ubuntu VERSION image")
$(call print_help_target, release-all, "release all Ubuntu versions")
$(call print_help_target, release-ubuntu-VERSION, "release the Ubuntu VERSION image")
$(call print_help_target, remove-current-images, "remove and prune all ${DOCKER_IMAGE} Docker images")
$(call print_help_target, remove-all-images, "remove and prune all ${DOCKER_IMAGE_NAME} Docker images")
echo
$(call print_help_section, "User configuration")
$(call print_help_define, CONAN_PROFILE, ${CONAN_PROFILE})
$(call print_help_define, VENDOR_TARGET, ${VENDOR_TARGET})
$(call print_help_define, PACKAGE_TARGET, ${PACKAGE_TARGET})
$(call print_help_define, KEEP_SOURCES, ${KEEP_SOURCES})
$(call print_help_args_lines, DOCKER_USER_ARGS, ${DOCKER_USER_ARGS})
echo
$(call print_help_section, "Docker configuration")
$(call print_help_define, UBUNTU_NAME, "${UBUNTU_NAME}")
$(call print_help_define_lines, UBUNTU_VERSIONS, ${UBUNTU_VERSIONS})
$(call print_help_define, DOCKER, "${DOCKER}")
$(call print_help_define, DOCKER_CONTEXT, "${DOCKER_CONTEXT}")
$(call print_help_define, DOCKER_NETWORK, "${DOCKER_NETWORK}")
$(call print_help_define, DOCKER_IMAGE, "${DOCKER_IMAGE}")
$(call print_help_args_lines, DOCKER_BUILD_ARGS, ${DOCKER_BUILD_ARGS})
$(call print_help_args_lines, DOCKER_RUN_ARGS, ${DOCKER_RUN_ARGS})
echo
.SILENT: FORCE
FORCE:
# Targets containing patterns (%) cannot be made .PHONY. The standard
# solution to work around this is to add a FORCE target to the
# prerequisites of every target with patterns.
.PHONY: build-all
build-all: $(addprefix build-ubuntu-,${UBUNTU_VERSIONS})
.PHONY: test-all
test-all: $(addprefix test-ubuntu-,${UBUNTU_VERSIONS})
.PHONY: release-all
release-all: $(addprefix release-ubuntu-,${UBUNTU_VERSIONS})
ubuntu-%: FORCE build-ubuntu-% test-ubuntu-%
@echo
@echo "Completed building and testing: ${DOCKER_IMAGE}-$@"
.PHONY: all
all: $(addprefix ubuntu-,${UBUNTU_VERSIONS})
build-ubuntu-%: FORCE Dockerfile
${DOCKER} build -f Dockerfile ${DOCKER_BUILD_ARGS} ${DOCKER_USER_ARGS} \
--build-arg UBUNTU_VERSION=$* \
-t ${DOCKER_IMAGE}-ubuntu-$* \
${DOCKER_CONTEXT}
test-ubuntu-%: FORCE
docker run ${DOCKER_RUN_ARGS} ${DOCKER_USER_ARGS} ${DOCKER_IMAGE}-ubuntu-$* \
bash -ec "[ -f /root/setup.sh ] && source /root/setup.sh; make smoketest"
run-ubuntu-%: FORCE
docker run -it ${DOCKER_RUN_ARGS} ${DOCKER_USER_ARGS} ${DOCKER_IMAGE}-ubuntu-$*
release-ubuntu-%: FORCE
@test -f setup.sh || echo 'Error: require setup.sh for user authentication'
${DOCKER} run ${DOCKER_RUN_ARGS} ${DOCKER_USER_ARGS} ${DOCKER_IMAGE}-ubuntu-$* \
bash -ec 'source /root/setup.sh && upload_conan_packages'
.PHONY: require-setup-sh
require-setup-sh:
@if [ ! -f ${PROJECT_ROOT}/setup.sh ]; then \
echo "ERROR: require ${PROJECT_ROOT}/setup.sh to proceed"; \
exit 1; \
fi
.PHONY: remove-current-images
remove-current-images:
docker rmi $$(docker images --format '{{.Repository}}:{{.Tag}}' | grep '${DOCKER_IMAGE}')
.PHONY: remove-all-images
remove-all-images:
docker rmi $$(docker images --format '{{.Repository}}:{{.Tag}}' | grep '${DOCKER_IMAGE_NAME}:')