-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (118 loc) · 4.47 KB
/
Makefile
File metadata and controls
134 lines (118 loc) · 4.47 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
# Makefile for Latitude.sh Agent
# Variables
BINARY_NAME=lsh-agent
BINARY_PATH=./cmd/agent
BUILD_DIR=./build
VERSION ?= 1.0.0
LDFLAGS=-ldflags "-X main.Version=$(VERSION)"
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Default target
.DEFAULT_GOAL := build
# Build the binary
.PHONY: build
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(BINARY_PATH)
# Build for Linux (common deployment target)
.PHONY: build-linux
build-linux:
@echo "Building $(BINARY_NAME) for Linux..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(BINARY_PATH)
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
# Download dependencies
.PHONY: deps
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Run tests
.PHONY: test
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Check configuration syntax
.PHONY: check-config
check-config: build
@echo "Checking configuration..."
$(BUILD_DIR)/$(BINARY_NAME) -check-config -config configs/agent.yaml
# Install the binary to /usr/local/bin
.PHONY: install
install: build
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
sudo cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
sudo chmod +x /usr/local/bin/$(BINARY_NAME)
# Uninstall the binary
.PHONY: uninstall
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
sudo rm -f /usr/local/bin/$(BINARY_NAME)
# Create systemd service (development helper)
.PHONY: create-service
create-service:
@echo "Creating systemd service..."
@echo '[Unit]' | sudo tee /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'Description=Latitude.sh Agent (Go)' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'After=network.target' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'Wants=network.target' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo '' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo '[Service]' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'Type=simple' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'ExecStart=/usr/local/bin/$(BINARY_NAME) -config /etc/lsh-agent/config.yaml' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'Restart=always' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'RestartSec=10' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'User=root' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'Environment=LATITUDESH_AUTH_TOKEN=""' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo '' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo '[Install]' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@echo 'WantedBy=multi-user.target' | sudo tee -a /etc/systemd/system/lsh-agent-go.service > /dev/null
@sudo systemctl daemon-reload
@echo "Service created. Configure environment variables and enable with:"
@echo " sudo systemctl enable lsh-agent-go"
@echo " sudo systemctl start lsh-agent-go"
# Remove systemd service
.PHONY: remove-service
remove-service:
@echo "Removing systemd service..."
-sudo systemctl stop lsh-agent-go
-sudo systemctl disable lsh-agent-go
sudo rm -f /etc/systemd/system/lsh-agent-go.service
sudo systemctl daemon-reload
# Show version
.PHONY: version
version:
@echo "Version: $(VERSION)"
# Development: build and run with sample config
.PHONY: dev-run
dev-run: build
@echo "Running agent in development mode..."
$(BUILD_DIR)/$(BINARY_NAME) -config configs/agent.yaml
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build the binary"
@echo " build-linux - Build for Linux x86_64"
@echo " clean - Clean build artifacts"
@echo " deps - Download and tidy dependencies"
@echo " test - Run tests"
@echo " check-config - Validate configuration file"
@echo " install - Install binary to /usr/local/bin"
@echo " uninstall - Remove binary from /usr/local/bin"
@echo " create-service - Create systemd service"
@echo " remove-service - Remove systemd service"
@echo " dev-run - Build and run with sample config"
@echo " version - Show version"
@echo " help - Show this help"