-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
216 lines (187 loc) · 6.74 KB
/
Makefile
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
APP_NAME := place.api
PUBLISH_OUTPUT := publish
COMPOSE_DB_FILE := docker/compose/databases/database-compose.yml
DOCKER_REPO := ossplacegenjiru
SOLUTION := Place.sln
API_PROJECT := src/Place.API/Place.API.csproj
ARCH := $(shell uname -m)
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
ifeq ($(ARCH),arm64)
RUNTIME := osx-arm64
DOCKER_ARCH := arm64
PLATFORM := linux/arm64
else
RUNTIME := osx-x64
DOCKER_ARCH := x64
PLATFORM := linux/amd64
endif
else
ifeq ($(ARCH),x86_64)
RUNTIME := linux-x64
DOCKER_ARCH := x64
PLATFORM := linux/amd64
else ifeq ($(ARCH),aarch64)
RUNTIME := linux-arm64
DOCKER_ARCH := arm64
PLATFORM := linux/amr64
else
RUNTIME := linux-x64
DOCKER_ARCH := x64
PLATFORM := linux/amd64
endif
endif
GREEN := \033[0;32m
RED := \033[0;31m
YELLOW := \033[0;33m
BLUE := \033[0;34m
NC := \033[0m
help:
@echo "Usage:"
@echo ""
@echo "Development Database Commands:"
@echo " make db-up - Start development databases"
@echo " make db-down - Stop databases"
@echo " make db-restart - Restart databases"
@echo " make db-logs - Display database logs"
@echo " make db-clean - Remove volumes and restart databases"
@echo ""
@echo "Build Commands:"
@echo " make restore - Restore NuGet packages"
@echo " make build - Build solution"
@echo " make test - Run all tests"
@echo " make test-unit - Run unit tests"
@echo " make test-integration - Run integration tests"
@echo " make publish - Publish application"
@echo " make docker - Build Docker image"
@echo " make all - Execute restore, build, test, and docker"
@echo " make clean - Clean build files"
@echo " make dev - Quick build without tests"
@echo ""
@echo "Full Development Setup:"
@echo " make dev-env - Setup complete dev environment (DBs + build)"
@echo " make dev-start - Start dev environment"
@echo " make dev-stop - Stop dev environment"
@echo ""
@echo "Options:"
@echo " RUNTIME=xxx - Specify runtime (linux-musl-x64, linux-musl-arm64)"
@echo ""
@echo "Detected architecture: $(ARCH)"
@echo "Default runtime: $(RUNTIME)"
# Database commands
db-up:
@echo "$(BLUE)🚀 Starting databases...$(NC)"
docker-compose -f $(COMPOSE_DB_FILE) up -d
@echo "$(GREEN)✅ Databases started$(NC)"
db-down:
@echo "$(BLUE)🛑 Stopping databases...$(NC)"
docker-compose -f $(COMPOSE_DB_FILE) down
@echo "$(GREEN)✅ Databases stopped$(NC)"
db-restart: db-down db-up
@echo "$(GREEN)✅ Databases restarted$(NC)"
db-logs:
@echo "$(BLUE)📋 Database logs:$(NC)"
docker-compose -f $(COMPOSE_DB_FILE) logs -f
db-clean:
@echo "$(BLUE)🧹 Complete database cleanup...$(NC)"
docker-compose -f $(COMPOSE_DB_FILE) down -v
@echo "$(YELLOW)🚀 Restarting clean databases...$(NC)"
docker-compose -f $(COMPOSE_DB_FILE) up -d
@echo "$(GREEN)✅ Databases reset$(NC)"
clean:
@echo "$(YELLOW)📦 Clean the solution...$(NC)"
dotnet clean
@echo "$(GREEN)✅ Solution cleaned$(NC)"
restore: clean
@echo "$(YELLOW)📦 Restoring NuGet packages...$(NC)"
@echo "$(BLUE)🔄 Restoring runtime-specific dependencies for $(RUNTIME)...$(NC)"
dotnet restore $(SOLUTION) -r $(RUNTIME)
@echo "$(GREEN)✅ Restore completed$(NC)"
build: restore
@echo "$(YELLOW)🔨 Building solution...$(NC)"
dotnet build $(SOLUTION) -c Release --no-restore
@echo "$(GREEN)✅ Build completed$(NC)"
test-unit: build
@echo "$(YELLOW)🧪 Running unit tests...$(NC)"
@dotnet test $(SOLUTION) \
--configuration Release \
--no-build \
--filter "Category=Unit" \
--verbosity minimal \
--logger "trx;LogFileName=unit_tests.trx" && \
echo "$(GREEN)✅ Unit tests completed$(NC)" || \
(echo "$(RED)❌ Unit tests failed$(NC)" && exit 1)
test-integration: build
@echo "$(YELLOW)🧪 Running integration tests...$(NC)"
@dotnet test $(SOLUTION) \
--configuration Release \
--no-build \
--filter "Category=Integration" \
--verbosity minimal \
--logger "trx;LogFileName=integration_tests.trx" && \
echo "$(GREEN)✅ Integration tests completed$(NC)" || \
(echo "$(RED)❌ Integration tests failed$(NC)" && exit 1)
test: build
@echo "$(YELLOW)🧪 Running all tests...$(NC)"
@dotnet test $(SOLUTION) \
--configuration Release \
--no-build \
--verbosity minimal \
--logger "trx;LogFileName=all_tests.trx" && \
echo "$(GREEN)✅ All tests completed$(NC)" || \
(echo "$(RED)❌ Tests failed$(NC)" && exit 1)
# Function to run specific test project
test-project:
@if [ -z "$(PROJECT)" ]; then \
echo "$(RED)❌ Please specify a project with PROJECT=path/to/test/project.csproj$(NC)"; \
exit 1; \
fi
@echo "$(YELLOW)🧪 Running tests for $(PROJECT)...$(NC)"
@dotnet test $(PROJECT) \
--configuration Release \
--verbosity normal \
--logger "console;verbosity=detailed" && \
echo "$(GREEN)✅ Project tests completed$(NC)" || \
(echo "$(RED)❌ Project tests failed$(NC)" && exit 1)
# Debug test command
test-debug:
@echo "$(YELLOW)🔍 Running tests with verbose output...$(NC)"
@dotnet test $(SOLUTION) \
--configuration Release \
--verbosity detailed \
--logger "console;verbosity=detailed" && \
echo "$(GREEN)✅ Debug tests completed$(NC)" || \
(echo "$(RED)❌ Debug tests failed$(NC)" && exit 1)
publish: build
@echo "$(YELLOW)📦 Publishing $(APP_NAME) for $(RUNTIME)...$(NC)"
@echo "$(BLUE)🚀 Building single file application...$(NC)"
dotnet publish $(API_PROJECT) \
-c Release \
-o $(PUBLISH_OUTPUT)/$(RUNTIME) \
--runtime $(RUNTIME) \
--self-contained true
@echo "$(GREEN)✅ Publish completed$(NC)"
docker:
@echo "$(YELLOW)🐳 Building Docker image for $(RUNTIME)...$(NC)"
docker build -f Dockerfile \
--platform="$(PLATFORM)" \
-t $(DOCKER_REPO):$(VERSION)-$(DOCKER_ARCH) .
@echo "$(GREEN)✅ Docker build completed$(NC)"
@echo "Tagged as: $(DOCKER_REPO):$(VERSION)-$(DOCKER_ARCH)"
dev-env: db-up restore build
@echo "$(GREEN)✅ Development environment ready$(NC)"
dev-start: db-up
@echo "$(GREEN)✅ Development environment started$(NC)"
dev-stop: db-down
@echo "$(GREEN)✅ Development environment stopped$(NC)"
clean:
@echo "$(YELLOW)🧹 Cleaning...$(NC)"
dotnet clean $(SOLUTION)
rm -rf $(PUBLISH_OUTPUT)
@echo "$(GREEN)✅ Clean completed$(NC)"
all: restore build test publish docker
@echo "$(GREEN)✅ All tasks completed successfully$(NC)"
dev: restore build publish docker
@echo "$(GREEN)✅ Dev build completed$(NC)"
.PHONY: help restore build test test-unit test-integration publish docker clean all dev \
db-up db-down db-restart db-logs db-clean dev-env dev-start dev-stop