-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (74 loc) · 3.02 KB
/
Copy pathMakefile
File metadata and controls
92 lines (74 loc) · 3.02 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
.PHONY: all build run dev clean test test-unit test-integration migrate-up migrate-down sqlc docker-build docker-run docker-dev docker-stop
# Go variables
BINARY_NAME=app
GO_FILES=$(shell find . -name '*.go' -not -path "./vendor/*")
# Default target
all: build
# Build the Go application
build:
@echo "Building $(BINARY_NAME)..."
@go build -o $(BINARY_NAME) ./cmd/server/main.go
# Run the compiled application
run: build
@echo "Running $(BINARY_NAME)..."
@./$(BINARY_NAME)
# Run the application with air for hot-reloading (development)
dev:
@echo "Starting dev server with air..."
@air
# Clean build artifacts
clean:
@echo "Cleaning..."
@go clean
@rm -f $(BINARY_NAME)
# Run all tests
test: test-unit test-integration
# Run unit tests
test-unit:
@echo "Running unit tests..."
@go test -v ./... -tags=unit -coverprofile=coverage-unit.out
# Run integration tests
test-integration:
@echo "Running integration tests..."
@go test -v ./... -tags=integration -coverprofile=coverage-integration.out
migrate-up:
@echo "Applying database migrations (via Docker)..."
@docker compose -f $(DOCKER_COMPOSE_FILE) exec app migrate -path /app/db/migration -database "$DB_URL" -verbose up
migrate-down:
@echo "Rolling back last database migration (via Docker)..."
@docker compose -f $(DOCKER_COMPOSE_FILE) exec app migrate -path /app/db/migration -database "$DB_URL" -verbose down 1
sqlc:
@echo "Generating SQLC code (via Docker)..."
@docker compose -f $(DOCKER_COMPOSE_FILE) exec app sqlc generate --path /app/sqlc.yaml
# Docker commands
DOCKER_COMPOSE_FILE=compose.yml:compose.dev.yml
DOCKER_IMAGE_NAME=cache-query-aggregator # Change this to your desired image name
docker-build:
@echo "Building Docker image..."
@docker compose -f $(DOCKER_COMPOSE_FILE) build
docker-run:
@echo "Running Docker containers..."
@docker compose -f $(DOCKER_COMPOSE_FILE) up -d
docker-dev:
@echo "Running Docker containers for development (with hot-reloading)..."
@docker compose -f $(DOCKER_COMPOSE_FILE) up --build app
docker-stop:
@echo "Stopping Docker containers..."
@docker compose -f $(DOCKER_COMPOSE_FILE) down
help:
@echo "Available targets:"
@echo " all - Build the application (default)"
@echo " build - Build the Go application"
@echo " run - Run the compiled application"
@echo " dev - Run the application with air for hot-reloading"
@echo " clean - Clean build artifacts"
@echo " test - Run all tests"
@echo " test-unit - Run unit tests"
@echo " test-integration - Run integration tests"
@echo " migrate-up - Apply all database migrations"
@echo " migrate-down - Rollback all database migrations"
@echo " sqlc - Generate SQLC code"
@echo " docker-build - Build Docker image using docker-compose"
@echo " docker-run - Run Docker containers in detached mode"
@echo " docker-dev - Run Docker containers for development with hot-reloading"
@echo " docker-stop - Stop Docker containers"