Skip to content

Commit 130fecd

Browse files
authored
Merge pull request #7 from cen-ngc5139/ghostbaby
feat: enhance Makefile for deployment automation
2 parents c453343 + 23fcabf commit 130fecd

File tree

2 files changed

+72
-9
lines changed

2 files changed

+72
-9
lines changed

Makefile

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,48 @@ VERSION=$(shell git describe --tags --always)
99
# For compiling libpcap and CGO
1010
CC ?= gcc
1111

12+
# 变量定义
13+
SSH_PASS := sshpass -p root
14+
SSH_OPTS := -o 'StrictHostKeyChecking no' -P 10022
15+
REMOTE_HOST := [email protected]
16+
MAX_RETRIES := 3
17+
18+
QEMU_LOG := qemu.log
19+
20+
# 定义超时时间(5分钟 = 300秒)
21+
TIMEOUT := 300
22+
LOG_FILE := /root/log/info.log
23+
24+
# .PHONY 声明
25+
.PHONY: deploy check-connection copy-files clean retry all
26+
27+
# 默认目标
28+
all: deploy
29+
30+
# 主要部署流程
31+
deploy: check-connection copy-files
32+
@echo "Deployment complete"
33+
34+
# 连接检查
35+
check-connection:
36+
@echo "Checking remote host connection..."
37+
while ! nc -z 127.0.0.1 10022 ; do echo "waiting for ssh"; sleep 1; done
38+
39+
# 文件复制
40+
copy-files:
41+
@echo "Copying files to remote host..."
42+
@for i in $$(seq 1 $(MAX_RETRIES)); do \
43+
echo "Attempt $$i of $(MAX_RETRIES)"; \
44+
if $(SSH_PASS) scp $(SSH_OPTS) ./cmd/shepherd $(REMOTE_HOST):/root/shepherd && \
45+
$(SSH_PASS) scp $(SSH_OPTS) ./cmd/config.yaml $(REMOTE_HOST):/root/config.yaml; then \
46+
echo "Files copied successfully"; \
47+
exit 0; \
48+
fi; \
49+
echo "Copy failed, retrying..."; \
50+
sleep 2; \
51+
done; \
52+
echo "All retry attempts failed"; \
53+
exit 1
1254

1355
build: elf
1456
cd ./cmd;CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_LDFLAGS='-g -lcapstone -static' go build -tags=netgo,osusergo -gcflags "all=-N -l" -v -o shepherd
@@ -60,21 +102,42 @@ start_qemu:
60102
-net nic -net user,hostfwd=tcp::10022-:22,hostfwd=tcp::16676-:6676,hostfwd=tcp::10443-:443 \
61103
-enable-kvm \
62104
-pidfile qemu.pid \
63-
-nographic &
105+
-nographic > $(QEMU_LOG) 2>&1 &
64106

65107
.ONESHELL:
66-
prepare_e2e: start_qemu
67-
while ! nc -z 127.0.0.1 10022 ; do echo "waiting for ssh"; sleep 1; done
68-
sshpass -p root scp -o 'StrictHostKeyChecking no' -P 10022 ./cmd/shepherd [email protected]:/root/shepherd
69-
sshpass -p root scp -o 'StrictHostKeyChecking no' -P 10022 ./cmd/config.yaml [email protected]:/root/config.yaml
108+
prepare_e2e: start_qemu deploy
70109
sshpass -p root ssh -p 10022 [email protected] 'chmod 0655 /root/shepherd && systemctl start shepherd.service'
71110
while ! sshpass -p root ssh -p 10022 [email protected] 'systemctl is-active shepherd.service' ; do echo "waiting for shepherd service"; sleep 1; done
72111

73112
.ONESHELL:
74-
e2e: prepare_e2e
113+
e2e: prepare_e2e check-log
75114
ifconfig
76115
RC=$$?
77-
pwd
78-
sshpass -p root ssh -p 10022 [email protected] 'ls /root && ls /root/log/'
116+
sshpass -p root ssh -p 10022 [email protected] 'systemctl status shepherd.service'
79117
sudo cat ./tests/e2e/vm/filesystem/qemu.pid | sudo xargs kill
80118
exit $$RC
119+
120+
check-log:
121+
@echo "Checking log file..."
122+
@start_time=$$(date +%s); \
123+
while true; do \
124+
current_time=$$(date +%s); \
125+
elapsed_time=$$((current_time - start_time)); \
126+
if [ $$elapsed_time -gt $(TIMEOUT) ]; then \
127+
echo "Timeout after $(TIMEOUT) seconds"; \
128+
exit 1; \
129+
fi; \
130+
if sshpass -p root ssh -p 10022 [email protected] "\
131+
if [ -f $(LOG_FILE) ] && [ -s $(LOG_FILE) ]; then \
132+
cat $(LOG_FILE); \
133+
exit 0; \
134+
else \
135+
exit 1; \
136+
fi"; then \
137+
echo "Log file found and not empty"; \
138+
break; \
139+
else \
140+
echo "Waiting for log file... ($$elapsed_time seconds elapsed)"; \
141+
sleep 5; \
142+
fi; \
143+
done

cmd/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ btf:
55
kernel: "/sys/kernel/btf/vmlinux"
66

77
output:
8-
type: clickhouse
8+
type: file
99
clickhouse:
1010
host: "192.168.200.201"
1111
port: "9000"

0 commit comments

Comments
 (0)