-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (113 loc) · 3.54 KB
/
Copy pathMakefile
File metadata and controls
137 lines (113 loc) · 3.54 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
.PHONY: build build-server build-client build-agent test clean install plugins \
docker-build docker-build-server docker-build-agent docker-build-client \
docker-push docker-up docker-down docker-logs
# Build variables
BINARY_NAME=orion-belt
BUILD_DIR=bin
PLUGIN_DIR=plugins
BUILD_DIR_PLUGINS=bin/plugins
PLUGINS := audit-logger notification
GO=go
GOFLAGS=-v
# Docker variables
DOCKER_REGISTRY ?=
DOCKER_IMAGE ?= orion-belt
DOCKER_TAG ?= latest
DOCKER_DIR=docker
DOCKERFILE=$(DOCKER_DIR)/Dockerfile
DOCKERFILE_AGENT=$(DOCKER_DIR)/Dockerfile.agent
# Helper to prefix image name with registry if set
ifdef DOCKER_REGISTRY
IMAGE_PREFIX=$(DOCKER_REGISTRY)/$(DOCKER_IMAGE)
else
IMAGE_PREFIX=$(DOCKER_IMAGE)
endif
# Build all components
build: build-server build-client build-admin build-agent
# Build server
build-server:
@echo "Building server..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-server ./cmd/server
# Build client
build-client:
@echo "Building client..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/osh ./cmd/osh
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/ocp ./cmd/ocp
# Build admin
build-admin:
@echo "Building admin..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/oadmin ./cmd/oadmin
# Build agent
build-agent:
@echo "Building agent..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-agent ./cmd/agent
# Run tests
test:
$(GO) test -v ./...
# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR)
@rm -f coverage.out
# Install binaries to $GOPATH/bin
install: build
@echo "Installing..."
@cp $(BUILD_DIR)/$(BINARY_NAME)-server $(GOPATH)/bin/
@cp $(BUILD_DIR)/$(BINARY_NAME)-agent $(GOPATH)/bin/
@cp $(BUILD_DIR)/osh $(GOPATH)/bin/
@cp $(BUILD_DIR)/ocp $(GOPATH)/bin/
# Run server
run-server: build-server
$(BUILD_DIR)/$(BINARY_NAME)-server
# Run tests with coverage
test-coverage:
$(GO) test -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out
# Format code
fmt:
$(GO) fmt ./...
# Lint code
lint:
golangci-lint run
# Download dependencies
deps:
$(GO) mod download
$(GO) mod verify
# Update dependencies
update-deps:
$(GO) get -u ./...
$(GO) mod tidy
# plugins section
plugins: $(BUILD_DIR_PLUGINS)
@echo "Building plugins..."
@for plugin in $(PLUGINS); do \
echo "Building $$plugin.so..."; \
$(GO) build -buildmode=plugin -o $(BUILD_DIR_PLUGINS)/$$plugin.so $(PLUGIN_DIR)/$$plugin/main.go || exit 1; \
done
@echo "Plugins built successfully"
$(BUILD_DIR_PLUGINS):
@mkdir -p $(BUILD_DIR_PLUGINS)
# ────────────────────────────────────────────────────────────
# Docker targets
# ────────────────────────────────────────────────────────────
# Build server image
docker-build-server:
@echo "Building server image: $(IMAGE_PREFIX)-server:$(DOCKER_TAG)..."
docker build \
--file $(DOCKERFILE) \
--tag $(IMAGE_PREFIX)-server:$(DOCKER_TAG) \
.
# Start the full stack via Docker Compose
docker-up:
docker compose -f $(DOCKER_DIR)/docker-compose.yml up -d
@echo "Stack is up. Server SSH: localhost:2222 API: localhost:8080"
# Stop the stack
docker-down:
docker compose -f $(DOCKER_DIR)/docker-compose.yml down
# Tail logs (optionally filter: make docker-logs SERVICE=server)
docker-logs:
docker compose -f $(DOCKER_DIR)/docker-compose.yml logs -f $(SERVICE)