-
Notifications
You must be signed in to change notification settings - Fork 819
/
Makefile
83 lines (70 loc) · 3.79 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
# New Makefile for multi-architecture
# WARNING:
# This makefile used docker buildx to build multi-arch image
# Please make sure you have the right version of docker.
.PHONY: microservice.push swag zadig-agent zadig-agent-clean
IMAGE_REPOSITORY ?= koderover.tencentcloudcr.com/koderover-public
IMAGE_REPOSITORY := $(IMAGE_REPOSITORY)
DEV_IMAGE_REPOSITORY ?= koderover.tencentcloudcr.com/test
DEV_IMAGE_REPOSITORY := $(DEV_IMAGE_REPOSITORY)
VERSION ?= $(shell date +'%Y%m%d%H%M%S')
VERSION := $(VERSION)
MICROSERVICE_TARGETS = aslan cron executor hub-agent hub-server init jenkins-plugin packager-plugin predator-plugin ua user warpdrive
BUILD_BASE_TARGETS = focal bionic
DEBUG_TOOLS_TARGETS = zadig-debug zgctl-sidecar
prereq:
@docker buildx create --node=multiarch --use --platform=linux/amd64,linux/arm64
microservice: prereq $(MICROSERVICE_TARGETS:=.image)
microservice.push: prereq $(MICROSERVICE_TARGETS:=.push)
buildbase: prereq $(BUILD_BASE_TARGETS:=.buildbase)
debugtools: prereq $(DEBUG_TOOLS_TARGETS:=.push)
%.image: MAKE_IMAGE_TAG ?= ${IMAGE_REPOSITORY}/$*:${VERSION}
%.image:
@docker buildx build -t ${MAKE_IMAGE_TAG} --platform linux/amd64,linux/arm64 -f docker/$*.Dockerfile .
%.push: MAKE_IMAGE_TAG ?= ${IMAGE_REPOSITORY}/$*:${VERSION}
%.push:
@docker buildx build -t ${MAKE_IMAGE_TAG} --platform linux/amd64,linux/arm64 -f docker/$*.Dockerfile --push .
# for zadig developers ONLY:
# the command below is used to generate amd64 file for daily developing purpose
%.dev: MAKE_IMAGE_TAG ?= ${DEV_IMAGE_REPOSITORY}/$*:${VERSION}
%.dev:
@docker buildx build -t ${MAKE_IMAGE_TAG} --platform linux/amd64 -f docker/$*.Dockerfile --push .
%.buildbase: MAKE_IMAGE_TAG ?= ${IMAGE_REPOSITORY}/build-base:$*
%.buildbase:
@docker buildx build -t ${MAKE_IMAGE_TAG} --platform linux/amd64,linux/arm64 -f docker/$*-base.Dockerfile --push .
swag:
swag init --parseDependency --parseInternal --parseDepth 1 -d cmd/aslan,pkg/microservice/aslan -g ../../pkg/microservice/aslan/server/rest/router.go -o pkg/microservice/aslan/server/rest/doc
# zadig-agent
# Usage:
# make zadig-agent ZADIG_AGENT_VERSION=2.1.0
# make zadig-agent-linux-amd64 ZADIG_AGENT_VERSION=2.10
# make tar-zadig-agent ZADIG_AGENT_VERSION=2.1.0
# make tar-zadig-agent-linux-amd64 ZADIG_AGENT_VERSION=2.1.0
ARCHS := amd64 arm64
PLATFORMS := windows linux darwin
BUILD_TIME := $(shell TZ=Asia/Shanghai date '+%Y-%m-%d %H:%M:%S %Z')
BUILD_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_GO_VERSION := $(shell go version | awk '{print $$3}')
ZADIG_AGENT_VERSION ?= $(shell date +'%Y%m%d%H%M%S')
ZADIG_AGENT_VERSION := $(ZADIG_AGENT_VERSION)
ZADIG_AGENT_OUT_DIR := cmd/zadig-agent/out
zadig-agent: $(foreach platform,$(PLATFORMS),$(foreach arch,$(ARCHS),zadig-agent-$(platform)-$(arch)))
zadig-agent-%:
@$(eval GOOS=$(firstword $(subst -, ,$*)))
@$(eval GOARCH=$(lastword $(subst -, ,$*)))
@$(eval ZADIG_AGENT_OUT_FILE=$(ZADIG_AGENT_OUT_DIR)/zadig-agent-$(GOOS)-$(GOARCH)-v$(ZADIG_AGENT_VERSION)$(if $(findstring windows,$(GOOS)),.exe))
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags '-X "main.BuildAgentVersion=$(ZADIG_AGENT_VERSION)" -X "main.BuildGoVersion=$(BUILD_GO_VERSION)" -X "main.BuildTime=$(BUILD_TIME)" -X "main.BuildCommit=$(BUILD_COMMIT)"' -o $(ZADIG_AGENT_OUT_FILE) cmd/zadig-agent/main.go
tar-zadig-agent: $(foreach platform,$(PLATFORMS),$(foreach arch,$(ARCHS),tar-zadig-agent-$(platform)-$(arch)))
tar-zadig-agent-%: zadig-agent-%
@$(eval GOOS=$(firstword $(subst -, ,$*)))
@$(eval GOARCH=$(lastword $(subst -, ,$*)))
tar -czvf $(ZADIG_AGENT_OUT_DIR)/zadig-agent-$*-v$(ZADIG_AGENT_VERSION).tar.gz -C $(ZADIG_AGENT_OUT_DIR) zadig-agent-$*-v$(ZADIG_AGENT_VERSION)$(if $(findstring windows,$(GOOS)),.exe)
zadig-agent-clean:
@rm -rf $(ZADIG_AGENT_OUT_DIR)/*
# debug scripts
%.build:
./debug/build.sh $*
%.run:
./debug/run.sh $*
%.debug:
./debug/debug.sh $*