forked from edgexfoundry/edgex-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
338 lines (283 loc) · 13 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#
# Copyright 2022 Intel Corporation
# Copyright (c) 2018 Cavium
#
# SPDX-License-Identifier: Apache-2.0
#
.PHONY: build clean unittest hadolint lint test docker run
# change the following boolean flag to include or exclude the delayed start libs for builds for most of core services except support services
INCLUDE_DELAYED_START_BUILD_CORE:="false"
# change the following boolean flag to include or exclude the delayed start libs for builds for support services exculsively
INCLUDE_DELAYED_START_BUILD_SUPPORT:="true"
GO=CGO_ENABLED=0 GO111MODULE=on go
# see https://shibumi.dev/posts/hardening-executables
CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2"
CGO_CFLAGS="-O2 -pipe -fno-plt"
CGO_CXXFLAGS="-O2 -pipe -fno-plt"
CGO_LDFLAGS="-Wl,-O1,–sort-common,–as-needed,-z,relro,-z,now"
GOCGO=CGO_ENABLED=1 GO111MODULE=on go
DOCKERS= \
docker_core_data \
docker_core_metadata \
docker_core_command \
docker_support_notifications \
docker_sys_mgmt_agent \
docker_support_scheduler \
docker_security_proxy_setup \
docker_security_secretstore_setup \
docker_security_bootstrapper \
docker_security_spire_server \
docker_security_spire_agent \
docker_security_spire_config \
docker_security_spiffe_token_provider
.PHONY: $(DOCKERS)
MICROSERVICES= \
cmd/core-data/core-data \
cmd/core-metadata/core-metadata \
cmd/core-command/core-command \
cmd/support-notifications/support-notifications \
cmd/sys-mgmt-executor/sys-mgmt-executor \
cmd/sys-mgmt-agent/sys-mgmt-agent \
cmd/support-scheduler/support-scheduler \
cmd/security-proxy-setup/security-proxy-setup \
cmd/security-secretstore-setup/security-secretstore-setup \
cmd/security-file-token-provider/security-file-token-provider \
cmd/secrets-config/secrets-config \
cmd/security-bootstrapper/security-bootstrapper \
cmd/security-spiffe-token-provider/security-spiffe-token-provider
.PHONY: $(MICROSERVICES)
VERSION=$(shell cat ./VERSION 2>/dev/null || echo 0.0.0)
DOCKER_TAG=$(VERSION)-dev
GOFLAGS=-ldflags "-X github.com/edgexfoundry/edgex-go.Version=$(VERSION)" -trimpath -mod=readonly
CGOFLAGS=-ldflags "-linkmode=external -X github.com/edgexfoundry/edgex-go.Version=$(VERSION)" -trimpath -mod=readonly -buildmode=pie
GOTESTFLAGS?=-race
GIT_SHA=$(shell git rev-parse HEAD)
ARCH=$(shell uname -m)
GO_VERSION=$(shell grep '^go [0-9].[0-9]*' go.mod | cut -d' ' -f 2)
# DO NOT change the following flag, as it is automatically set based on the boolean switch INCLUDE_DELAYED_START_BUILD_CORE
NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE:=non_delayedstart
ifeq ($(INCLUDE_DELAYED_START_BUILD_CORE),"true")
NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE:=
endif
NON_DELAYED_START_GO_BUILD_TAG_FOR_SUPPORT:=
ifeq ($(INCLUDE_DELAYED_START_BUILD_SUPPORT),"false")
NON_DELAYED_START_GO_BUILD_TAG_FOR_SUPPORT:=non_delayedstart
endif
NO_MESSAGEBUS_GO_BUILD_TAG:=no_messagebus
NO_ZMQ_GO_BUILD_TAG:=no_zmq
# Base docker image to speed up local builds
BASE_DOCKERFILE=https://raw.githubusercontent.com/edgexfoundry/ci-build-images/golang-${GO_VERSION}/Dockerfile
LOCAL_CACHE_IMAGE_BASE=edgex-go-local-cache-base
LOCAL_CACHE_IMAGE=edgex-go-local-cache
build: $(MICROSERVICES)
tidy:
go mod tidy
metadata: cmd/core-metadata/core-metadata
cmd/core-metadata/core-metadata:
$(GO) build -tags "$(NO_ZMQ_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o $@ ./cmd/core-metadata
data: cmd/core-data/core-data
cmd/core-data/core-data:
$(GOCGO) build -tags "$(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(CGOFLAGS) -o $@ ./cmd/core-data
command: cmd/core-command/core-command
cmd/core-command/core-command:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o $@ ./cmd/core-command
notifications: cmd/support-notifications/support-notifications
cmd/support-notifications/support-notifications:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_SUPPORT)" $(GOFLAGS) -o $@ ./cmd/support-notifications
cmd/sys-mgmt-executor/sys-mgmt-executor:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o $@ ./cmd/sys-mgmt-executor
cmd/sys-mgmt-agent/sys-mgmt-agent:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o $@ ./cmd/sys-mgmt-agent
scheduler: cmd/support-scheduler/support-scheduler
cmd/support-scheduler/support-scheduler:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_SUPPORT)" $(GOFLAGS) -o $@ ./cmd/support-scheduler
proxy: cmd/security-proxy-setup/security-proxy-setup
cmd/security-proxy-setup/security-proxy-setup:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o ./cmd/security-proxy-setup/security-proxy-setup ./cmd/security-proxy-setup
secretstore: cmd/security-secretstore-setup/security-secretstore-setup
cmd/security-secretstore-setup/security-secretstore-setup:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o ./cmd/security-secretstore-setup/security-secretstore-setup ./cmd/security-secretstore-setup
token: cmd/security-file-token-provider/security-file-token-provider
cmd/security-file-token-provider/security-file-token-provider:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o ./cmd/security-file-token-provider/security-file-token-provider ./cmd/security-file-token-provider
secrets-config: cmd/secrets-config/secrets-config
cmd/secrets-config/secrets-config:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o ./cmd/secrets-config ./cmd/secrets-config
bootstrapper: cmd/security-bootstrapper/security-bootstrapper
cmd/security-bootstrapper/security-bootstrapper:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o ./cmd/security-bootstrapper/security-bootstrapper ./cmd/security-bootstrapper
spiffetp: cmd/security-spiffe-token-provider/security-spiffe-token-provider
cmd/security-spiffe-token-provider/security-spiffe-token-provider:
$(GO) build -tags "$(NO_MESSAGEBUS_GO_BUILD_TAG) $(NON_DELAYED_START_GO_BUILD_TAG_FOR_CORE)" $(GOFLAGS) -o $@ ./cmd/security-spiffe-token-provider
clean:
rm -f $(MICROSERVICES)
unittest:
GO111MODULE=on go test $(GOTESTFLAGS) -coverprofile=coverage.out ./...
hadolint:
if which hadolint > /dev/null ; then hadolint --config .hadolint.yml `find * -type f -name 'Dockerfile*' -print` ; elif test "${ARCH}" = "x86_64" && which docker > /dev/null ; then docker run --rm -v `pwd`:/host:ro,z --entrypoint /bin/hadolint hadolint/hadolint:latest --config /host/.hadolint.yml `find * -type f -name 'Dockerfile*' | xargs -i echo '/host/{}'` ; fi
lint:
@which golangci-lint >/dev/null || echo "WARNING: go linter not installed. To install, run\n curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b \$$(go env GOPATH)/bin v1.46.2"
@if [ "z${ARCH}" = "zx86_64" ] && which golangci-lint >/dev/null ; then golangci-lint run --config .golangci.yml ; else echo "WARNING: Linting skipped (not on x86_64 or linter not installed)"; fi
test: unittest hadolint lint
GO111MODULE=on go vet ./...
gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")
[ "`gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")`" = "" ]
./bin/test-attribution-txt.sh
docker: $(DOCKERS)
clean_docker_base:
docker rmi -f $(LOCAL_CACHE_IMAGE) $(LOCAL_CACHE_IMAGE_BASE)
docker_base:
echo "Building local cache image";\
response=$(shell curl --write-out '%{http_code}' --silent --output /dev/null "$(BASE_DOCKERFILE)"); \
if [ "$${response}" = "200" ]; then \
echo "Found base Dockerfile"; \
curl -s "$(BASE_DOCKERFILE)" | docker build -t $(LOCAL_CACHE_IMAGE_BASE) -f - .; \
echo "FROM $(LOCAL_CACHE_IMAGE_BASE)\nWORKDIR /edgex-go\nCOPY go.mod .\nRUN go mod download" | docker build -t $(LOCAL_CACHE_IMAGE) -f - .; \
else \
echo "No base Dockerfile found. Using golang:$(GO_VERSION)-alpine"; \
echo "FROM golang:$(GO_VERSION)-alpine\nRUN apk add --update make git\nWORKDIR /edgex-go\nCOPY go.mod .\nRUN go mod download" | docker build -t $(LOCAL_CACHE_IMAGE) -f - .; \
fi
ddata: docker_core_metadata
docker_core_metadata: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/core-metadata/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/core-metadata:$(GIT_SHA) \
-t edgexfoundry/core-metadata:$(DOCKER_TAG) \
.
dmetadata: docker_core_data
docker_core_data: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/core-data/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/core-data:$(GIT_SHA) \
-t edgexfoundry/core-data:$(DOCKER_TAG) \
.
dcommand: docker_core_command
docker_core_command: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/core-command/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/core-command:$(GIT_SHA) \
-t edgexfoundry/core-command:$(DOCKER_TAG) \
.
dnotifications: docker_support_notifications
docker_support_notifications: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/support-notifications/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/support-notifications:$(GIT_SHA) \
-t edgexfoundry/support-notifications:$(DOCKER_TAG) \
.
dscheduler: docker_support_scheduler
docker_support_scheduler: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/support-scheduler/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/support-scheduler:$(GIT_SHA) \
-t edgexfoundry/support-scheduler:$(DOCKER_TAG) \
.
docker_sys_mgmt_agent: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/sys-mgmt-agent/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/sys-mgmt-agent:$(GIT_SHA) \
-t edgexfoundry/sys-mgmt-agent:$(DOCKER_TAG) \
.
dproxy: docker_security_proxy_setup
docker_security_proxy_setup: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/security-proxy-setup/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/security-proxy-setup:$(GIT_SHA) \
-t edgexfoundry/security-proxy-setup:$(DOCKER_TAG) \
.
dsecretstore: docker_security_secretstore_setup
docker_security_secretstore_setup: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/security-secretstore-setup/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/security-secretstore-setup:$(GIT_SHA) \
-t edgexfoundry/security-secretstore-setup:$(DOCKER_TAG) \
.
dbootstrapper: docker_security_bootstrapper
docker_security_bootstrapper: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/security-bootstrapper/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/security-bootstrapper:$(GIT_SHA) \
-t edgexfoundry/security-bootstrapper:$(DOCKER_TAG) \
.
dspires: docker_security_spire_server
docker_security_spire_server: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/security-spire-server/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/security-spire-server:$(GIT_SHA) \
-t edgexfoundry/security-spire-server:$(DOCKER_TAG) \
.
dspirea: docker_security_spire_agent
docker_security_spire_agent: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/security-spire-agent/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/security-spire-agent:$(GIT_SHA) \
-t edgexfoundry/security-spire-agent:$(DOCKER_TAG) \
.
dspirec: docker_security_spire_config
docker_security_spire_config: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/security-spire-config/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/security-spire-config:$(GIT_SHA) \
-t edgexfoundry/security-spire-config:$(DOCKER_TAG) \
.
dspiffetp: docker_security_spiffe_token_provider
docker_security_spiffe_token_provider: docker_base
docker build \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg BUILDER_BASE=$(LOCAL_CACHE_IMAGE) \
-f cmd/security-spiffe-token-provider/Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/security-spiffe-token-provider:$(GIT_SHA) \
-t edgexfoundry/security-spiffe-token-provider:$(DOCKER_TAG) \
.
vendor:
$(GO) mod vendor