forked from Edgenesis/shifu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
312 lines (256 loc) · 15.2 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
PROJECT_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
IMAGE_VERSION = $(shell cat version.txt)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.31.0
# Controller-Runtime branch `release-0.19` has the implementation of the setup-envtest's code responsible
# for downloading the tarball from the correct location.
ENVTEST_VERSION ?= release-0.19
DEVICESHIFU_CMDS := deviceshifu/cmdhttp deviceshifu/cmdmqtt deviceshifu/cmdopcua deviceshifu/cmdplc4x deviceshifu/cmdsocket
HTTPSTUB_CMDS := httpstub/powershellstub httpstub/sshstub
SHIFUCTL_CMD := shifuctl
TELEMETRYSERVICE_CMD := telemetryservice
CONTROLLER_CMD := pkg/k8s/crd
BUILD_TARGETS := $(DEVICESHIFU_CMDS) $(HTTPSTUB_CMDS) $(SHIFUCTL_CMD) $(TELEMETRYSERVICE_CMD)
fmt: ## Run go fmt against code.
go fmt ./...
vet: ## Run go vet against code.
go vet ./...
install: shifuctl
go install ${PROJECT_ROOT}/cmd/shifuctl
shifuctl:
cd ${PROJECT_ROOT}/cmd/shifuctl; go build
clean:
rm -f ${PROJECT_ROOT}/cmd/shifuctl/shifuctl
build:
for target in $(BUILD_TARGETS); do \
go build -o bin/$$target ./cmd/$$target; \
echo "finished building $$target"; \
done
echo "building controller"
cd $(CONTROLLER_CMD) && go build -o bin/shifu-controller main.go
.PHONY: test
test: fmt envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -race -coverprofile=coverage.out -covermode=atomic $(shell go list ./... | grep -v -E '/cmd|/mockdevice|/pkg/telemetryservice')
go test -v -coverprofile=coverage_tdengine.out -covermode=atomic ./pkg/telemetryservice/...
buildx-push-image-deviceshifu-http-http:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuHTTP \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-http:${IMAGE_VERSION} --push
buildx-push-image-deviceshifu-http-mqtt:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuMQTT \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-mqtt:${IMAGE_VERSION} --push
buildx-push-image-deviceshifu-http-socket:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuSocket \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-socket:${IMAGE_VERSION} --push
buildx-push-image-deviceshifu-http-opcua:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuOPCUA \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-opcua:${IMAGE_VERSION} --push
buildx-push-image-deviceshifu-http-plc4x:
docker buildx build --platform=linux/amd64,linux/arm64 -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuPLC4X \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-plc4x:${IMAGE_VERSION} --push
buildx-push-image-deviceshifu-tcp-tcp:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuTCP\
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-tcp-tcp:${IMAGE_VERSION} --push
buildx-push-image-deviceshifu-http-lwm2m:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuLwM2M \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-lwm2m:${IMAGE_VERSION} --push
buildx-push-image-gateway-lwm2m:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
-f $(PROJECT_ROOT)/dockerfiles/Dockerfile.gatewayLwM2M \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/gateway-lwm2m:$(IMAGE_VERSION) --push
buildx-push-image-shifu-controller:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f $(PROJECT_ROOT)/pkg/k8s/crd/Dockerfile \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/shifu-controller:$(IMAGE_VERSION) --push
buildx-push-image-mockdevice-thermometer:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/thermometer/Dockerfile.mockdevice-thermometer \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-thermometer:$(IMAGE_VERSION) --push
buildx-push-image-mockdevice-robot-arm:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/robot-arm/Dockerfile.mockdevice-robot-arm \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-robot-arm:$(IMAGE_VERSION) --push
buildx-push-image-mockdevice-plate-reader:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/plate-reader/Dockerfile.mockdevice-plate-reader \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-plate-reader:$(IMAGE_VERSION) --push
buildx-push-image-mockdevice-agv:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/agv/Dockerfile.mockdevice-agv \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-agv:$(IMAGE_VERSION) --push
buildx-push-image-mockdevice-plc:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/plc/Dockerfile.mockdevice-plc \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-plc:$(IMAGE_VERSION) --push
buildx-push-image-mockdevice-socket:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-socket:$(IMAGE_VERSION) --push
buildx-push-image-mockdevice-opcua:
docker buildx build --platform=linux/amd64,linux/arm64 \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-opcua:$(IMAGE_VERSION) --push
.PHONY: buildx-push-image-deviceshifu
buildx-push-image-deviceshifu: \
buildx-push-image-deviceshifu-http-http \
buildx-push-image-deviceshifu-http-mqtt \
buildx-push-image-deviceshifu-http-socket \
buildx-push-image-deviceshifu-http-opcua \
buildx-push-image-deviceshifu-http-plc4x \
buildx-push-image-deviceshifu-tcp-tcp \
buildx-push-image-deviceshifu-http-lwm2m \
buildx-push-image-gateway-lwm2m
buildx-push-image-telemetry-service:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.telemetryservice \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/telemetryservice:${IMAGE_VERSION} --push
buildx-build-image-shifu-controller:
docker buildx build --platform=linux/$(shell go env GOARCH) -f $(PROJECT_ROOT)/pkg/k8s/crd/Dockerfile \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/shifu-controller:$(IMAGE_VERSION) --load
buildx-build-image-deviceshifu-http-http:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuHTTP \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-http:${IMAGE_VERSION} --load
buildx-build-image-deviceshifu-http-lwm2m:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuLwM2M \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-lwm2m:${IMAGE_VERSION} --load
buildx-build-image-deviceshifu-http-mqtt:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuMQTT \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-mqtt:${IMAGE_VERSION} --load
buildx-build-image-deviceshifu-http-socket:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuSocket \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-socket:${IMAGE_VERSION} --load
buildx-build-image-deviceshifu-http-opcua:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuOPCUA \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-opcua:${IMAGE_VERSION} --load
buildx-build-image-deviceshifu-http-plc4x:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuPLC4X\
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-plc4x:${IMAGE_VERSION} --load
buildx-build-image-deviceshifu-tcp-tcp:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuTCP\
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-tcp-tcp:${IMAGE_VERSION} --load
buildx-build-image-mockdevice-thermometer:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/thermometer/Dockerfile.mockdevice-thermometer \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-thermometer:$(IMAGE_VERSION) --load
buildx-build-image-mockdevice-robot-arm:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/robot-arm/Dockerfile.mockdevice-robot-arm \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-robot-arm:$(IMAGE_VERSION) --load
buildx-build-image-mockdevice-plate-reader:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/plate-reader/Dockerfile.mockdevice-plate-reader \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-plate-reader:$(IMAGE_VERSION) --load
buildx-build-image-mockdevice-agv:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/agv/Dockerfile.mockdevice-agv \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-agv:$(IMAGE_VERSION) --load
buildx-build-image-mockdevice-plc:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/plc/Dockerfile.mockdevice-plc \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-plc:$(IMAGE_VERSION) --load
buildx-build-image-mockdevice-socket:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-socket:$(IMAGE_VERSION) --load
buildx-build-image-mockdevice-opcua:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/mockdevice-opcua:$(IMAGE_VERSION) --load
buildx-build-image-deviceshifu: \
buildx-build-image-deviceshifu-http-http \
buildx-build-image-deviceshifu-http-mqtt \
buildx-build-image-deviceshifu-http-socket \
buildx-build-image-deviceshifu-http-opcua \
buildx-build-image-deviceshifu-http-plc4x \
buildx-build-image-deviceshifu-tcp-tcp \
buildx-build-image-deviceshifu-http-lwm2m \
buildx-build-image-gateway-lwm2m
buildx-build-image-telemetry-service:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.telemetryservice\
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/telemetryservice:${IMAGE_VERSION} --load
buildx-build-image-gateway-lwm2m:
docker buildx build --platform=linux/$(shell go env GOARCH) \
-f $(PROJECT_ROOT)/dockerfiles/Dockerfile.gatewayLwM2M \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
-t edgehub/gateway-lwm2m:$(IMAGE_VERSION) --load
.PHONY: download-demo-files
download-demo-files:
docker pull edgehub/mockdevice-agv:${IMAGE_VERSION}
docker pull edgehub/mockdevice-plate-reader:${IMAGE_VERSION}
docker pull edgehub/mockdevice-robot-arm:${IMAGE_VERSION}
docker pull edgehub/mockdevice-thermometer:${IMAGE_VERSION}
docker pull edgehub/deviceshifu-http-http:${IMAGE_VERSION}
docker pull edgehub/shifu-controller:${IMAGE_VERSION}
docker pull bitnami/kube-rbac-proxy:0.14.1
docker pull nginx:1.21
docker-push-image-deviceshifu:
docker push edgehub/deviceshifu-http-http:${IMAGE_VERSION}
docker-push-deviceshifu-demo-image:
docker push edgehub/demo-image-alpine:${IMAGE_VERSION}
docker-push-image-mockdevices:
docker push edgehub/mockdevice-thermometer:${IMAGE_VERSION}
docker push edgehub/mockdevice-robot-arm:${IMAGE_VERSION}
docker push edgehub/mockdevice-plate-reader:${IMAGE_VERSION}
docker push edgehub/mockdevice-agv:${IMAGE_VERSION}
.PHONY: clean-images
clean-images:
docker rmi $(shell sudo docker images | grep 'edgehub')
tag:
go run tools/tag.go ${PROJECT_ROOT} ${IMAGE_VERSION} $(VERSION)
cd pkg/k8s/crd/ && (make generate-controller-yaml IMG=edgehub/shifu-controller:$(VERSION) generate-install-yaml)
sed -e "s/${IMAGE_VERSION}/${VERSION}/g" ./test/scripts/deviceshifu-demo-aio.sh > ./test/scripts/tmp.sh && mv ./test/scripts/tmp.sh ./test/scripts/deviceshifu-demo-aio.sh
echo $(VERSION) > version.txt
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.16.3
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))