-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
97 lines (81 loc) · 3.39 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
all: build-docker-image
# NOTE: the architecture "armhf" (ARM v6) is excluded from the list because Go toolchain is not available there
ARCH:=--armv7 --amd64 --aarch64 --i386
ifeq ($(FAST),1)
# pick just 1 arch instead of all, to speedup
ARCH:=--amd64
endif
IMAGETAG:=$(shell yq .image config.yaml | sed 's@{arch}@amd64@g')
BACKEND_SOURCE_CODE_FILES:=$(shell find dhcp-clients-webapp-backend/ -type f -name '*.go')
ROOTFS_FILES:=$(shell find rootfs/ -type f)
build-docker-image: $(BACKEND_SOURCE_CODE_FILES) $(ROOTFS_FILES)
docker run \
--rm \
--privileged \
-v ~/.docker:/root/.docker \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v $(shell pwd):/data \
ghcr.io/home-assistant/amd64-builder \
$(ARCH) \
--target /data \
--version localtest \
--self-cache \
--test
# non-containerized build of the backend -- requires you to have go installed:
build-backend:
cd dhcp-clients-webapp-backend && \
go build -o bin/backend .
cd dhcp-clients-webapp-backend && \
golangci-lint run
cd dhcp-clients-webapp-backend && \
go test -v -cover ./...
TEST_CONTAINER_NAME:=dnsmasq-dhcp-test
DOCKER_RUN_OPTIONS:= \
-v $(shell pwd)/test-options.json:/data/options.json \
-v $(shell pwd)/test-leases.leases:/data/dnsmasq.leases \
-v $(shell pwd)/test-db.sqlite3:/data/trackerdb.sqlite3 \
-v $(shell pwd)/test-startepoch:/data/startepoch \
-v $(shell pwd)/dhcp-clients-webapp-backend:/app \
-v $(shell pwd)/dhcp-clients-webapp-backend/templates:/opt/web/templates/ \
-v $(shell pwd)/rootfs/opt/bin/dnsmasq-dhcp-script.sh:/opt/bin/dnsmasq-dhcp-script.sh \
-e LOCAL_TESTING=1 \
--cap-add NET_ADMIN \
--network host
# when using the 'test-docker-image' target it's normal to see messages like
# "Something went wrong contacting the API"
# at startup of the docker container... the reason is that the startup scripts
# will try to reach to HomeAssistant Supervisor which is not running...
test-docker-image:
$(MAKE) FAST=1 build-docker-image
@echo "Starting container of image ${IMAGETAG}:localtest"
docker run \
--rm \
--name $(TEST_CONTAINER_NAME) \
${DOCKER_RUN_OPTIONS} \
${IMAGETAG}:localtest
test-docker-image-live:
docker build -f Dockerfile.live -t debug-image-live .
@echo "Starting container of image debug-image-live"
docker run \
--rm \
--name $(TEST_CONTAINER_NAME) \
${DOCKER_RUN_OPTIONS} \
debug-image-live
INPUT_SCSS:=$(shell pwd)/dhcp-clients-webapp-backend/templates/scss/
OUTPUT_CSS:=$(shell pwd)/dhcp-clients-webapp-backend/templates/
build-css-live:
docker run -v $(INPUT_SCSS):/sass/ -v $(OUTPUT_CSS):/css/ -it michalklempa/dart-sass:latest
test-database-show:
sqlite3 test-db.sqlite3 'select * from dhcp_clients;'
test-database-drop:
sqlite3 test-db.sqlite3 'drop table dhcp_clients;'
# this target assumes that you launched 'test-docker-image-live' previously
test-database-add-entry:
docker exec -ti $(TEST_CONTAINER_NAME) /opt/bin/dnsmasq-dhcp-script.sh add "00:11:22:33:44:57" "192.168.1.250" "test-entry"
test-database-add-entry2:
docker exec -ti $(TEST_CONTAINER_NAME) /opt/bin/dnsmasq-dhcp-script.sh add "aa:bb:cc:dd:ee:01" "192.168.1.251" "test-entry2"
# NOTE:
# docker exec -ti $(TEST_CONTAINER_NAME) /opt/bin/dnsmasq-dhcp-script.sh del "00:11:22:33:44:57" "192.168.1.250" "test-entry"
# won't work: there is no 'del' support... the only way to
test-database-del-entry:
sqlite3 test-db.sqlite3 "DELETE FROM dhcp_clients WHERE mac_addr = '00:11:22:33:44:57';"