Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
209 lines (178 loc) · 6.93 KB
/
Copy pathMakefile
File metadata and controls
209 lines (178 loc) · 6.93 KB
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
.DEFAULT_GOAL := install
VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo "devel")
GIT_DIRTY ?= $(shell git status --porcelain 2>/dev/null)
ifeq ($(GIT_DIRTY),)
BUILD_VERSION = $(VERSION)
else
BUILD_VERSION = devel
endif
LDFLAGS = -ldflags="-X 'pvmlab/internal/config.Version=$(BUILD_VERSION)'"
.PHONY: isntall socket_vmnet clean clean.iso install.socket_vmnet install.socket_vmnet.launchd install.completions test test.coverage integration.test uninstall uninstall-pvmlab uninstall.socket_vmnet uninstall.launchd uninstall.completions uninstall-pxeboot-stack-container clean.initrd clean.socket_vmnet build.socket_vmnet build-pxeboot-stack-container release lint lint.md clean.iso clean.initrd
install: install-pvmlab install.completions install.launchd build-pxeboot-stack-container
@echo "🚀"
clean: clean.iso clean.initrd
@make -C pxeboot_stack clean
clean.iso:
@echo "Cleaning generated ISOs..."
@rm -f ~/.pvmlab/configs/cloud-init/*.iso
clean.initrd:
@echo "Cleaning generated initrds..."
make -C pxeboot_stack/initrd clean
install-pvmlab:
go install $(LDFLAGS) ./pvmlab
build-pxeboot-stack-container:
@make -C pxeboot_stack all
define load_launchd
@if pvmlab vm list 2>/dev/null | grep -q Running; then \
echo "Error: Cannot reload launchd service while VMs are running. Please stop all VMs first."; \
exit 1; \
fi
logger "Stopping launchd service $(1) if running..."
sudo launchctl bootout system "/Library/LaunchDaemons/$(1).plist" || true
@logger "Installing launchd service for socket_vmnet in /Library/LaunchDaemons/$(1).plist"
sudo cp launchd/$(1).plist /Library/LaunchDaemons/$(1).plist
sudo launchctl enable system/$(1)
sudo launchctl bootstrap system "/Library/LaunchDaemons/$(1).plist" || true
sudo launchctl kickstart -kp system/$(1)
sudo launchctl list $(1)
endef
define unload_launchd
@if pvmlab vm list 2>/dev/null | grep -q Running; then \
echo "Error: Cannot unload launchd service while VMs are running. Please stop all VMs first."; \
exit 1; \
fi
logger "Uninstalling launchd service for ${1}"
sudo launchctl bootout system "$(DESTDIR)/Library/LaunchDaemons/$(1).plist" || true
sudo rm -f /Library/LaunchDaemons/$(1).plist
endef
install.launchd:
logger "Installing launchd wrapper script..."
sudo mkdir -p /opt/pvmlab/libexec/
sudo cp launchd/socket_vmnet_wrapper.sh /opt/pvmlab/libexec/socket_vmnet_wrapper.sh
sudo chmod +x /opt/pvmlab/libexec/socket_vmnet_wrapper.sh
$(call load_launchd,io.github.pallotron.pvmlab.socket_vmnet)
uninstall.launchd:
logger "Uninstalling launchd wrapper script..."
sudo rm -f /opt/pvmlab/libexec/socket_vmnet_wrapper.sh
$(call unload_launchd,io.github.pallotron.pvmlab.socket_vmnet)
install.completions: install-pvmlab
@echo "Installing shell completions..."
@if command -v brew &> /dev/null; then \
BASH_COMPLETION_DIR=$$(brew --prefix)/etc/bash_completion.d; \
mkdir -p $$BASH_COMPLETION_DIR; \
pvmlab completion bash > $$BASH_COMPLETION_DIR/pvmlab; \
echo "Bash completion installed in $$BASH_COMPLETION_DIR"; \
echo "Run 'source $$BASH_COMPLETION_DIR/pvmlab' to load it."; \
else \
echo "brew not found, skipping bash completion installation"; \
fi
@if command -v zsh &> /dev/null; then \
INSTALLED=false; \
for dir in $$(zsh -i -c 'echo $$fpath'); do \
echo "Trying $$dir"; \
if [ -d "$$dir" ]; then \
if pvmlab completion zsh | sudo tee "$$dir/_pvmlab" >/dev/null ; then \
echo "Zsh completion installed in $$dir"; \
echo "Run 'source $$dir/_pvmlab' to load it."; \
INSTALLED=true; \
break; \
fi; \
fi; \
done; \
if [ "$$INSTALLED" = "false" ]; then \
echo "Could not install zsh completion in any fpath directory."; \
fi; \
else \
echo "zsh not found, skipping zsh completion installation"; \
fi
release:
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make release VERSION=vX.Y.Z"; \
exit 1; \
fi
@if [ -n "$$(git status --porcelain)" ]; then \
echo "Git working directory is not clean. Please commit or stash your changes."; \
exit 1; \
fi
git tag -a $(VERSION) -m "Version $(VERSION)"
git push origin $(VERSION)
@echo "🎉"
uninstall: uninstall-pvmlab uninstall.launchd uninstall.completions uninstall-pxeboot-stack-container
@echo "Uninstall complete."
@echo "👋"
uninstall-pvmlab:
@echo "stopping all VMs..."
@echo "Uninstalling pvmlab binary..."
@if [ -f "$$(go env GOPATH)/bin/pvmlab" ]; then \
pvmlab clean --purge \
rm "$$(go env GOPATH)/bin/pvmlab"; \
echo "Removed $$(go env GOPATH)/bin/pvmlab"; \
else \
echo "pvmlab binary not found, skipping."; \
fi
uninstall.completions:
@echo "Uninstalling shell completions..."
@if command -v brew &> /dev/null; then \
BASH_COMPLETION_DIR=$$(brew --prefix)/etc/bash_completion.d; \
if [ -f "$$BASH_COMPLETION_DIR/pvmlab" ]; then \
rm "$$BASH_COMPLETION_DIR/pvmlab"; \
echo "Bash completion removed from $$BASH_COMPLETION_DIR"; \
else \
echo "Bash completion not found, skipping."; \
fi; \
else \
echo "brew not found, skipping bash completion uninstallation"; \
fi
@if command -v zsh &> /dev/null; then \
UNINSTALLED=false; \
for dir in $$(zsh -i -c 'echo $$fpath'); do \
if [ -f "$$dir/_pvmlab" ]; then \
if sudo rm "$$dir/_pvmlab"; then \
echo "Zsh completion removed from $$dir"; \
UNINSTALLED=true; \
break; \
fi; \
fi; \
done; \
if [ "$$UNINSTALLED" = "false" ]; then \
echo "Could not find zsh completion file to remove."; \
fi; \
else \
echo "zsh not found, skipping zsh completion uninstallation"; \
fi
uninstall-pxeboot-stack-container:
@echo "Uninstalling pxeboot stack container..."
@make -C pxeboot_stack clean || true
MD_FILES := $(shell find . -name "*.md" -not -path "./socket_vmnet/*" -not -path "./pxeboot_stack/initrd/u-root/*")
.PHONY: lint lint.md
lint: lint.md
lint.md:
@echo "Linting Markdown files..."
@if ! command -v markdownlint &> /dev/null; then \
echo "markdownlint not found. Please install with 'brew install markdownlint-cli'"; \
exit 1; \
fi
markdownlint --disable MD013 MD033 MD041 --fix $(MD_FILES)
test:
RUN_INTEGRATION_TESTS=false go test ./...
test.coverage:
@echo "Running tests with coverage..."
@RUN_INTEGRATION_TESTS=false go test ./... -coverprofile=coverage.txt -covermode=atomic
@echo ""
@echo "Coverage summary:"
@go tool cover -func=coverage.txt | tail -1
@echo ""
@echo "Detailed coverage by package:"
@go tool cover -func=coverage.txt | grep -E "^total:|pvmlab/" | grep -v ".pb.go"
@echo ""
@echo "HTML coverage report generated at coverage.html"
@go tool cover -html=coverage.txt -o coverage.html
integration.test:
@make -C pxeboot_stack tar
@RUN_INTEGRATION_TESTS=true go test ./tests/integration/...
integration.test.ssh.provisioner:
@PVMLAB_HOME=$$(./tests/find-test-pvmlab-home.sh) ./build/pvmlab_test vm shell test-provisioner
integration.test.ssh.client:
@PVMLAB_HOME=$$(./tests/find-test-pvmlab-home.sh) ./build/pvmlab_test vm shell test-client
github-ci.go-test:
act -W .github/workflows/go-test.yml --container-daemon-socket -