-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (91 loc) · 3.26 KB
/
Makefile
File metadata and controls
111 lines (91 loc) · 3.26 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
PROJECT_NAME = https_proxy
VERSION = $(shell cat VERSION | tr -d '[:space:]')
INSTALL_DIR = /usr/bin
CONFIG_DIR = /etc/$(PROJECT_NAME)
SYSTEMD_DIR = /etc/systemd/system
DOCKER_IMAGE = hightemp/$(PROJECT_NAME)
.PHONY: build run clean install uninstall install-service uninstall-service start stop restart status enable disable release docker-build docker-push docker-release
build:
CGO_ENABLED=0 go build -o $(PROJECT_NAME) main.go
chmod +x $(PROJECT_NAME)
build-static:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o $(PROJECT_NAME)_static main.go
chmod +x $(PROJECT_NAME)
run:
./$(PROJECT_NAME)
clean:
rm -f $(PROJECT_NAME)
rm -f $(PROJECT_NAME)_static
install: build
@echo "Installing $(PROJECT_NAME)..."
install -d $(CONFIG_DIR)
install -m 755 $(PROJECT_NAME) $(INSTALL_DIR)/$(PROJECT_NAME)
@if [ ! -f $(CONFIG_DIR)/config.yaml ]; then \
install -m 644 config.example.yaml $(CONFIG_DIR)/config.yaml; \
echo "Config installed: $(CONFIG_DIR)/config.yaml"; \
else \
echo "Config already exists, skipping: $(CONFIG_DIR)/config.yaml"; \
fi
install -m 644 packaging/$(PROJECT_NAME).service $(SYSTEMD_DIR)/$(PROJECT_NAME).service
systemctl daemon-reload
systemctl enable $(PROJECT_NAME)
systemctl restart $(PROJECT_NAME)
@echo "Installation complete. Service $(PROJECT_NAME) is running and enabled on boot."
uninstall:
@echo "Removing $(PROJECT_NAME)..."
-systemctl stop $(PROJECT_NAME) 2>/dev/null || true
-systemctl disable $(PROJECT_NAME) 2>/dev/null || true
rm -f $(SYSTEMD_DIR)/$(PROJECT_NAME).service
rm -f $(INSTALL_DIR)/$(PROJECT_NAME)
systemctl daemon-reload
@echo "Removal complete."
@echo "Configuration preserved in $(CONFIG_DIR)"
uninstall-full: uninstall
@echo "Removing configuration..."
rm -rf $(CONFIG_DIR)
@echo "Full removal complete."
install-service:
install -m 644 packaging/$(PROJECT_NAME).service $(SYSTEMD_DIR)/$(PROJECT_NAME).service
systemctl daemon-reload
systemctl enable $(PROJECT_NAME)
systemctl start $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) installed and started."
uninstall-service:
-systemctl stop $(PROJECT_NAME) 2>/dev/null || true
-systemctl disable $(PROJECT_NAME) 2>/dev/null || true
rm -f $(SYSTEMD_DIR)/$(PROJECT_NAME).service
systemctl daemon-reload
@echo "Service $(PROJECT_NAME) removed."
start:
systemctl start $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) started."
stop:
systemctl stop $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) stopped."
restart:
systemctl restart $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) restarted."
status:
systemctl status $(PROJECT_NAME)
enable:
systemctl enable $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) enabled on boot."
disable:
systemctl disable $(PROJECT_NAME)
@echo "Service $(PROJECT_NAME) disabled from boot."
release:
@test -n "$(VERSION)" || (echo "VERSION file is empty"; exit 1)
@echo "Releasing v$(VERSION)..."
git add -A
git commit -m "release v$(VERSION)" || true
git tag -f "v$(VERSION)"
git push
git push -f --tags
@echo "Released v$(VERSION)"
docker-build:
docker build -t $(DOCKER_IMAGE):$(VERSION) -t $(DOCKER_IMAGE):latest .
docker-push: docker-build
docker push $(DOCKER_IMAGE):$(VERSION)
docker push $(DOCKER_IMAGE):latest
docker-release: docker-push
@echo "Pushed $(DOCKER_IMAGE):$(VERSION) and :latest"