-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
284 lines (244 loc) · 8.63 KB
/
Taskfile.yml
File metadata and controls
284 lines (244 loc) · 8.63 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
version: '3'
vars:
# Cross-platform Maven wrapper command
MVN: '{{if eq OS "windows"}}mvnw.cmd{{else}}./mvnw{{end}}'
# Cross-platform Open command
OPEN: '{{if eq OS "windows"}}start{{else if eq OS "darwin"}}open{{else}}xdg-open{{end}}'
tasks:
default:
desc: List available commands
cmds:
- task --list
# Infrastructure Commands
init:
desc: Initialize project (copy .env, create directories)
cmds:
- task: copy-env
- cmd: "powershell -NoProfile -Command \"New-Item -ItemType Directory -Force -Path 'infrastructure/docker/prometheus','infrastructure/docker/grafana/dashboards','infrastructure/docker/grafana/datasources' | Out-Null\""
platforms: [windows]
ignore_error: true # Ignore if already exists
- cmd: mkdir -p infrastructure/docker/prometheus infrastructure/docker/grafana/dashboards infrastructure/docker/grafana/datasources
platforms: [linux, darwin]
ignore_error: true # Ignore if already exists
- echo "✅ Project initialized!"
copy-env:
internal: true
cmds:
- cmd: "powershell -NoProfile -Command \"if (Test-Path .env) { Write-Host '⚠️ .env already exists' } else { Copy-Item -Path .env.example -Destination .env -Force; Write-Host '✅ Created .env file' }\""
platforms: [windows]
- cmd: 'if [ -f .env ]; then echo "⚠️ .env already exists"; else cp .env.example .env; echo "✅ Created .env file"; fi'
platforms: [linux, darwin]
up:
desc: Start all Docker services
cmds:
- docker compose up -d
- echo "✅ Services started!"
- task: print-urls
down:
desc: Stop all Docker services
cmds:
- echo "🛑 Stopping all Docker services..."
- docker compose down
- echo "✅ Services stopped!"
restart:
desc: Restart all Docker services
cmds:
- task: down
- task: up
reload-docker:
desc: Reload Docker services (down + up, keeps volumes)
cmds:
- echo "🔄 Reloading Docker services..."
- docker compose down
- docker compose up -d
- echo "✅ Services reloaded!"
- task: print-urls
reload-docker-v:
desc: Reload Docker services with volume reset (down -v + up)
prompt: "⚠️ WARNING: This will delete all Docker volumes! Are you sure?"
cmds:
- echo "🔄 Reloading Docker services (with volume reset)..."
- docker compose down -v
- docker compose up -d
- echo "✅ Services reloaded with fresh volumes!"
- task: print-urls
logs:
desc: View logs from all services
cmds:
- docker compose logs -f
clean:
desc: Remove all Docker volumes and data
prompt: "⚠️ WARNING: This will delete all Docker volumes and data! Are you sure?"
cmds:
- docker compose down -v
- echo "✅ All data cleaned!"
# Services
gateway-run:
desc: Run API Gateway (Spring Cloud Gateway)
dir: api-gateway
cmds:
- '{{.MVN}} spring-boot:run'
backend-run:
desc: Run Backend (Modular Monolith)
dir: backend
cmds:
- '{{.MVN}} spring-boot:run'
bot-run:
desc: Run Telegram Bot
dir: telegram-bot
cmds:
- '{{.MVN}} spring-boot:run'
admin-run:
desc: Run Admin Panel (Angular)
dir: admin-panel
cmds:
- npm install
- ng serve --port 4200
store-run:
desc: Run Store Frontend (Next.js)
dir: store-frontend
cmds:
- npm install
- npm run dev
# Monitoring
monitoring:
desc: Open Grafana dashboards
cmds:
- '{{.OPEN}} http://localhost:3001'
tracing:
desc: Open Jaeger tracing UI
cmds:
- '{{.OPEN}} http://localhost:16686'
prometheus:
desc: Open Prometheus UI
cmds:
- '{{.OPEN}} http://localhost:9090'
keycloak-export:
desc: Export Keycloak realm config to infrastructure/keycloak/realm-export.json
cmds:
- echo "📦 Exporting Keycloak realm..."
- docker exec store-keycloak sh -c "rm -rf /tmp/keycloak-export && mkdir -p /tmp/keycloak-export"
- docker exec store-keycloak /opt/keycloak/bin/kc.sh export --optimized --realm online-store --users skip --dir /tmp/keycloak-export
- docker cp store-keycloak:/tmp/keycloak-export/online-store-realm.json infrastructure/keycloak/realm-export.json
- echo "✅ Realm exported to infrastructure/keycloak/realm-export.json"
# Database
db-migrate:
desc: Run database migrations
dir: backend
cmds:
- '{{.MVN}} flyway:migrate'
db-psql:
desc: Connect to PostgreSQL (primary)
interactive: true
cmds:
- docker exec -it store-postgres-primary psql -U store -d online_store
db-psql-replica:
desc: Connect to PostgreSQL (replica)
interactive: true
cmds:
- docker exec -it store-postgres-replica psql -U store -d online_store
db-replication-status:
desc: Check PostgreSQL replication status
cmds:
- echo "📊 Checking replication status..."
- docker exec store-postgres-primary psql -U store -d online_store -c "SELECT application_name, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, pg_wal_lsn_diff(sent_lsn, replay_lsn) AS lag_bytes FROM pg_stat_replication;"
- docker exec store-postgres-primary psql -U store -d online_store -c "SELECT slot_name, active, restart_lsn FROM pg_replication_slots;"
db-replication-test:
desc: Run full replication test
cmds:
- echo "🧪 Running replication test..."
- docker exec store-postgres-primary bash -c "
TEST_ID=$$(date +%s);
psql -U store -d online_store -c \"CREATE TABLE IF NOT EXISTS _replication_test (id BIGINT PRIMARY KEY, created_at TIMESTAMP DEFAULT NOW())\";
psql -U store -d online_store -c \"INSERT INTO _replication_test (id) VALUES ($$TEST_ID) ON CONFLICT (id) DO UPDATE SET created_at = NOW()\";
sleep 1;
echo 'Checking replica...';
"
- docker exec store-postgres-replica psql -U store -d online_store -c "SELECT * FROM _replication_test ORDER BY id DESC LIMIT 5;"
- echo "✅ Replication test complete!"
db-reset:
desc: "Reset database (WARNING: deletes all data)"
prompt: "⚠️ WARNING: This will delete all database data! Are you sure?"
cmds:
- docker compose stop postgres-primary postgres-replica
- docker volume rm onlinestore_postgres_primary_data onlinestore_postgres_replica_data
- docker compose up -d postgres-primary postgres-replica
- cmd: sleep 5
platforms: [linux, darwin]
- cmd: "powershell -NoProfile -Command \"Start-Sleep -Seconds 5\""
platforms: [windows]
ignore_error: true
- task: db-migrate
- echo "✅ Database reset complete!"
# Testing
test:
desc: Run backend tests (current)
cmds:
- task: test-backend
test-backend:
desc: Run backend tests
dir: backend
cmds:
- '{{.MVN}} test'
test-e2e:
desc: Run E2E tests
dir: store-frontend
cmds:
- npm run test:e2e
# Build
build:
desc: Build all services
cmds:
- echo "🔨 Building all services..."
- task: build-gateway
- task: build-backend
- task: build-bot
- task: build-admin
- task: build-store
- echo "✅ Build complete!"
build-gateway:
dir: api-gateway
cmds: ['{{.MVN}} clean package -DskipTests']
build-backend:
dir: backend
cmds: ['{{.MVN}} clean package -DskipTests']
build-bot:
dir: telegram-bot
cmds: ['{{.MVN}} clean package -DskipTests']
build-admin:
dir: admin-panel
cmds: ['npm run build']
build-store:
dir: store-frontend
cmds: ['npm run build']
docker-build:
desc: Build Docker images
cmds:
- echo "🐳 Building Docker images..."
- task: docker-build-gateway
- task: docker-build-backend
- task: docker-build-bot
- echo "✅ Docker images built!"
docker-build-gateway:
dir: api-gateway
cmds: ['{{.MVN}} spring-boot:build-image']
docker-build-backend:
dir: backend
cmds: ['{{.MVN}} spring-boot:build-image']
docker-build-bot:
dir: telegram-bot
cmds: ['{{.MVN}} spring-boot:build-image']
# Helper Tasks
print-urls:
internal: true
silent: true
cmds:
- echo "📊 Access points:"
- echo " - Keycloak{{":"}} http://localhost:8180"
- echo " - RabbitMQ{{":"}} http://localhost:15672"
- echo " - Elasticsearch{{":"}} http://localhost:9200"
- echo " - MinIO Console{{":"}} http://localhost:9001"
- echo " - Grafana{{":"}} http://localhost:3001"
- echo " - Jaeger{{":"}} http://localhost:16686"
- echo " - Prometheus{{":"}} http://localhost:9090"
- echo " - Vault{{":"}} http://localhost:8200"