This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
forked from enableiot/iotkit-agent
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
76 lines (64 loc) · 3.01 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
#----------------------------------------------------------------------------------------------------------------------
# targets
#----------------------------------------------------------------------------------------------------------------------
IMAGE_NAME = oisp/oisp-iot-agent
CONTAINER_NAME = oisp-iot-agent
GETAGENTENVDIR = container/test
GETSAMPLES = ./getSamples.sh
CONFIGFILE = ${GETAGENTENVDIR}/testconfig.sh
DEVICENAME:=agenttestdevice
SHELL := /bin/bash
OISP_PREP_FILE ?= ../tests/oisp-prep-only.conf
USERNAME = $(shell cat ${OISP_PREP_FILE} | jq .username)
PASSWORD = $(shell cat ${OISP_PREP_FILE} | jq .password)
ACCOUNTID = $(shell cat ${OISP_PREP_FILE} | jq .accountId)
COMPONENT_NAME = "temp"
build:
@$(call msg,"Building oisp-agent ...");
@docker build . -t ${IMAGE_NAME}
start:
@$(call msg,"Starting oisp-agent container...");
@echo USERNAME=${USERNAME} PASSWORD=${PASSWORD}
@source ${CONFIGFILE} && \
echo Starting container with the following settings: OISP_DEVICE_ACTIVATION_CODE="$${OISP_DEVICE_ACTIVATION_CODE}" \
OISP_DEVICE_ID="$${OISP_DEVICE_ID}" && \
docker run \
-d -t -i --network=host --rm \
--env OISP_DEVICE_ACTIVATION_CODE=$${OISP_DEVICE_ACTIVATION_CODE} \
--env OISP_DEVICE_ID=$${OISP_DEVICE_ID} \
--env OISP_DEVICE_NAME=$${OISP_DEVICE_NAME} \
--env OISP_FORCE_REACTIVATION=$${OISP_FORCE_REACTIVATION} \
--name ${CONTAINER_NAME} ${IMAGE_NAME}
stop:
@$(call msg,"Stopping oisp-agent ...");
@docker stop ${CONTAINER_NAME} || echo "${CONTAINER_NAME} cannot be stopped."
@docker rm -f ${CONTAINER_NAME} || echo "${CONTAINER_NAME} cannot be removed."
@make -C container stop
clean: stop
@$(call msg,"Cleaning ...");
@docker rm -f ${CONTAINER_NAME} || echo "${CONTAINER_NAME} cannot be deleted"
@/bin/bash -c "docker rmi -f ${IMAGE_NAME}" || echo "${IMAGE_NAME} cannot be deleted"
@rm -f .prepare-testconfig
@make -C container clean
@./oisp-admin.js reset-data-directory
@rm -f config/config.json
.prepare-testconfig:
@cp -n config/config.json.template config/config.json
cd ${GETAGENTENVDIR} && make build && source ./getActivationCode.sh ${USERNAME} ${PASSWORD} ${DEVICENAME}
@touch $@
test: .prepare-testconfig build start
# Testing basic data sending
@make COMPONENT_NAME=${COMPONENT_NAME} ACCOUNTID=${ACCOUNTID} DEVICENAME=${DEVICENAME} USERNAME=${USERNAME} PASSWORD=${PASSWORD} -C container test
# Testing automatic device token refresh mechanism
@docker exec oisp-iot-agent ./oisp-admin.js force-device-token-refresh
@docker exec oisp-iot-agent ./oisp-admin.js register refresh-test-sensor temperature.v1.0
#----------------------------------------------------------------------------------------------------------------------
# helper functions
#----------------------------------------------------------------------------------------------------------------------
define msg
tput setaf 2 && \
for i in $(shell seq 1 120 ); do echo -n "-"; done; echo -n "\n" && \
echo "\t"$1 && \
for i in $(shell seq 1 120 ); do echo -n "-"; done; echo "\n" && \
tput sgr0
endef