-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
249 lines (205 loc) · 7.41 KB
/
Makefile
File metadata and controls
249 lines (205 loc) · 7.41 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# ================================
# Notifier Service Makefile
# ================================
.PHONY: all build run test clean proto migrate migrate-up migrate-down migrate-down-all migrate-create migrate-status migrate-version migrate-force docker-build docker-up docker-down docker-logs docker-logs-dev
# Variables
APP_NAME=notifier
BINARY=bin/$(APP_NAME)
MIGRATE_BINARY=bin/migrate
GO=go
DOCKER_COMPOSE=docker compose
# ================================
# Proto Commands
# ================================
.PHONY: proto proto-buf proto-protoc proto-install proto-clean
proto:
@echo "Generating protobuf files from notifier service..."
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/notifier/v1/notifier.proto
@echo "Copying generated files to go-sdk..."
@if [ -d "../go-sdk/notifier/proto/notifier/v1" ]; then \
cp proto/notifier/v1/*.pb.go ../go-sdk/notifier/proto/notifier/v1/; \
echo "Proto files copied to go-sdk successfully"; \
fi
# Generate protobuf files with buf (recommended)
proto-buf:
@echo "Generating protobuf files with buf..."
cd proto && buf generate
# Generate protobuf files with protoc (alternative)
proto-protoc:
@echo "Generating protobuf files with protoc..."
@if ! command -v protoc >/dev/null 2>&1; then \
echo "Error: protoc is not installed. Run 'make proto-install' first."; \
exit 1; \
fi
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/notifier/v1/notifier.proto
# Install protobuf tools
proto-install:
@echo "Installing protobuf tools..."
$(GO) install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$(GO) install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
$(GO) install github.com/bufbuild/buf/cmd/buf@latest
@echo "✓ Protobuf tools installed"
@echo "Note: You may also need to install protoc separately:"
@echo " - macOS: brew install protobuf"
@echo " - Linux: apt-get install protobuf-compiler"
@echo " - Windows: choco install protoc or download from https://github.com/protocolbuffers/protobuf/releases"
# Clean generated protobuf files
proto-clean:
@echo "Cleaning generated protobuf files..."
find proto -name "*.pb.go" -type f -delete
@echo "✓ Cleaned"
# ================================
# Build Commands
# ================================
all: build
build:
@echo "Building $(APP_NAME)..."
$(GO) build -o $(BINARY) ./cmd/server
build-migrate:
@echo "Building migration tool..."
$(GO) build -o $(MIGRATE_BINARY) ./cmd/migrate/main.go
run: build
@echo "Running $(APP_NAME)..."
./$(BINARY)
clean:
rm -rf bin/
rm -f proto/**/*.pb.go
# ================================
# Test Commands
# ================================
test:
$(GO) test -v ./...
test-coverage:
$(GO) test -v -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
lint:
golangci-lint run
# ================================
# Migration Commands
# ================================
# Apply all pending migrations
migrate: migrate-up
migrate-up: build-migrate
@echo "Applying migrations..."
./$(MIGRATE_BINARY) up
# Rollback last migration
migrate-down: build-migrate
@echo "Rolling back last migration..."
./$(MIGRATE_BINARY) down 1
# Rollback all migrations
migrate-down-all: build-migrate
@echo "Rolling back all migrations..."
./$(MIGRATE_BINARY) down $(shell ls -1 migrations/*.up.sql 2>/dev/null | wc -l)
# Show migration status
migrate-status: build-migrate
@echo "Migration status..."
./$(MIGRATE_BINARY) status
# Show current version
migrate-version: build-migrate
./$(MIGRATE_BINARY) version
# Create new migration
# Usage: make migrate-create name=add_webhooks
migrate-create: build-migrate
@if [ -z "$(name)" ]; then \
echo "Error: Please provide migration name: make migrate-create name=your_migration_name"; \
exit 1; \
fi
./$(MIGRATE_BINARY) create $(name)
# Force migration version (for fixing dirty state)
# Usage: make migrate-force version=1
migrate-force: build-migrate
@if [ -z "$(version)" ]; then \
echo "Error: Please provide version: make migrate-force version=1"; \
exit 1; \
fi
./$(MIGRATE_BINARY) force $(version)
# ================================
# Docker Commands
# ================================
docker-build:
docker build -t $(APP_NAME):latest .
docker-up:
$(DOCKER_COMPOSE) up -d
docker-up-dev:
$(DOCKER_COMPOSE) -f docker-compose.dev.yml up -d
docker-down:
$(DOCKER_COMPOSE) down
docker-down-dev:
$(DOCKER_COMPOSE) -f docker-compose.dev.yml down
docker-logs:
$(DOCKER_COMPOSE) logs -f $(APP_NAME)
docker-logs-dev:
$(DOCKER_COMPOSE) -f docker-compose.dev.yml logs -f $(APP_NAME)
# ================================
# Database Commands (Docker)
# ================================
db-shell:
docker exec -it notifier_postgres psql -U notifier_user -d notifier_db
db-shell-dev:
docker exec -it notifier_postgres_dev psql -U notifier_user -d notifier_db
# ================================
# Development Commands
# ================================
dev:
@echo "Starting development mode with hot reload..."
@air 2>/dev/null || $(GO) run ./cmd/server
# Install development tools
tools:
$(GO) install github.com/cosmtrek/air@latest
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GO) install github.com/golang-migrate/migrate/v4/cmd/migrate@latest
fmt:
$(GO) fmt ./...
# ================================
# Help
# ================================
help:
@echo "Notifier Service Makefile Commands"
@echo ""
@echo "Proto:"
@echo " make proto - Generate protobuf files (default method)"
@echo " make proto-buf - Generate protobuf files with buf"
@echo " make proto-protoc - Generate protobuf files with protoc"
@echo " make proto-install - Install protobuf generation tools"
@echo " make proto-clean - Remove generated protobuf files"
@echo ""
@echo "Build:"
@echo " make build - Build the application"
@echo " make run - Build and run the application"
@echo " make clean - Clean build artifacts"
@echo ""
@echo "Test:"
@echo " make test - Run tests"
@echo " make test-coverage - Run tests with coverage"
@echo " make lint - Run linter"
@echo ""
@echo "Migrations:"
@echo " make migrate-up - Apply all pending migrations"
@echo " make migrate-down - Rollback last migration"
@echo " make migrate-down-all - Rollback all migrations"
@echo " make migrate-status - Show migration status"
@echo " make migrate-version - Show current migration version"
@echo " make migrate-create name=<name> - Create new migration"
@echo " make migrate-force version=<n> - Force migration version"
@echo ""
@echo "Docker:"
@echo " make docker-build - Build Docker image"
@echo " make docker-up - Start with docker-compose"
@echo " make docker-up-dev - Start development environment"
@echo " make docker-down - Stop containers"
@echo " make docker-down-dev - Stop development containers"
@echo " make docker-logs - Show container logs"
@echo " make docker-logs-dev - Show development container logs"
@echo ""
@echo "Database:"
@echo " make db-shell - Connect to database shell"
@echo " make db-shell-dev - Connect to development database shell"
@echo ""
@echo "Development:"
@echo " make dev - Run with hot reload if air is available, otherwise run directly"
@echo " make tools - Install development tools"
@echo " make fmt - Format Go code"