-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
214 lines (177 loc) · 6.92 KB
/
Makefile
File metadata and controls
214 lines (177 loc) · 6.92 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
210
211
212
213
214
# PodSweeper Makefile
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
# Binary names
GAMEMASTER_BINARY=gamemaster
HINT_AGENT_BINARY=hint-agent
# Build directories
BUILD_DIR=bin
CMD_DIR=cmd
# Container runtime: auto-detect podman or docker
CONTAINER_RUNTIME?=$(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
REGISTRY?=ghcr.io/zwindler
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
# Kubernetes parameters
NAMESPACE=podsweeper-game
.PHONY: all build build-gamemaster build-hint-agent test test-coverage clean run run-gamemaster fmt vet lint deps tidy docker-build docker-push deploy undeploy help play install-hooks
## Default target
all: fmt vet test build
## Build all binaries
build: build-gamemaster build-hint-agent
## Build the gamemaster binary
build-gamemaster:
@echo "Building gamemaster..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(GAMEMASTER_BINARY) -v ./$(CMD_DIR)/gamemaster
## Build the hint-agent binary
build-hint-agent:
@echo "Building hint-agent..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(HINT_AGENT_BINARY) -v ./$(CMD_DIR)/hint-agent
## Run all tests
test:
@echo "Running tests..."
$(GOTEST) -v -race ./...
## Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
## Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR)
@rm -f coverage.out coverage.html
## Run the gamemaster locally (requires kubeconfig)
run: run-gamemaster
## Run the gamemaster
run-gamemaster: build-gamemaster
@echo "Running gamemaster..."
./$(BUILD_DIR)/$(GAMEMASTER_BINARY)
## Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
## Run go vet
vet:
@echo "Running go vet..."
$(GOCMD) vet ./...
## Run golangci-lint (must be installed separately)
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Run: brew install golangci-lint" && exit 1)
golangci-lint run ./...
## Install git pre-commit hooks
install-hooks:
@echo "Installing git hooks..."
@cp scripts/pre-commit .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "Pre-commit hook installed!"
## Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOGET) -v -t -d ./...
## Tidy go.mod
tidy:
@echo "Tidying go.mod..."
$(GOMOD) tidy
## Build Docker images
docker-build: docker-build-gamemaster docker-build-hint-agent docker-build-player-terminal
## Build gamemaster Docker image
docker-build-gamemaster:
@echo "Building gamemaster Docker image..."
$(CONTAINER_RUNTIME) build -t $(REGISTRY)/podsweeper-gamemaster:$(VERSION) -f build/gamemaster/Dockerfile --build-arg VERSION=$(VERSION) .
## Build hint-agent Docker image
docker-build-hint-agent:
@echo "Building hint-agent Docker image..."
$(CONTAINER_RUNTIME) build -t $(REGISTRY)/podsweeper-hint-agent:$(VERSION) -f build/hint-agent/Dockerfile --build-arg VERSION=$(VERSION) .
## Build player-terminal Docker image
docker-build-player-terminal:
@echo "Building player-terminal Docker image..."
$(CONTAINER_RUNTIME) build -t $(REGISTRY)/podsweeper-player-terminal:$(VERSION) -f build/player-terminal/Dockerfile build/player-terminal
## Push Docker images
docker-push: docker-push-gamemaster docker-push-hint-agent docker-push-player-terminal
## Push gamemaster Docker image
docker-push-gamemaster:
@echo "Pushing gamemaster Docker image..."
$(CONTAINER_RUNTIME) push $(REGISTRY)/podsweeper-gamemaster:$(VERSION)
## Push hint-agent Docker image
docker-push-hint-agent:
@echo "Pushing hint-agent Docker image..."
$(CONTAINER_RUNTIME) push $(REGISTRY)/podsweeper-hint-agent:$(VERSION)
## Push player-terminal Docker image
docker-push-player-terminal:
@echo "Pushing player-terminal Docker image..."
$(CONTAINER_RUNTIME) push $(REGISTRY)/podsweeper-player-terminal:$(VERSION)
## Generate code (for future CRDs if needed)
generate:
@echo "Running code generation..."
$(GOCMD) generate ./...
## Deploy to Kubernetes cluster
deploy:
@echo "Deploying PodSweeper..."
kubectl apply -k deploy/base
## Remove PodSweeper from cluster
undeploy:
@echo "Removing PodSweeper..."
kubectl delete -k deploy/base --ignore-not-found
## Start a game (creates ConfigMap with action=start)
start-game:
@echo "Starting game at level 0..."
kubectl patch configmap podsweeper-config -n $(NAMESPACE) --type merge -p '{"data":{"level":"0","action":"start"}}'
## Start a game at a specific level (use: make start-level LEVEL=3)
start-level:
@echo "Starting game at level $(LEVEL)..."
kubectl patch configmap podsweeper-config -n $(NAMESPACE) --type merge -p '{"data":{"level":"$(LEVEL)","action":"start"}}'
## Show game status
game-status:
@kubectl get configmap podsweeper-config -n $(NAMESPACE) -o yaml | grep -E "^ (level|status|message|progress|gridSize|mines):"
## Join the game as a player (exec into player terminal)
play:
@echo "Joining PodSweeper as player..."
@kubectl get pod player -n $(NAMESPACE) > /dev/null 2>&1 || (echo "Player terminal not running. Deploying..." && kubectl apply -f deploy/base/player-terminal.yaml)
@kubectl wait --for=condition=Ready pod/player -n $(NAMESPACE) --timeout=30s 2>/dev/null || true
@kubectl exec -it player -n $(NAMESPACE) -- bash
## Show help
help:
@echo "PodSweeper - The most impractical way to play Minesweeper"
@echo ""
@echo "Usage:"
@echo " make <target>"
@echo ""
@echo "Build Targets:"
@echo " all Format, vet, test, and build (default)"
@echo " build Build all binaries"
@echo " build-gamemaster Build the gamemaster binary"
@echo " build-hint-agent Build the hint-agent binary"
@echo " test Run all tests"
@echo " test-coverage Run tests with coverage report"
@echo " clean Remove build artifacts"
@echo " fmt Format Go code"
@echo " vet Run go vet"
@echo " lint Run golangci-lint"
@echo " install-hooks Install git pre-commit hooks"
@echo ""
@echo "Docker Targets:"
@echo " docker-build Build all Docker images"
@echo " docker-build-gamemaster Build gamemaster image"
@echo " docker-build-hint-agent Build hint-agent image"
@echo " docker-build-player-terminal Build player terminal image"
@echo " docker-push Push all Docker images"
@echo ""
@echo "Kubernetes Targets:"
@echo " deploy Deploy to Kubernetes cluster"
@echo " undeploy Remove from cluster"
@echo " start-game Start a new game at level 0"
@echo " start-level Start at specific level (LEVEL=N)"
@echo " game-status Show current game status"
@echo " play Join the game (exec into player terminal)"
@echo ""
@echo "Quick Start:"
@echo " make deploy && make start-game && make play"