-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (116 loc) · 4.9 KB
/
Makefile
File metadata and controls
138 lines (116 loc) · 4.9 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
# configfilename Variables
ENV=local
CONFIG_FILENAME=default.${ENV}.yaml
.PHONY: help dev up down build test tests clean proto logs prepare migrate-up migrate-down sqlc install-tools restart restart-centrifugo
# Default target
help:
@echo "Usage: make <target>"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## ' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
dev: ## Start services and run the Go server locally (depends on `up` command)
serve: ## Run the Go server locally
up: ## Start all Docker services
up-postgres: ## Start only the postgres database services
down: ## Stop all Docker services
build: ## Build the Go binary
test: ## Run particular Go test
tests: ## Run all Go tests
clean: ## Remove build artifacts and stop services
proto: ## Generate protobuf and gRPC code
logs: ## Tail logs from all services
prepare: ## Create necessary directories for volumes
migrate-up: ## Run database migrations up
migrate-down: ## Rollback database migrations
sqlc: ## Generate sqlc types and queries
restart: ## Restart all Docker services
restart-centrifugo: ## Restart only the Centrifugo service
# Development commands
dev: up serve
serve:
@echo "Starting server..."
@go run cmd/server/main.go --config="default.yaml" --env=$(ENV)
up:
@echo "Building local binary..."
@make build
@echo "Building backend docker image..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml build backend
@echo "Starting services..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml up -d
up-postgres:
@echo "Starting database services..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml up -d postgres
rebuild:
@echo "Rebuilding services..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml build --no-cache
@docker-compose --env-file docker.env -f docker-compose.dev.yml up -d
down:
@echo "Stopping services..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml down
restart:
@echo "Restarting all services..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml restart
restart-centrifugo:
@echo "Restarting Centrifugo service..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml restart centrifugo
build:
@echo "Building service..."
@go mod tidy
@go build -o bin/voidkitgo cmd/server/main.go
test:
@echo "Running tests with debug output..."
@TEST_ENV_VARIABLE=true \
go test -v -count=1 ./tests/... -run $(TEST)
tests:
@echo "Running tests..."
@go test -v -count=1 ./... | grep -v "no test files"
clean:
@echo "Cleaning up..."
@rm -rf bin
@make down
proto:
@echo "Generating protobuf code..."
@protoc -I. \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
pkg/proto/**/*.proto \
internal/infrastructure/websocket/centrifugo/proto/*.proto
logs:
@echo "Showing logs..."
@docker-compose --env-file docker.env -f docker-compose.dev.yml logs -f
# Database commands
migrate-up:
@echo "Running database migrations up..."
@echo "Reading database configuration..."
@DB_USER=$$(yq e '.database.user' $(CONFIG_FILENAME)) && \
DB_PASSWORD=$$(yq e '.database.password' $(CONFIG_FILENAME)) && \
DB_HOST=$$(yq e '.database.host' $(CONFIG_FILENAME)) && \
DB_PORT=$$(yq e '.database.port' $(CONFIG_FILENAME)) && \
DB_NAME=$$(yq e '.database.dbname' $(CONFIG_FILENAME)) && \
echo "Running migrations up... $$DB_USER:$$DB_PASSWORD@$$DB_HOST:$$DB_PORT/$$DB_NAME" && \
migrate -path internal/infrastructure/persistence/postgres/migrations -database "postgresql://$$DB_USER:$$DB_PASSWORD@$$DB_HOST:$$DB_PORT/$$DB_NAME?sslmode=disable" up
migrate-down:
@echo "Rolling back database migrations..."
@echo "Reading database configuration..."
@DB_USER=$$(yq e '.database.user' $(CONFIG_FILENAME)) && \
DB_PASSWORD=$$(yq e '.database.password' $(CONFIG_FILENAME)) && \
DB_HOST=$$(yq e '.database.host' $(CONFIG_FILENAME)) && \
DB_PORT=$$(yq e '.database.port' $(CONFIG_FILENAME)) && \
DB_NAME=$$(yq e '.database.dbname' $(CONFIG_FILENAME)) && \
migrate -path internal/infrastructure/persistence/postgres/migrations -database "postgresql://$$DB_USER:$$DB_PASSWORD@$$DB_HOST:$$DB_PORT/$$DB_NAME?sslmode=disable" down
sqlc:
@echo "Generating sqlc types and queries..."
@cd internal/infrastructure/persistence/postgres && sqlc generate
swagger:
@echo "Generating swagger documentation..."
@swag init -g cmd/server/main.go -o ./_apidocs
# Tool installation
install-tools: ## Install all required development tools
@echo "Installing required tools..."
@go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
@go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
@go install github.com/mikefarah/yq/v4@latest
@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/swaggo/swag/cmd/swag@latest
@echo "Tools installed successfully!"