forked from baetyl/baetyl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
237 lines (197 loc) · 10.8 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
PREFIX?=/usr/local
VERSION?=git-$(shell git rev-list HEAD|head -1|cut -c 1-6)
GOFLAG?=-ldflags "-X 'github.com/baidu/openedge/cmd.GoVersion=`go version`' -X 'github.com/baidu/openedge/cmd.Version=$(VERSION)'"
DEPLOY_TARGET=agent hub function-manager remote-mqtt timer function-python function-node
all: openedge package
package:
for target in $(DEPLOY_TARGET) ; do \
make openedge-$$target/package.zip;\
done
SRC=$(wildcard *.go) $(shell find cmd master logger sdk protocol utils -type f -name '*.go')
openedge: $(SRC)
@echo "BUILD $@"
@go build -o openedge ${GOFLAG} .
openedge-hub/package.zip:
make -C openedge-hub
openedge-agent/package.zip:
make -C openedge-agent
openedge-remote-mqtt/package.zip:
make -C openedge-remote-mqtt
openedge-function-manager/package.zip:
make -C openedge-function-manager
openedge-function-python/package.zip:
make -C openedge-function-python package27.zip
make -C openedge-function-python package36.zip
openedge-function-node/package.zip:
make -C openedge-function-node package85.zip
openedge-timer/package.zip:
make -C openedge-timer
test:
go test --race --cover ./...
install: openedge
install -d -m 0755 ${PREFIX}/bin
install -m 0755 openedge ${PREFIX}/bin/
tar cf - -C example/docker etc var | tar xvf - -C ${PREFIX}/
install-native: openedge package
install -d -m 0755 ${PREFIX}/bin
install -m 0755 openedge ${PREFIX}/bin/
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-hub
unzip -o openedge-hub/package.zip -d ${PREFIX}/var/db/openedge/openedge-hub
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-agent
unzip -o openedge-agent/package.zip -d ${PREFIX}/var/db/openedge/openedge-agent
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-remote-mqtt
unzip -o openedge-remote-mqtt/package.zip -d ${PREFIX}/var/db/openedge/openedge-remote-mqtt
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-function-manager
unzip -o openedge-function-manager/package.zip -d ${PREFIX}/var/db/openedge/openedge-function-manager
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-function-python27
unzip -o openedge-function-python/package27.zip -d ${PREFIX}/var/db/openedge/openedge-function-python27
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-function-python36
unzip -o openedge-function-python/package36.zip -d ${PREFIX}/var/db/openedge/openedge-function-python36
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-function-node85
unzip -o openedge-function-node/package85.zip -d ${PREFIX}/var/db/openedge/openedge-function-node85
install -d -m 0755 ${PREFIX}/var/db/openedge/openedge-timer
unzip -o openedge-timer/package.zip -d ${PREFIX}/var/db/openedge/openedge-timer
tar cf - -C example/native etc var | tar xvf - -C ${PREFIX}/
.PHONY: uninstall
uninstall:
@rm -f ${PREFIX}/bin/openedge
@rm -rf ${PREFIX}/etc/openedge
@rm -rf ${PREFIX}/var/db/openedge
@rm -rf ${PREFIX}/var/log/openedge
@rm -rf ${PREFIX}/var/run/openedge
@! test -d ${PREFIX}/var/db || ! ls ${PREFIX}/var/db | xargs test -z || rmdir ${PREFIX}/var/db
@! test -d ${PREFIX}/var/log || ! ls ${PREFIX}/var/log | xargs test -z || rmdir ${PREFIX}/var/log
@! test -d ${PREFIX}/var/run || ! ls ${PREFIX}/var/run | xargs test -z || rmdir ${PREFIX}/var/run
@! test -d ${PREFIX}/var || ! ls ${PREFIX}/var | xargs test -z || rmdir ${PREFIX}/var
@! test -d ${PREFIX}/etc || ! ls ${PREFIX}/etc | xargs test -z || rmdir ${PREFIX}/etc
@! test -d ${PREFIX}/bin || ! ls ${PREFIX}/bin | xargs test -z || rmdir ${PREFIX}/bin
@! test -d ${PREFIX} || ! ls ${PREFIX} | xargs test -z || rmdir ${PREFIX}
.PHONY: uninstall-native
uninstall-native: uninstall
.PHONY: clean
clean:
rm -f openedge
make -C openedge-hub clean
make -C openedge-agent clean
make -C openedge-remote-mqtt clean
make -C openedge-function-manager clean
make -C openedge-function-python clean
make -C openedge-function-node clean
make -C openedge-timer clean
rebuild: clean all
generate:
go generate ./...
image: clean
for target in $(DEPLOY_TARGET) ; do \
make -C openedge-$$target image;\
done
function-python-image:
make -C openedge-function-python image
release: clean release-master release-image push-image release-manifest
release-master: clean
# release linux 386
env GOOS=linux GOARCH=386 make install PREFIX=__release_build/openedge-$(VERSION)-linux-386
cd __release_build/openedge-$(VERSION)-linux-386 && zip -q -r ../../openedge-$(VERSION)-linux-386.zip bin/
make uninstall clean PREFIX=__release_build/openedge-$(VERSION)-linux-386
# release linux amd64
env GOOS=linux GOARCH=amd64 make install PREFIX=__release_build/openedge-$(VERSION)-linux-amd64
cd __release_build/openedge-$(VERSION)-linux-amd64 && zip -q -r ../../openedge-$(VERSION)-linux-amd64.zip bin/
make uninstall clean PREFIX=__release_build/openedge-$(VERSION)-linux-amd64
# release linux arm v7
env GOOS=linux GOARCH=arm GOARM=7 make install PREFIX=__release_build/openedge-$(VERSION)-linux-armv7
cd __release_build/openedge-$(VERSION)-linux-armv7 && zip -q -r ../../openedge-$(VERSION)-linux-armv7.zip bin/
make uninstall clean PREFIX=__release_build/openedge-$(VERSION)-linux-armv7
# release linux arm64
env GOOS=linux GOARCH=arm64 make install PREFIX=__release_build/openedge-$(VERSION)-linux-arm64
cd __release_build/openedge-$(VERSION)-linux-arm64 && zip -q -r ../../openedge-$(VERSION)-linux-arm64.zip bin/
make uninstall clean PREFIX=__release_build/openedge-$(VERSION)-linux-arm64
# release darwin amd64
env GOOS=darwin GOARCH=amd64 make install PREFIX=__release_build/openedge-$(VERSION)-darwin-amd64
cd __release_build/openedge-$(VERSION)-darwin-amd64 && zip -q -r ../../openedge-$(VERSION)-darwin-amd64.zip bin/
make uninstall PREFIX=__release_build/openedge-$(VERSION)-darwin-amd64
make clean
# at last
rmdir __release_build
release-image: clean
# linux-amd64 images release
env GOOS=linux GOARCH=amd64 make image IMAGE_SUFFIX="-linux-amd64"
make clean
# linux-386 images release
env GOOS=linux GOARCH=386 make image IMAGE_SUFFIX="-linux-386"
make clean
# linux-arm images release
env GOOS=linux GOARCH=arm GOARM=7 make image IMAGE_SUFFIX="-linux-armv7"
make clean
# linux-arm64 images release
env GOOS=linux GOARCH=arm64 make image IMAGE_SUFFIX="-linux-arm64"
make clean
release-manifest:
rm -rf tmp
mkdir tmp
for target in $(DEPLOY_TARGET) ; do \
sed "s?__IMAGE_PREFIX__?$(IMAGE_PREFIX)?g; s?__TAG__?$(VERSION)?g; s?__VERSION__?$(VERSION)?g; s?__TARGET__?openedge-$$target?g;" manifest.yml.template > tmp/manifest-$$target-$(VERSION).yml;\
./bin/manifest-tool-darwin-amd64 --insecure --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-$$target-$(VERSION).yml;\
sed "s?__IMAGE_PREFIX__?$(IMAGE_PREFIX)?g; s?__TAG__?latest?g; s?__VERSION__?$(VERSION)?g; s?__TARGET__?openedge-$$target?g;" manifest.yml.template > tmp/manifest-$$target-latest.yml;\
./bin/manifest-tool-darwin-amd64 --insecure --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-$$target-latest.yml;\
done
rm -rf tmp
# You need build the function-builder image at different platforms and push them to the hub first
release-builder-manifest:
mkdir tmp
# Push openedge-python27-builder manifest version
sed "s/__REGISTRY__/$(REGISTRY)/g; s/__NAMESPACE__/$(NAMESPACE)/g; s/__VERSION__/$(VERSION)/g;" openedge-function-python/manifest-python27-builder.yml.template > tmp/manifest-python27-builder-$(VERSION).yml
./bin/manifest-tool-linux-amd64 --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-python27-builder-$(VERSION).yml
# Push openedge-python27-builder manifest latest
sed "s/__REGISTRY__/$(REGISTRY)/g; s/__NAMESPACE__/$(NAMESPACE)/g; s/__VERSION__/latest/g;" openedge-function-python/manifest-python27-builder.yml.template > tmp/manifest-python27-builder-latest.yml
./bin/manifest-tool-linux-amd64 --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-python27-builder-latest.yml
# Push openedge-python36-builder manifest version
sed "s/__REGISTRY__/$(REGISTRY)/g; s/__NAMESPACE__/$(NAMESPACE)/g; s/__VERSION__/$(VERSION)/g;" openedge-function-python/manifest-python36-builder.yml.template > tmp/manifest-python36-builder-$(VERSION).yml
./bin/manifest-tool-linux-amd64 --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-python36-builder-$(VERSION).yml
# Push openedge-python36-builder manifest latest
sed "s/__REGISTRY__/$(REGISTRY)/g; s/__NAMESPACE__/$(NAMESPACE)/g; s/__VERSION__/latest/g;" openedge-function-python/manifest-python36-builder.yml.template > tmp/manifest-python36-builder-latest.yml
./bin/manifest-tool-linux-amd64 --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-python36-builder-latest.yml
# Push openedge-node85-builder manifest version
sed "s/__REGISTRY__/$(REGISTRY)/g; s/__NAMESPACE__/$(NAMESPACE)/g; s/__VERSION__/$(VERSION)/g;" openedge-function-node/manifest-node85-builder.yml.template > tmp/manifest-node85-builder-$(VERSION).yml
./bin/manifest-tool-linux-amd64 --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-node85-builder-$(VERSION).yml
# Push openedge-node85-builder manifest latest
sed "s/__REGISTRY__/$(REGISTRY)/g; s/__NAMESPACE__/$(NAMESPACE)/g; s/__VERSION__/latest/g;" openedge-function-node/manifest-node85-builder.yml.template > tmp/manifest-node85-builder-latest.yml
./bin/manifest-tool-linux-amd64 --username=$(USERNAME) --password=$(PASSWORD) push from-spec tmp/manifest-node85-builder-latest.yml
rm -rf tmp
release-package: clean
# Release modules' package -- linux armv7
env GOOS=linux GOARCH=arm GOARM=7 make package
for target in $(DEPLOY_TARGET) ; do \
mv openedge-$$target/package.zip ./openedge-$$target-linux-armv7-$(VERSION).zip;\
done
make clean
# Release modules' package -- linux amd64
env GOOS=linux GOARCH=amd64 make package
for target in $(DEPLOY_TARGET); do \
mv openedge-$$target/package.zip ./openedge-$$target-linux-amd64-$(VERSION).zip;\
done
make clean
# Release modules' package -- linux arm64
env GOOS=linux GOARCH=arm64 make package
for target in $(DEPLOY_TARGET); do \
mv openedge-$$target/package.zip ./openedge-$$target-linux-arm64-$(VERSION).zip;\
done
make clean
# Release modules' package -- linux 386
env GOOS=linux GOARCH=386 make package
for target in $(DEPLOY_TARGET); do \
mv openedge-$$target/package.zip ./openedge-$$target-linux-386-$(VERSION).zip;\
done
make clean
# Release modules' package -- darwin amd64
env GOOS=darwin GOARCH=amd64 make package
for target in $(DEPLOY_TARGET); do \
mv openedge-$$target/package.zip ./openedge-$$target-darwin-amd64-$(VERSION).zip;\
done
make clean
push-image:
for target in $(DEPLOY_TARGET); do \
docker push $(IMAGE_PREFIX)/openedge-$$target:$(VERSION)-linux-amd64;\
docker push $(IMAGE_PREFIX)/openedge-$$target:$(VERSION)-linux-arm64;\
docker push $(IMAGE_PREFIX)/openedge-$$target:$(VERSION)-linux-armv7;\
docker push $(IMAGE_PREFIX)/openedge-$$target:$(VERSION)-linux-386;\
done