-
Notifications
You must be signed in to change notification settings - Fork 99
/
Makefile
682 lines (584 loc) · 28.3 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
ifeq ($(TMPDIR),)
TMPDIR := /tmp/
endif
ifneq ("$(wildcard ./rules.env)","")
include rules.env
export $(shell sed 's/=.*//' rules.env)
endif
SHELL := /bin/bash
# Set branch name to the name of the branch to which this file belongs. This must be updated
# when a new branch is created. Development on the main (master) branch should leave this variable empty.
# DO NOT set this variable to the branch in which you are doing development work.
BRANCH_NAME ?= ""
export VERSION ?= 2.32.0
# BUILD_NUMBER will be added to the version if set. It can be a simple number or something like a numeric timestamp or jenkins hash.
# It can NOT contain dashes, but can contain: plus, period, and tilde.
export BUILD_NUMBER
# only set DISTRO if the artifact needs to be built differently for this distro. Value can be like "ubuntu" or "ubuntu.bionic". Will be appended to BUILD_NUMBER
export DISTRO
ifdef BUILD_NUMBER
BUILD_NUMBER := -$(BUILD_NUMBER:-%=%)
endif
# This sets the version in the go code dynamically at build time. See https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications
GO_BUILD_LDFLAGS := -X 'github.com/open-horizon/anax/version.HORIZON_VERSION=$(VERSION)$(BUILD_NUMBER)'
EXECUTABLE := anax
export CLI_EXECUTABLE := cli/hzn
export CLI_CONFIG_FILE := cli/hzn.json
CLI_HORIZON_CONTAINER := anax-in-container/horizon-container
export CLI_MAN_DIR := cli/man1
export CLI_COMPLETION_DIR := cli/bash_completion
DEFAULT_UI = api/static/index.html
# used for creating hzn man pages
CLI_TEMP_EXECUTABLE := cli/hzn.tmp
IMAGE_REPO ?= openhorizon
IMAGE_OVERRIDE ?= ""
# by default, do not use upx
USE_UPX ?= false
ANAX_CONTAINER_DIR := anax-in-container
ANAX_IMAGE_VERSION ?= $(VERSION)
ANAX_IMAGE_BASE = $(IMAGE_REPO)/$(arch)_anax
ANAX_IMAGE = $(ANAX_IMAGE_BASE):$(ANAX_IMAGE_VERSION)
ANAX_IMAGE_STG = $(ANAX_IMAGE_BASE):testing$(BRANCH_NAME)
ANAX_IMAGE_PROD = $(ANAX_IMAGE_BASE):stable$(BRANCH_NAME)
# the latest tag is the same as stable
ANAX_IMAGE_LATEST = $(ANAX_IMAGE_BASE):latest$(BRANCH_NAME)
ANAX_IMAGE_LABELS ?= --label "name=$(arch)_anax" --label "version=$(ANAX_IMAGE_VERSION)" --label "release=$(shell git rev-parse --short HEAD)"
# By default we do not use cache for the anax container build, so it picks up the latest horizon deb pkgs. If you do want to use the cache: DOCKER_MAYBE_CACHE='' make anax-image
DOCKER_MAYBE_CACHE ?= --no-cache
I18N_OUT_GOTEXT_FILES := locales/*/out.gotext.json
I18N_CATALOG_FILE := i18n_messages/catalog.go
AGBOT_IMAGE_BASE=$(IMAGE_REPO)/$(arch)_agbot
AGBOT_IMAGE_VERSION ?= $(ANAX_IMAGE_VERSION)
AGBOT_IMAGE = $(AGBOT_IMAGE_BASE):$(AGBOT_IMAGE_VERSION)
AGBOT_IMAGE_STG = $(AGBOT_IMAGE_BASE):testing$(BRANCH_NAME)
AGBOT_IMAGE_PROD = $(AGBOT_IMAGE_BASE):stable$(BRANCH_NAME)
# the latest tag is the same as stable
AGBOT_IMAGE_LATEST = $(AGBOT_IMAGE_BASE):latest$(BRANCH_NAME)
AGBOT_IMAGE_LABELS ?= --label "name=$(arch)_agbot" --label "version=$(AGBOT_IMAGE_VERSION)" --label "release=$(shell git rev-parse --short HEAD)"
# anax container running in kubernetes
ANAX_K8S_CONTAINER_DIR := anax-in-k8s
ANAX_K8S_IMAGE_BASE = $(ANAX_IMAGE_BASE)_k8s
ANAX_K8S_IMAGE_VERSION ?= $(ANAX_IMAGE_VERSION)
ANAX_K8S_IMAGE = $(ANAX_K8S_IMAGE_BASE):$(ANAX_K8S_IMAGE_VERSION)
ANAX_K8S_IMAGE_STG = $(ANAX_K8S_IMAGE_BASE):testing$(BRANCH_NAME)
ANAX_K8S_IMAGE_PROD = $(ANAX_K8S_IMAGE_BASE):stable$(BRANCH_NAME)
ANAX_K8S_IMAGE_LATEST = $(ANAX_K8S_IMAGE_BASE):latest$(BRANCH_NAME)
ANAX_K8S_IMAGE_LABELS ?= --label "name=$(arch)_anax_k8s" --label "version=$(ANAX_K8S_IMAGE_VERSION)" --label "release=$(shell git rev-parse --short HEAD)"
# agent-auto-upgrade cronjob container running in kubernetes
CRONJOB_AUTO_UPGRADE_IMAGE_BASE = $(IMAGE_REPO)/$(arch)_auto-upgrade-cronjob
CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE = $(CRONJOB_AUTO_UPGRADE_IMAGE_BASE)_k8s
CRONJOB_AUTO_UPGRADE_K8S_IMAGE_VERSION ?= $(ANAX_IMAGE_VERSION)
CRONJOB_AUTO_UPGRADE_K8S_IMAGE = $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE):$(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_VERSION)
CRONJOB_AUTO_UPGRADE_K8S_IMAGE_STG = $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE):testing$(BRANCH_NAME)
CRONJOB_AUTO_UPGRADE_K8S_IMAGE_PROD = $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE):stable$(BRANCH_NAME)
CRONJOB_AUTO_UPGRADE_K8S_IMAGE_LATEST = $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE):latest$(BRANCH_NAME)
CRONJOB_AUTO_UPGRADE_K8S_IMAGE_LABELS ?= --label "name=$(arch)_auto-upgrade-cronjob_k8s" --label "version=$(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_VERSION)" --label "release=$(shell git rev-parse --short HEAD)"
# Variables that control packaging the file sync service containers
DOCKER_REGISTRY ?= "dockerhub"
ANAX_K8S_REGISTRY ?= $(DOCKER_REGISTRY)
FSS_REGISTRY ?= $(DOCKER_REGISTRY)
ANAX_REGISTRY ?= $(DOCKER_REGISTRY)
AGBOT_REGISTRY ?= $(DOCKER_REGISTRY)
# The CSS and its production container. This container is NOT used by hzn dev.
CSS_EXECUTABLE := css/cloud-sync-service
CSS_CONTAINER_DIR := css
CSS_IMAGE_VERSION ?= 1.11.4$(BRANCH_NAME)
CSS_IMAGE_BASE = image/cloud-sync-service
CSS_IMAGE_NAME = $(IMAGE_REPO)/$(arch)_cloud-sync-service
CSS_IMAGE = $(CSS_IMAGE_NAME):$(CSS_IMAGE_VERSION)
CSS_IMAGE_STG = $(CSS_IMAGE_NAME):testing$(BRANCH_NAME)
CSS_IMAGE_PROD = $(CSS_IMAGE_NAME):stable$(BRANCH_NAME)
# the latest tag is the same as stable
CSS_IMAGE_LATEST = $(CSS_IMAGE_NAME):latest$(BRANCH_NAME)
CSS_IMAGE_LABELS ?= --label "name=$(arch)_cloud-sync-service" --label "version=$(CSS_IMAGE_VERSION)" --label "release=$(shell git rev-parse --short HEAD)"
# The hzn dev ESS/CSS and its container.
ESS_EXECUTABLE := ess/edge-sync-service
ESS_CONTAINER_DIR := ess
ESS_IMAGE_VERSION ?= 1.11.4$(BRANCH_NAME)
ESS_IMAGE_BASE = image/edge-sync-service
ESS_IMAGE_NAME = $(IMAGE_REPO)/$(arch)_edge-sync-service
ESS_IMAGE = $(ESS_IMAGE_NAME):$(ESS_IMAGE_VERSION)
ESS_IMAGE_STG = $(ESS_IMAGE_NAME):testing$(BRANCH_NAME)
ESS_IMAGE_PROD = $(ESS_IMAGE_NAME):stable$(BRANCH_NAME)
# the latest tag is the same as stable
ESS_IMAGE_LATEST = $(ESS_IMAGE_NAME):latest$(BRANCH_NAME)
ESS_IMAGE_LABELS ?= --label "name=$(arch)_edge-sync-service" --label "version=$(ESS_IMAGE_VERSION)" --label "release=$(shell git rev-parse --short HEAD)"
# license file name
export LICENSE_FILE = LICENSE.txt
# supported locales
export SUPPORTED_LOCALES ?= de es fr it ja ko pt_BR zh_CN zh_TW
export TMPGOPATH ?= $(TMPDIR)$(EXECUTABLE)-gopath
export PKGPATH := $(TMPGOPATH)/src/github.com/open-horizon/$(EXECUTABLE)
export PATH := $(TMPGOPATH)/bin:$(PATH)
export EXCHANGE_URL ?=
export FSS_CSS_URL ?=
export AGBOT_URL ?=
# we use a script that will give us the debian arch version since that's what the packaging system inputs
arch ?= $(shell tools/arch-tag)
COMPILE_ARGS ?= CGO_ENABLED=0
# TODO: handle other ARM architectures on build boxes too
ifeq ($(arch),armhf)
COMPILE_ARGS += GOARCH=arm GOARM=6
else ifeq ($(arch),arm64)
COMPILE_ARGS += GOARCH=arm64
else ifeq ($(arch),amd64)
COMPILE_ARGS += GOARCH=amd64
else ifeq ($(arch),ppc64el)
COMPILE_ARGS += GOARCH=ppc64le
else ifeq ($(arch),s390x)
COMPILE_ARGS += GOARCH=s390x
else ifeq ($(arch),riscv64)
COMPILE_ARGS += GOARCH=riscv64
endif
opsys ?= $(shell uname -s)
ifeq ($(opsys),Linux)
COMPILE_ARGS += GOOS=linux
else ifeq ($(opsys),Darwin)
COMPILE_ARGS += GOOS=darwin
endif
COMPILE_ARGS_LOCAL ?= CGO_ENABLED=0
arch_local ?= $(shell tools/arch-tag)
# TODO: handle other ARM architectures on build boxes too
ifeq ($(arch_local),armhf)
COMPILE_ARGS_LOCAL += GOARCH=arm GOARM=6
else ifeq ($(arch_local),arm64)
COMPILE_ARGS_LOCAL += GOARCH=arm64
else ifeq ($(arch_local),amd64)
COMPILE_ARGS_LOCAL += GOARCH=amd64
else ifeq ($(arch_local),ppc64el)
COMPILE_ARGS_LOCAL += GOARCH=ppc64le
else ifeq ($(arch_local),s390x)
COMPILE_ARGS_LOCAL += GOARCH=s390x
else ifeq ($(arch_local),riscv64)
COMPILE_ARGS_LOCAL += GOARCH=riscv64
endif
opsys_local ?= $(shell uname -s)
ifeq ($(opsys_local),Linux)
COMPILE_ARGS_LOCAL += GOOS=linux
else ifeq ($(opsys_local),Darwin)
COMPILE_ARGS_LOCAL += GOOS=darwin
endif
NO_DEBUG_PKGS := $(shell tools/no-debug-pkg)
ifeq (${NO_DEBUG_PKGS},true)
GO_BUILD_LDFLAGS := $(GO_BUILD_LDFLAGS) -linkmode=external
endif
ifdef GO_BUILD_LDFLAGS
GO_BUILD_LDFLAGS := -ldflags="$(GO_BUILD_LDFLAGS) -s -w"
endif
# Test if we can use Docker buildx if USE_DOCKER_BUILDX is set. If not, then we can't build multi-arch images on x86 but
# will instead need to have a build platform of each arch to build images of different archs
DOCKER_BUILDX_PLATFORM=$(arch)
ifeq ($(arch),ppc64el)
DOCKER_BUILDX_PLATFORM = ppc64le
endif
DOCKER_BUILD_CMD = build
ifneq ($(origin USE_DOCKER_BUILDX), undefined)
DOCKER_BUILD_CMD = buildx build --platform linux/$(DOCKER_BUILDX_PLATFORM)
endif
ifndef verbose
.SILENT:
endif
all: check-upx gopathlinks deps $(EXECUTABLE) $(CLI_EXECUTABLE) $(CSS_EXECUTABLE) $(ESS_EXECUTABLE)
deps: gofolders
$(EXECUTABLE): $(shell find . -name '*.go') gopathlinks
@echo "Producing $(EXECUTABLE) given arch: $(arch)"
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); \
$(COMPILE_ARGS) go build $(GO_BUILD_LDFLAGS) -o $(EXECUTABLE);
exch_min_ver=$(shell grep "MINIMUM_EXCHANGE_VERSION =" $(PKGPATH)/version/version.go | awk -F '"' '{print $$2}') && \
echo "The required minimum exchange version is $$exch_min_ver";
exch_pref_ver=$(shell grep "PREFERRED_EXCHANGE_VERSION =" $(PKGPATH)/version/version.go | awk -F '"' '{print $$2}') && \
echo "The preferred exchange version is $$exch_pref_ver"; \
if [[ $(USE_UPX) == "true" ]]; then \
echo "Packing executable $(EXECUTABLE) with UPX"; \
upx $(EXECUTABLE); \
fi;
$(CLI_EXECUTABLE): $(shell find . -name '*.go') gopathlinks
@echo "Producing $(CLI_EXECUTABLE) given arch: $(arch)"
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); \
$(COMPILE_ARGS) go build $(GO_BUILD_LDFLAGS) -o $(CLI_EXECUTABLE) $(CLI_EXECUTABLE).go && \
envsubst < cli/cliconfig/hzn.json.tmpl > $(CLI_CONFIG_FILE)
if [[ $(arch) == $(shell tools/arch-tag) && $(opsys) == $(shell uname -s) ]]; then \
mkdir -p $(CLI_MAN_DIR) && $(CLI_EXECUTABLE) --help-man > $(CLI_MAN_DIR)/hzn.1 && \
for loc in $(SUPPORTED_LOCALES) ; do \
HZN_LANG=$$loc $(CLI_EXECUTABLE) --help-man > $(CLI_MAN_DIR)/hzn.1.$$loc; \
done && \
mkdir -p $(CLI_COMPLETION_DIR) && $(CLI_EXECUTABLE) --completion-script-bash > $(CLI_COMPLETION_DIR)/hzn_bash_autocomplete.sh; \
else \
echo "Producing $(CLI_TEMP_EXECUTABLE) under $(arch_local) for generating hzn man pages"; \
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); \
$(COMPILE_ARGS_LOCAL) go build $(GO_BUILD_LDFLAGS) -o $(CLI_TEMP_EXECUTABLE) $(CLI_EXECUTABLE).go; \
mkdir -p $(CLI_MAN_DIR) && $(CLI_TEMP_EXECUTABLE) --help-man > $(CLI_MAN_DIR)/hzn.1 && \
for loc in $(SUPPORTED_LOCALES) ; do \
HZN_LANG=$$loc $(CLI_TEMP_EXECUTABLE) --help-man > $(CLI_MAN_DIR)/hzn.1.$$loc; \
done && \
rm $(CLI_TEMP_EXECUTABLE); \
fi;
$(CSS_EXECUTABLE): $(shell find . -name '*.go') gopathlinks
@echo "Producing $(CSS_EXECUTABLE) given arch: $(arch)"
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); \
$(COMPILE_ARGS) go build $(GO_BUILD_LDFLAGS) -o $(CSS_EXECUTABLE) css/cmd/cloud-sync-service/main.go; \
if [[ $(USE_UPX) == "true" ]]; then \
echo "Packing executable $(CSS_EXECUTABLE) with UPX"; \
upx $(CSS_EXECUTABLE); \
fi;
$(ESS_EXECUTABLE): $(shell find . -name '*.go') gopathlinks
@echo "Producing $(ESS_EXECUTABLE) given arch: $(arch)"
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); \
$(COMPILE_ARGS) go build $(GO_BUILD_LDFLAGS) -o $(ESS_EXECUTABLE) ess/cmd/edge-sync-service/main.go; \
if [[ $(USE_UPX) == "true" ]]; then \
echo "Packing executable $(ESS_EXECUTABLE) with UPX"; \
upx $(ESS_EXECUTABLE); \
fi;
# Build the deb pkgs and put them in pkg/deb/debs/
debpkgs:
$(MAKE) -C pkg/deb all
# Build the rpm pkgs and put them in ~/rpmbuild/RPMS/x86_64/
rpmpkgs:
$(MAKE) -C pkg/rpm all
# Build the horizon-cli pkg for mac
MAC_PKG_VERSION = $(VERSION)$(BUILD_NUMBER)
MAC_PKG = pkg/mac/build/horizon-cli-$(MAC_PKG_VERSION).pkg
check-upx:
@if [[ $(USE_UPX) == "true" ]]; then \
if ! type upx >/dev/null 2>&1 ; then \
if [[ $(opsys_local) == "Linux" ]]; then \
echo "upx is not installed, consider doing apt-get install upx" && exit 1; \
else \
echo "upx is not installed, consider doing brew install upx" && exit 1; \
fi; \
fi; \
fi;
# This is a 1-time step to create the private signing key and public cert for the mac pkg.
# You must first set HORIZON_CLI_PRIV_KEY_PW to the passphrase to use the private key.
gen-mac-key:
$(MAKE) -C pkg/mac gen-mac-key
# This is a 1-time step to install the mac pkg signing key on your mac so it can be used to sign the pkg.
# You must first set HORIZON_CLI_PRIV_KEY_PW to the passphrase to use the private key.
# If you did not just create the pkg/mac/build/horizon-cli.p12 file using the make target above, download it and put it there.
install-mac-key:
$(MAKE) -C pkg/mac install-mac-key
# DEPRECATED: this Makefile now sets the version dynamically at build time. See GO_BUILD_LDFLAGS
# Inserts the version into version.go in prep for the macpkg build
temp-mod-version:
mv version/version.go version/version.go.bak # preserve the time stamp
cp version/version.go.bak version/version.go
sed -i.bak2 's/local build/$(MAC_PKG_VERSION)/' version/version.go
rm -f version/version.go.bak2 # this backup is necessary to make the above sed work on both linux and mac
# DEPRECATED: this Makefile now sets the version dynamically at build time. See GO_BUILD_LDFLAGS
# Undoes the above, so the source is unchanged
temp-mod-version-undo:
mv version/version.go.bak version/version.go
# Build the mac pkg and put it in pkg/mac/build/
macpkg: $(MAC_PKG)
$(MAC_PKG):
$(MAKE) -C pkg/mac macpkg
macinstall: $(MAC_PKG)
$(MAKE) -C pkg/mac macinstall
# This only works on the installed package
macpkginfo:
$(MAKE) -C pkg/mac macpkginfo
# note that we can use Docker buildx for building multiplatform archs on x86 if we export USE_DOCKER_BUILDX=true
anax-image:
@echo "Producing anax docker image $(ANAX_IMAGE)"
if [[ $(arch) == "amd64" || $(arch) == "ppc64el" || $(arch) == "s390x" || $(arch) == "arm64" ]]; then \
rm -rf $(ANAX_CONTAINER_DIR)/anax; \
rm -rf $(ANAX_CONTAINER_DIR)/hzn; \
cp $(EXECUTABLE) $(ANAX_CONTAINER_DIR); \
cp $(CLI_EXECUTABLE) $(ANAX_CONTAINER_DIR); \
cp -f $(LICENSE_FILE) $(ANAX_CONTAINER_DIR); \
cd $(ANAX_CONTAINER_DIR) && docker $(DOCKER_BUILD_CMD) $(DOCKER_MAYBE_CACHE) $(ANAX_IMAGE_LABELS) -t $(ANAX_IMAGE) -f Dockerfile.ubi.$(arch) . && \
docker tag $(ANAX_IMAGE) $(ANAX_IMAGE_STG); \
else echo "Building the anax docker image is not supported on $(arch)"; fi
agbot-image:
@echo "Producing agbot docker image $(AGBOT_IMAGE)"
if [[ $(arch) == "amd64" ]]; then \
rm -rf $(ANAX_CONTAINER_DIR)/anax; \
rm -rf $(ANAX_CONTAINER_DIR)/hzn; \
cp $(EXECUTABLE) $(ANAX_CONTAINER_DIR); \
cp $(CLI_EXECUTABLE) $(ANAX_CONTAINER_DIR); \
cp -f $(LICENSE_FILE) $(ANAX_CONTAINER_DIR); \
cd $(ANAX_CONTAINER_DIR) && docker build $(DOCKER_MAYBE_CACHE) $(AGBOT_IMAGE_LABELS) -t $(AGBOT_IMAGE) -f Dockerfile_agbot.ubi . && \
docker tag $(AGBOT_IMAGE) $(AGBOT_IMAGE_STG); \
else echo "Building the agbot docker image is not supported on $(arch)"; fi
# Pushes the docker image with the staging tag
docker-push-only:
@echo "Pushing anax docker image $(ANAX_IMAGE)"
docker push $(ANAX_IMAGE)
docker push $(ANAX_IMAGE_STG)
agbot-push-only:
@echo "Pushing agbot docker image $(AGBOT_IMAGE)"
docker push $(AGBOT_IMAGE)
docker push $(AGBOT_IMAGE_STG)
docker-push: anax-image docker-push-only agbot-image agbot-push-only
# you must set ANAX_IMAGE_VERSION to the correct version for promotion to production
promote-anax:
@echo "Promoting $(ANAX_IMAGE)"
docker pull $(ANAX_IMAGE)
docker tag $(ANAX_IMAGE) $(ANAX_IMAGE_PROD)
docker push $(ANAX_IMAGE_PROD)
docker tag $(ANAX_IMAGE) $(ANAX_IMAGE_LATEST)
docker push $(ANAX_IMAGE_LATEST)
# you must set ANAX_IMAGE_VERSION to the correct version for promotion to production
promote-agbot:
@echo "Promoting $(AGBOT_IMAGE)"
docker pull $(AGBOT_IMAGE)
docker tag $(AGBOT_IMAGE) $(AGBOT_IMAGE_PROD)
docker push $(AGBOT_IMAGE_PROD)
docker tag $(AGBOT_IMAGE) $(AGBOT_IMAGE_LATEST)
docker push $(AGBOT_IMAGE_LATEST)
promote-anax-k8s:
@echo "Promoting $(ANAX_K8S_IMAGE)"
docker pull $(ANAX_K8S_IMAGE)
docker tag $(ANAX_K8S_IMAGE) $(ANAX_K8S_IMAGE_PROD)
docker push $(ANAX_K8S_IMAGE_PROD)
docker tag $(ANAX_K8S_IMAGE) $(ANAX_K8S_IMAGE_LATEST)
docker push $(ANAX_K8S_IMAGE_LATEST)
promote-auto-upgrade-cronjob-k8s:
@echo "Promoting $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE)"
docker pull $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE)
docker tag $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE) $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_PROD)
docker push $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_PROD)
docker tag $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE) $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_LATEST)
docker push $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_LATEST)
anax-package: anax-image
@echo "Packaging anax image"
if [[ $(shell tools/image-exists $(ANAX_REGISTRY) $(ANAX_IMAGE_BASE) $(ANAX_IMAGE_VERSION) 2> /dev/null) == "0" || $(IMAGE_OVERRIDE) != "" ]]; then \
echo "Pushing anax docker image $(ANAX_IMAGE_BASE):$(ANAX_IMAGE_VERSION)"; \
docker push $(ANAX_IMAGE_BASE):$(ANAX_IMAGE_VERSION); \
docker push $(ANAX_IMAGE_STG); \
else \
echo "anax-k8s container $(ANAX_IMAGE_STG):$(ANAX_IMAGE_VERSION) already present in $(IMAGE_REPO)"; \
fi
agbot-package: agbot-image
@echo "Packaging agbot image"
if [[ $(shell tools/image-exists $(AGBOT_REGISTRY) $(AGBOT_IMAGE_BASE) $(AGBOT_IMAGE_VERSION) 2> /dev/null) == "0" || $(IMAGE_OVERRIDE) != "" ]]; then \
echo "Pushing agbot docker image $(AGBOT_IMAGE_BASE):$(AGBOT_IMAGE_VERSION)"; \
docker push $(AGBOT_IMAGE_BASE):$(AGBOT_IMAGE_VERSION); \
docker push $(AGBOT_IMAGE_STG); \
else \
echo "anax-k8s container $(AGBOT_IMAGE_STG):$(AGBOT_IMAGE_VERSION) already present in $(IMAGE_REPO)"; \
fi
# note that we can use Docker buildx for building multiplatform archs on x86 if we export USE_DOCKER_BUILDX=true
anax-k8s-image: anax-k8s-clean
cp $(EXECUTABLE) $(ANAX_K8S_CONTAINER_DIR)
cp $(CLI_EXECUTABLE) $(ANAX_K8S_CONTAINER_DIR)
cp -f $(LICENSE_FILE) $(ANAX_K8S_CONTAINER_DIR)
@echo "Producing ANAX K8S docker image $(ANAX_K8S_IMAGE_STG)"
if [[ $(arch) == "amd64" || $(arch) == "ppc64el" || $(arch) == "arm64" || $(arch) == "s390x" ]]; then \
cd $(ANAX_K8S_CONTAINER_DIR) && docker $(DOCKER_BUILD_CMD) $(DOCKER_MAYBE_CACHE) $(ANAX_K8S_IMAGE_LABELS) -t $(ANAX_K8S_IMAGE_STG) -f Dockerfile.ubi.$(arch) .; \
fi
docker tag $(ANAX_K8S_IMAGE_STG) $(ANAX_K8S_IMAGE_BASE):$(ANAX_K8S_IMAGE_VERSION)
auto-upgrade-cronjob-k8s-image: auto-upgrade-cronjob-k8s-clean
@echo "Producing Agent Auto Upgrade CronJob K8S docker image $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_STG)"
if [[ $(arch) == "amd64" || $(arch) == "ppc64el" || $(arch) == "arm64" || $(arch) == "s390x" ]]; then \
cd $(ANAX_K8S_CONTAINER_DIR) && docker build $(DOCKER_MAYBE_CACHE) $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_LABELS) -t $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_STG) -f Dockerfile.ubi.auto-upgrade-cron.$(arch) .; \
fi
docker tag $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_STG) $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE):$(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_VERSION)
anax-k8s-package: anax-k8s-image
@echo "Packaging anax-k8s container"
if [[ $(shell tools/image-exists $(ANAX_K8S_REGISTRY) $(ANAX_K8S_IMAGE_BASE) $(ANAX_K8S_IMAGE_VERSION) 2> /dev/null) == "0" || $(IMAGE_OVERRIDE) != "" ]]; then \
echo "Pushing anax-k8s docker image $(ANAX_K8S_IMAGE_BASE):$(ANAX_K8S_IMAGE_VERSION)"; \
docker push $(ANAX_K8S_IMAGE_BASE):$(ANAX_K8S_IMAGE_VERSION); \
docker push $(ANAX_K8S_IMAGE_STG); \
else \
echo "anax-k8s container $(ANAX_K8S_IMAGE_STG):$(ANAX_K8S_IMAGE_VERSION) already present in $(IMAGE_REPO)"; \
fi
auto-upgrade-cronjob-k8s-package: auto-upgrade-cronjob-k8s-image
@echo "Packaging anax-k8s container"
if [[ $(shell tools/image-exists $(ANAX_K8S_REGISTRY) $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE) $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_VERSION) 2> /dev/null) == "0" || $(IMAGE_OVERRIDE) != "" ]]; then \
echo "Pushing anax-k8s docker image $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE):$(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_VERSION)"; \
docker push $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_BASE):$(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_VERSION); \
docker push $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_STG); \
else \
echo "anax-k8s container $(ANAX_K8S_IMAGE_STG):$(ANAX_K8S_IMAGE_VERSION) already present in $(IMAGE_REPO)"; \
fi
css-docker-image: css-clean
@echo "Producing CSS docker image $(CSS_IMAGE)"
if [[ $(arch) == "amd64" ]]; then \
cp -f $(LICENSE_FILE) $(CSS_CONTAINER_DIR); \
cd $(CSS_CONTAINER_DIR) && docker build $(DOCKER_MAYBE_CACHE) $(CSS_IMAGE_LABELS) -t $(CSS_IMAGE) -f ./$(CSS_IMAGE_BASE)-$(arch)/Dockerfile.ubi . && \
docker tag $(CSS_IMAGE) $(CSS_IMAGE_STG); \
else echo "Building the CSS docker image is not supported on $(arch)"; fi
promote-css:
@echo "Promoting $(CSS_IMAGE)"
docker pull $(CSS_IMAGE)
docker tag $(CSS_IMAGE) $(CSS_IMAGE_PROD)
docker push $(CSS_IMAGE_PROD)
docker tag $(CSS_IMAGE) $(CSS_IMAGE_LATEST)
docker push $(CSS_IMAGE_LATEST)
ess-docker-image: ess-clean
@echo "Producing ESS docker image $(ESS_IMAGE)"
cp -f $(LICENSE_FILE) $(ESS_CONTAINER_DIR)
cd $(ESS_CONTAINER_DIR) && docker build $(DOCKER_MAYBE_CACHE) $(ESS_IMAGE_LABELS) -t $(ESS_IMAGE) -f ./$(ESS_IMAGE_BASE)-$(arch)/Dockerfile.ubi . && \
docker tag $(ESS_IMAGE) $(ESS_IMAGE_STG); \
ess-promote:
@echo "Promoting $(ESS_IMAGE)"
docker pull $(ESS_IMAGE)
docker tag $(ESS_IMAGE) $(ESS_IMAGE_PROD)
docker push $(ESS_IMAGE_PROD)
docker tag $(ESS_IMAGE) $(ESS_IMAGE_LATEST)
docker push $(ESS_IMAGE_LATEST)
# This target should be used by developers working on anax, to build the ESS and CSS containers for the anax test environment.
# These containers only need to be rebuilt when either the authentication plugin changes or when anax rebases on a new level/tag
# of the edge-sync-service.
fss: ess-docker-image css-docker-image
@echo "Built file sync service containers"
# This is a target that is ONLY called by the deb packager system. The ESS and CSS containers are built and published by that process
# when new versions are created. Developers should not use this target.
# Note that only ESS is supported by amd64, arm64 and ppc64el archs. CSS is amd64 only.
fss-package: ess-docker-image css-docker-image
@echo "Packaging file sync service containers"
if [[ $(shell tools/image-exists $(FSS_REGISTRY) $(ESS_IMAGE_NAME) $(ESS_IMAGE_VERSION) 2> /dev/null) == "0" || $(IMAGE_OVERRIDE) != "" ]]; then \
echo "Pushing ESS Docker image $(ESS_IMAGE)"; \
docker push $(ESS_IMAGE); \
docker push $(ESS_IMAGE_STG); \
else \
echo "File sync service container $(ESS_IMAGE_NAME):$(ESS_IMAGE_VERSION) already present in $(FSS_REGISTRY)"; \
fi
if [[ $(arch) == "amd64" ]]; then \
if [[ ($(shell tools/image-exists $(FSS_REGISTRY) $(CSS_IMAGE_NAME) $(CSS_IMAGE_VERSION) 2> /dev/null) == "0" || $(IMAGE_OVERRIDE) != "") ]]; then \
echo "Pushing CSS Docker image $(CSS_IMAGE)"; \
docker push $(CSS_IMAGE); \
docker push $(CSS_IMAGE_STG); \
else echo "File sync service container $(CSS_IMAGE_NAME):$(CSS_IMAGE_VERSION) already present in $(FSS_REGISTRY)"; fi \
fi
clean: mostlyclean
@echo "Clean"
ifneq ($(TMPGOPATH),$(GOPATH))
rm -rf $(TMPGOPATH)
endif
rm -rf ./contracts
realclean: i18n-clean clean
mostlyclean: anax-container-clean agbot-container-clean anax-k8s-clean auto-upgrade-cronjob-k8s-clean css-clean ess-clean
@echo "Mostlyclean"
rm -f $(EXECUTABLE) $(CLI_EXECUTABLE) $(CSS_EXECUTABLE) $(ESS_EXECUTABLE) $(CLI_CONFIG_FILE)
rm -Rf vendor
i18n-clean:
@echo "i18n-clean"
rm -f $(I18N_OUT_GOTEXT_FILES) cli/$(I18N_OUT_GOTEXT_FILES) $(I18N_CATALOG_FILE) cli/$(I18N_CATALOG_FILE)
css-clean:
rm -f $(CSS_CONTAINER_DIR)/$(LICENSE_FILE)
-docker rmi $(CSS_IMAGE) 2> /dev/null || :
-docker rmi $(CSS_IMAGE_STG) 2> /dev/null || :
ess-clean:
rm -f $(ESS_CONTAINER_DIR)/$(LICENSE_FILE)
-docker rmi $(ESS_IMAGE) 2> /dev/null || :
-docker rmi $(ESS_IMAGE_STG) 2> /dev/null || :
anax-container-clean:
rm -f $(ANAX_CONTAINER_DIR)/hzn
rm -f $(ANAX_CONTAINER_DIR)/anax
rm -f $(ANAX_CONTAINER_DIR)/$(LICENSE_FILE)
-docker rmi $(ANAX_IMAGE) 2> /dev/null || :
-docker rmi $(ANAX_IMAGE_STG) 2> /dev/null || :
agbot-container-clean:
rm -f $(ANAX_CONTAINER_DIR)/hzn
rm -f $(ANAX_CONTAINER_DIR)/anax
rm -f $(ANAX_CONTAINER_DIR)/$(LICENSE_FILE)
-docker rmi $(AGBOT_IMAGE) 2> /dev/null || :
-docker rmi $(AGBOT_IMAGE_STG) 2> /dev/null || :
anax-k8s-clean:
rm -f $(ANAX_K8S_CONTAINER_DIR)/hzn
rm -f $(ANAX_K8S_CONTAINER_DIR)/anax
rm -f $(ANAX_K8S_CONTAINER_DIR)/$(LICENSE_FILE)
-docker rmi $(ANAX_K8S_IMAGE) 2> /dev/null || :
-docker rmi $(ANAX_K8S_IMAGE_STG) 2> /dev/null || :
auto-upgrade-cronjob-k8s-clean:
-docker rmi $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE) 2> /dev/null || :
-docker rmi $(CRONJOB_AUTO_UPGRADE_K8S_IMAGE_STG) 2> /dev/null || :
gofolders:
ifneq ($(GOPATH),$(TMPGOPATH))
if [ ! -z $(GOPATH) ] && [ -w $(GOPATH) ] && [ -d $(GOPATH) ]; then \
mkdir -p $(GOPATH)/pkg $(GOPATH)/bin; \
fi
endif
i18n-catalog: gopathlinks deps $(TMPGOPATH)/bin/gotext
@echo "Creating message catalogs"
rm -Rf vendor; \
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); export PATH=$(TMPGOPATH)/bin:$$PATH; \
CGO_ENABLED=0 tools/update-i18n-messages
rm -Rf vendor; \
i18n-translation: i18n-catalog
@echo "Copying message files for translation"
cd $(PKGPATH) && \
export PKGPATH=$(PKGPATH); export PATH=$(TMPGOPATH)/bin:$$PATH; \
tools/copy-i18n-messages
i18n-unpack:
@echo "Unpacking the translated messages..."
cd $(PKGPATH) && \
export PKGPATH=$(PKGPATH); export PATH=$(TMPGOPATH)/bin:$$PATH; \
tools/unpack-i18n-messages
$(TMPGOPATH)/bin/gotext:
if [ ! -e "$(TMPGOPATH)/bin/gotext" ]; then \
echo "Fetching gotext"; \
export GOPATH=$(TMPGOPATH); export PATH=$(TMPGOPATH)/bin:$$PATH; \
go install golang.org/x/text/cmd/gotext@master; \
fi
gopathlinks:
# unfortunately the .cache directory has to be copied b/c of https://github.com/kardianos/govendor/issues/274
ifneq ($(GOPATH),$(TMPGOPATH))
if [ -d "$(PKGPATH)" ] && [ "$(readlink -- "$(PKGPATH)")" != "$(CURDIR)" ]; then \
rm $(PKGPATH); \
fi
if [ ! -L "$(PKGPATH)" ]; then \
mkdir -p $(shell dirname "$(PKGPATH)"); \
ln -s "$(CURDIR)" "$(PKGPATH)"; \
fi
for d in bin pkg; do \
if [ ! -L "$(TMPGOPATH)/$$d" ]; then \
ln -s $(GOPATH)/$$d $(TMPGOPATH)/$$d; \
fi; \
done
if [ ! -L "$(TMPGOPATH)/.cache" ] && [ -d "$(GOPATH)/.cache" ]; then \
cp -Rfpa $(GOPATH)/.cache $(TMPGOPATH)/.cache; \
fi
endif
PKGS=$(shell cd $(PKGPATH); GOPATH=$(TMPGOPATH) go list ./... | gawk '$$1 !~ /vendor\// {print $$1}')
CDIR=$(DESTDIR)/go/src/github.com/open-horizon/go-solidity/contracts
install:
@echo "Installing $(EXECUTABLE), $(CLI_EXECUTABLE) and $(CLI_HORIZON_CONTAINER) in $(DESTDIR)/bin"
mkdir -p $(DESTDIR)/bin && \
cp $(EXECUTABLE) $(DESTDIR)/bin && \
cp $(CLI_EXECUTABLE) $(DESTDIR)/bin && \
cp $(CLI_HORIZON_CONTAINER) $(DESTDIR)/bin
# mkdir -p $(DESTDIR)/web && \
# cp $(DEFAULT_UI) $(DESTDIR)/web
cp -Rapv cli/samples $(DESTDIR)/
mkdir -p $(CDIR) && \
find $(CDIR)/ \( -name "Makefile" -or -iname ".git*" \) -exec rm {} \;
format:
@echo "Formatting all Golang source code with gofmt"
find . -name '*.go' -exec gofmt -l -w {} \;
lint: gopathlinks
@echo "Checking source code for style issues and statically-determinable errors"
-golint ./...
-cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) $(COMPILE_ARGS) go vet $(shell find . -iname '*.go' -print | xargs dirname | sort | uniq | xargs) 2>&1 | grep -vP "^exit.*"
pull: deps
# only unit tests
test: gopathlinks
@echo "Executing unit tests"
-@cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) $(COMPILE_ARGS) go test -cover -tags=unit $(PKGS)
test-integration: gopathlinks
@echo "Executing integration tests"
-@cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) $(COMPILE_ARGS) go test -cover -tags=integration $(PKGS)
test-ci: gopathlinks
@echo "Executing integration tests intended for CI systems with special configuration"
-@cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) $(COMPILE_ARGS) go test -cover -tags=ci $(PKGS)
# N.B. this doesn't run ci tests, the ones that require CI system setup
check: lint test test-integration
# build sequence diagrams
diagrams:
java -jar $(plantuml_path)/plantuml.jar ./exchange/diagrams/senderEncryption.txt
java -jar $(plantuml_path)/plantuml.jar ./exchange/diagrams/receiverEncryption.txt
java -jar $(plantuml_path)/plantuml.jar ./basicprotocol/diagrams/protocolSequenceDiagram.txt
java -jar $(plantuml_path)/plantuml.jar ./basicprotocol/diagrams/horizonSequenceDiagram.txt
.PHONY: check clean deps format gopathlinks install lint mostlyclean realclean pull i18n-catalog i18n-translation test test-integration docker-image docker-push promote-anax gen-mac-key install-mac-key css-docker-image ess-promote