forked from brianchenl/CloudIaC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
244 lines (173 loc) · 8.33 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
#GOCMD=CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go
GOCMD=CGO_ENABLED=0 go
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
HOSTOS=$(shell go env GOHOSTOS)
HOSTARCH=$(shell go env GOHOSTARCH)
MYSQL_ROOT_PASSWORD?=cloudiac
MYSQL_PORT=3307
RM=/bin/rm -f
#VERSION=$(shell git describe --tags --abbrev=0 --always)
VERSION=$(shell cat VERSION)
DATE_VER=$(shell date "+%Y%m%d")
COMMIT=$(shell git rev-parse --short HEAD)
GOLDFLAGS="-X cloudiac/common.VERSION=$(VERSION) -X cloudiac/common.BUILD=$(COMMIT)"
GOBUILD=$(GOCMD) build -v -ldflags $(GOLDFLAGS)
GORUN=$(GOCMD) run -v -ldflags $(GOLDFLAGS)
PB_PROTOC=protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative
WORKDIR?=/usr/yunji/cloudiac
DOCKER_REPO=cloudiac
DOCKER_REGISTRY?=$(DOCKER_REPO)
# base image 不支持自定义 docker registry
BASE_IMAGE_DOCKER_REPO=cloudiac
DOCKER_BUILD=docker build --build-arg http_proxy="$(http_proxy)" --build-arg https_proxy="$(https_proxy)" --build-arg WORKDIR=$(WORKDIR)
DOCKER_RUN=docker run --rm -d
ifeq (${HOSTOS}_${HOSTARCH}, darwin_arm64)
DOCKER_RUN=DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -d
endif
DOCKER_STOP=docker stop
BUILD_DIR=$(PWD)/build
.PHONY: all build portal runner run run-portal ru-runner clean package repos providers package-release
all: build
build: portal runner tool
build-linux-amd64-portal:
GOOS=linux GOARCH=amd64 $(MAKE) portal tool
build-linux-amd64-runner:
GOOS=linux GOARCH=amd64 $(MAKE) runner
build-linux-arm64-portal:
GOOS=linux GOARCH=arm64 $(MAKE) portal tool
build-linux-arm64-runner:
GOOS=linux GOARCH=arm64 $(MAKE) runner
reset-build-dir:
$(RM) -r $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/assets/
gen-lang:
GOOS="" go run cmds/gen-lang/main.go docs/lang.csv portal/consts/e/lang.go
gen-lang-arm64:
GOOS=linux GOARCH=arm64 go run cmds/gen-lang/main.go docs/lang.csv portal/consts/e/lang.go
gen-code:
go generate ./portal/models
swag-docs: gen-lang
which swag || go install github.com/swaggo/swag/cmd/swag; swag init -g portal/web/api/v1/route.go
mkdocs:
GOOS="" GOARCH="" go run scripts/updatedocs/main.go
mkdocs-arm64:
GOOS=linux GOARCH=arm64 go run scripts/updatedocs/main.go
portal: reset-build-dir mkdocs swag-docs
$(GOBUILD) -o $(BUILD_DIR)/iac-portal ./cmds/portal
runner: reset-build-dir
$(GOBUILD) -o $(BUILD_DIR)/ct-runner ./cmds/runner
tool:
$(GOBUILD) -o $(BUILD_DIR)/iac-tool ./cmds/tool
run: run-portal
run-portal: swag-docs
$(GORUN) ./cmds/portal -v -c config-portal.yml
run-runner:
$(GORUN) ./cmds/runner -v -c config-runner.yml
run-tool:
$(GORUN) ./cmds/tool -v -c config-portal.yml
start-mysql-unittest: stop-mysql-unittest tool
$(DOCKER_RUN) --name cloudiac-mysql-unittest -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} -e MYSQL_DATABASE=iac_test -p $(MYSQL_PORT):3306 mysql:5.7 mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
while ! docker exec cloudiac-mysql-unittest mysql -h127.0.0.1 -uroot -p"${MYSQL_ROOT_PASSWORD}" -e "SELECT 1" ; do echo "waiting for mysql ready..."; sleep 1; done
$(BUILD_DIR)/iac-tool initdb "root:${MYSQL_ROOT_PASSWORD}@tcp(127.0.0.1:$(MYSQL_PORT))/iac_test?charset=utf8mb4&parseTime=True&loc=Local"
stop-mysql-unittest:
$(DOCKER_STOP) cloudiac-mysql-unittest || true
dumpdb: tool
mkdir -p ./dumpdb/
$(BUILD_DIR)/iac-tool dumpdb ./dumpdb/
test:
$(GOTEST) -v -parallel 1 ./...
coverage:
$(GOTEST) -parallel 1 ./... -coverpkg=./... -coverprofile=coverage.out || true
view-coverage:
go tool cover -func=coverage.out
clean: reset-build-dir
$(GOCLEAN) ./cmds/portal
$(GOCLEAN) ./cmds/runner
$(GOCLEAN) ./cmds/tool
PACKAGE_NAME=cloudiac_$(VERSION).tar.gz
package-local: reset-build-dir clean build
cp -a ./assets/terraform.py $(BUILD_DIR)/assets/ && \
cp -a ./assets/terraformrc-* $(BUILD_DIR)/assets/ && \
cp ./scripts/iac-portal.service ./scripts/ct-runner.service $(BUILD_DIR)/ && \
cp ./configs/config-portal.yml.sample $(BUILD_DIR)/config-portal.yml.sample && \
cp ./configs/dotenv.sample $(BUILD_DIR)/dotenv.sample && \
cp ./configs/config-runner.yml.sample $(BUILD_DIR)/config-runner.yml.sample && \
cp ./configs/demo-conf.yml.sample $(BUILD_DIR)/demo-conf.yml.sample && \
cd $(BUILD_DIR) && tar -czf ../$(PACKAGE_NAME) ./ && echo "Package: $(PACKAGE_NAME)"
package-linux-amd64:
GOOS=linux GOARCH=amd64 $(MAKE) package-local
package-linux-arm64:
GOOS=linux GOARCH=arm64 $(MAKE) package-local
package: package-linux-amd64
BASE_IMAGE_VERSION=$(shell cat docker/base/VERSION)
BASE_REPOS_FROM=$(shell cat docker/base/REPOS_FROM)
BASE_PROVIDERS_FROM=$(shell cat docker/base/PROVIDERS_FROM)
base-image-portal:
$(DOCKER_BUILD) --build-arg REPOS=$(BASE_REPOS_FROM) -t ${BASE_IMAGE_DOCKER_REPO}/base-iac-portal:$(BASE_IMAGE_VERSION) -f docker/base/portal/Dockerfile .
base-image-portal-arm64:
$(DOCKER_BUILD) --build-arg REPOS=$(BASE_REPOS_FROM) -t ${BASE_IMAGE_DOCKER_REPO}/base-iac-portal:$(BASE_IMAGE_VERSION)-arm64 -f docker/base/portal/Dockerfile-arm64 .
base-image-runner:
$(DOCKER_BUILD) -t ${BASE_IMAGE_DOCKER_REPO}/base-ct-runner:$(BASE_IMAGE_VERSION) -f docker/base/runner/Dockerfile .
base-image-runner-arm64:
$(DOCKER_BUILD) -t ${BASE_IMAGE_DOCKER_REPO}/base-ct-runner:$(BASE_IMAGE_VERSION)-arm64 -f docker/base/runner/Dockerfile-arm64 .
base-image-worker:
$(DOCKER_BUILD) --build-arg PROVIDERS=$(BASE_PROVIDERS_FROM) -t ${BASE_IMAGE_DOCKER_REPO}/base-ct-worker:$(BASE_IMAGE_VERSION) -f docker/base/worker/Dockerfile .
base-image-worker-arm64:
$(DOCKER_BUILD) --build-arg PROVIDERS=$(BASE_PROVIDERS_FROM) -t ${BASE_IMAGE_DOCKER_REPO}/base-ct-worker:$(BASE_IMAGE_VERSION)-arm64 -f docker/base/worker/Dockerfile-arm64 .
base-image: base-image-portal base-image-runner base-image-worker
@echo "Update base image version to $(BASE_IMAGE_VERSION)" && bash scripts/update-base-image-version.sh
base-image-arm64: base-image-portal-arm64 base-image-runner-arm64 base-image-worker-arm64
bash scripts/update-base-image-version.sh
push-base-image:
for NAME in iac-portal ct-runner ct-worker; do \
docker push cloudiac/base-$${NAME}:$(BASE_IMAGE_VERSION) || exit $$?; \
done
image-portal: build-linux-amd64-portal
$(DOCKER_BUILD) -t ${DOCKER_REPO}/iac-portal:$(VERSION) -f docker/portal/Dockerfile .
image-portal-arm64: build-linux-arm64-portal
$(DOCKER_BUILD) -t ${DOCKER_REPO}/iac-portal:$(VERSION) -f docker/portal/Dockerfile-arm64 .
image-runner: build-linux-amd64-runner
$(DOCKER_BUILD) --build-arg WORKER_IMAGE=${DOCKER_REPO}/ct-worker:$(VERSION) \
-t ${DOCKER_REPO}/ct-runner:$(VERSION) -f docker/runner/Dockerfile .
image-runner-arm64: build-linux-arm64-runner
$(DOCKER_BUILD) --build-arg WORKER_IMAGE=${DOCKER_REPO}/ct-worker:$(VERSION) \
-t ${DOCKER_REPO}/ct-runner:$(VERSION) -f docker/runner/Dockerfile-arm64 .
image-worker: build-linux-amd64-portal
$(DOCKER_BUILD) -t ${DOCKER_REPO}/ct-worker:$(VERSION) -f docker/worker/Dockerfile .
image-worker-arm64: image-worker
image: image-portal image-worker image-runner
image-arm64: image-portal-arm64 image-runner-arm64 image-worker-arm64
push-image:
for NAME in iac-portal ct-runner ct-worker; do \
docker tag cloudiac/$${NAME}:$(VERSION) ${DOCKER_REGISTRY}/$${NAME}:$(VERSION) && \
docker push ${DOCKER_REGISTRY}/$${NAME}:$(VERSION) || exit $$?; \
done
push-image-latest:
for NAME in iac-portal ct-runner ct-worker; do \
docker tag cloudiac/$${NAME}:$(VERSION) ${DOCKER_REGISTRY}/$${NAME}:latest && \
docker push ${DOCKER_REGISTRY}/$${NAME}:latest || exit $$?; \
done
OSNAME=$(shell uname -s)
CMD_MD5SUM=md5sum | head -c8
ifeq ($(OSNAME),Darwin)
CMD_MD5SUM=md5 | head -c8
endif
repos: repos.list
mkdir -p ./repos/cloudiac && \
cd ./repos/cloudiac && bash ../../scripts/clone-repos.sh
REPOS_SHA1SUM=$(shell tar -c ./repos | $(CMD_MD5SUM))
REPOS_PACKAGE_NAME=cloudiac-repos_$(VERSION)_$(REPOS_SHA1SUM).tar.gz
repos-package:
tar -czf $(REPOS_PACKAGE_NAME) ./repos
#providers:
# bash scripts/generate-providers-mirror.sh
#
#providers-arm64:
# PLATFORM=linux_arm64 bash scripts/generate-providers-mirror.sh
#PROVIDERS_SHA1SUM=$(shell tar -c ./assets/providers | $(CMD_MD5SUM))
#PROVIDERS_PACKAGE_NAME=cloudiac-providers_$(VERSION)_$(PROVIDERS_SHA1SUM).tar.gz
#providers-package:
# @if [[ ! -e "$(PROVIDERS_PACKAGE_NAME)" ]]; then echo "Package $(PROVIDERS_PACKAGE_NAME)"; tar -czf $(PROVIDERS_PACKAGE_NAME) ./assets/providers; fi
#