-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
171 lines (132 loc) · 4.3 KB
/
Copy pathMakefile
File metadata and controls
171 lines (132 loc) · 4.3 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
.PHONY: build run dev clean test docker docker-push frontend all migrate
BINARY=nowen-reader
MIGRATE_BINARY=nowen-migrate
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
LDFLAGS=-ldflags "-s -w \
-X main.Version=$(VERSION) \
-X main.BuildTime=$(BUILD_TIME) \
-X main.GitCommit=$(GIT_COMMIT)"
# ============================================================
# Build targets
# ============================================================
all: build
build:
go build $(LDFLAGS) -o $(BINARY).exe ./cmd/server
build-linux:
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY)-linux-amd64 ./cmd/server
build-arm64:
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BINARY)-linux-arm64 ./cmd/server
build-all: build build-linux build-arm64
# Static build (CGO_ENABLED=0, for Docker and standalone deployment)
build-static:
CGO_ENABLED=0 go build $(LDFLAGS) -o $(BINARY) ./cmd/server
# ============================================================
# Run targets
# ============================================================
run: build
./$(BINARY).exe
dev:
go run ./cmd/server
# Dev mode with frontend directory (for development with separate frontend)
dev-with-frontend:
FRONTEND_DIR=./frontend/dist go run ./cmd/server
# ============================================================
# Frontend targets
# ============================================================
frontend:
@if [ -d "frontend" ]; then \
cd frontend && npm install && npm run build; \
rm -rf web/dist/*; \
cp -r frontend/dist/* web/dist/; \
echo "[OK] Frontend built and copied to web/dist/"; \
else \
echo "[SKIP] No frontend/ directory found"; \
fi
# Build with embedded frontend
build-full: frontend build
# ============================================================
# Docker targets
# ============================================================
docker:
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
-t $(BINARY):$(VERSION) \
-t $(BINARY):latest \
.
docker-push:
docker tag $(BINARY):latest cropflre/nowen-reader:latest
docker tag $(BINARY):$(VERSION) cropflre/nowen-reader:$(VERSION)
docker push cropflre/nowen-reader:latest
docker push cropflre/nowen-reader:$(VERSION)
# Multi-platform build (amd64 + arm64, requires docker buildx)
docker-multiarch:
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
-t cropflre/nowen-reader:$(VERSION) \
-t cropflre/nowen-reader:latest \
--push \
.
docker-up:
docker compose up -d
docker-down:
docker compose down
docker-logs:
docker compose logs -f
# ============================================================
# Quality targets
# ============================================================
clean:
rm -f $(BINARY) $(BINARY).exe $(BINARY)-linux-*
rm -f $(MIGRATE_BINARY) $(MIGRATE_BINARY).exe
rm -f coverage.out
go clean
test:
go test ./... -v -race
test-short:
go test ./... -short
test-cover:
go test ./... -race -coverprofile=coverage.out -covermode=atomic
go tool cover -func=coverage.out
@echo ""
@echo "To view HTML coverage report: go tool cover -html=coverage.out"
# ============================================================
# Migration tool
# ============================================================
migrate:
go build $(LDFLAGS) -o $(MIGRATE_BINARY) ./cmd/migrate
migrate-run: migrate
./$(MIGRATE_BINARY)
migrate-import: migrate
@if [ -z "$(FROM)" ]; then \
echo "Usage: make migrate-import FROM=/path/to/prisma/dev.db"; \
exit 1; \
fi
./$(MIGRATE_BINARY) -import $(FROM)
deps:
go mod tidy
go mod download
fmt:
go fmt ./...
goimports -w .
lint:
golangci-lint run ./...
vet:
go vet ./...
# ============================================================
# Info targets
# ============================================================
version:
@echo "Version: $(VERSION)"
@echo "Build Time: $(BUILD_TIME)"
@echo "Git Commit: $(GIT_COMMIT)"
info: version
@echo "Binary: $(BINARY)"
@echo "Go Version: $(shell go version)"
@echo "Platform: $(shell go env GOOS)/$(shell go env GOARCH)"