Skip to content

Commit 79c41e2

Browse files
committed
chore(dev): streamline Makefile for hot-reload workflow (+ logs/rebuild targets); finalize health endpoints & vite prox
1 parent 72255bf commit 79c41e2

6 files changed

Lines changed: 76 additions & 112 deletions

File tree

Makefile

Lines changed: 57 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# ===== Workmate Dev Makefile (clean) =====
1+
# ===== Workmate Dev Makefile =====
22
# Usage:
33
# make help
4-
# make up / down / restart / ps / logs
5-
# make db / db-clean
6-
# make be / fe / be-sh / fe-sh / psql
4+
# make up / down / restart / ps
5+
# make be-logs / fe-logs / be-restart / fe-restart
6+
# make rebuild-ui / rebuild-be
77
# make migrate / makemigration MIG_MSG="add email" / alembic-current / alembic-history
8+
# make test / health / ready / live
89
# make seed SEED_FILE="kit-staff/workmate_employees_basic.json"
9-
# make test / fmt / ci / build-be
10-
# make health
1110

1211
SHELL := /bin/sh
1312

@@ -23,86 +22,72 @@ ADMINER_SVC ?= adminer
2322

2423
SEED_FILE ?= kit-staff/workmate_employees_basic.json
2524

26-
# Internal helper
25+
# Helper: run compose with profile + env file wired in
2726
CMD = ENV_FILE=$(ENV) $(COMPOSE) --profile $(PROFILE)
2827

29-
# Current short git sha (host)
28+
# Git SHA (short) for ENV stamping (optional)
3029
SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
3130

3231
.PHONY: help
33-
help: ## Show this help
32+
help:
3433
@grep -E '^[a-zA-Z0-9_-]+:.*?##' $(MAKEFILE_LIST) | sed 's/:.*##/: /' | sort
3534

3635
# ---- Metadata helpers ----
3736
.PHONY: sha
38-
sha: ## Set GIT_SHA=<short> inside $(ENV)
37+
sha: ## Set GIT_SHA in $(ENV) to current commit
3938
@if [ -f "$(ENV)" ]; then \
40-
if grep -q '^GIT_SHA=' "$(ENV)"; then \
41-
sed -i 's/^GIT_SHA=.*/GIT_SHA=$(SHA)/' "$(ENV)"; \
42-
else \
43-
printf "\nGIT_SHA=$(SHA)\n" >> "$(ENV)"; \
44-
fi; \
45-
else \
46-
printf "APP_VERSION=0.1.0\nGIT_SHA=$(SHA)\n" > "$(ENV)"; \
47-
fi
48-
@echo "GIT_SHA set to $(SHA) in $(ENV)"
49-
50-
.PHONY: set-version
51-
set-version: ## Set APP_VERSION (use: make set-version VERSION=0.2.0)
52-
@test -n "$(VERSION)" || (echo 'Bitte VERSION="x.y.z" setzen' && exit 1)
53-
@if [ -f "$(ENV)" ]; then \
54-
if grep -q '^APP_VERSION=' "$(ENV)"; then \
55-
sed -i 's/^APP_VERSION=.*/APP_VERSION=$(VERSION)/' "$(ENV)"; \
56-
else \
57-
printf "\nAPP_VERSION=$(VERSION)\n" >> "$(ENV)"; \
58-
fi; \
59-
else \
60-
printf "APP_VERSION=$(VERSION)\nGIT_SHA=$(SHA)\n" > "$(ENV)"; \
61-
fi
62-
@echo "APP_VERSION set to $(VERSION) in $(ENV)"
63-
64-
# ---- Stack ----
39+
if grep -q '^GIT_SHA=' "$(ENV)"; then sed -i 's/^GIT_SHA=.*/GIT_SHA=$(SHA)/' "$(ENV)"; \
40+
else printf "\nGIT_SHA=$(SHA)\n" >> "$(ENV)"; fi; \
41+
else printf "APP_VERSION=0.1.0\nGIT_SHA=$(SHA)\n" > "$(ENV)"; fi; \
42+
echo "GIT_SHA=$(SHA)"
43+
44+
# ---- Stack controls ----
6545
.PHONY: up
66-
up: sha ## Start all services (detached) after setting GIT_SHA
67-
$(CMD) up -d --build
46+
up: sha ## Start stack (no rebuild)
47+
$(CMD) up -d
6848

6949
.PHONY: down
70-
down: ## Stop all services (keep volumes)
50+
down: ## Stop stack (keep volumes)
7151
$(CMD) down
7252

7353
.PHONY: restart
74-
restart: ## Restart all services
75-
$(CMD) down && $(CMD) up -d --build
54+
restart: ## Restart backend+ui
55+
$(CMD) restart $(BACKEND_SVC) $(FRONTEND_SVC)
7656

7757
.PHONY: ps
78-
ps: ## Show service status
58+
ps: ## Show container status
7959
$(CMD) ps
8060

81-
.PHONY: logs
82-
logs: ## Tail logs (use SVC=<name>, default=$(BACKEND_SVC))
83-
$(CMD) logs -f $${SVC:-$(BACKEND_SVC)} --tail=100
61+
# ---- Logs / restarts ----
62+
.PHONY: be-logs
63+
be-logs: ## Tail backend logs
64+
$(CMD) logs -f $(BACKEND_SVC)
65+
66+
.PHONY: fe-logs
67+
fe-logs: ## Tail frontend logs
68+
$(CMD) logs -f $(FRONTEND_SVC)
8469

85-
# ---- Partial starts ----
86-
.PHONY: db
87-
db: ## Start DB + Adminer only
88-
$(CMD) up -d $(DB_SVC) $(ADMINER_SVC)
70+
.PHONY: be-restart
71+
be-restart: ## Restart backend only
72+
$(CMD) restart $(BACKEND_SVC)
8973

90-
.PHONY: db-clean
91-
db-clean: ## ⚠️ Stop stack & remove volumes (fresh DB)
92-
$(CMD) down -v
74+
.PHONY: fe-restart
75+
fe-restart: ## Restart frontend only
76+
$(CMD) restart $(FRONTEND_SVC)
9377

94-
.PHONY: be
95-
be: ## Run backend in foreground (debug)
96-
$(CMD) up $(BACKEND_SVC)
78+
# ---- Rebuilds (only when Dockerfile/locks changed) ----
79+
.PHONY: rebuild-ui
80+
rebuild-ui: ## Rebuild UI image only
81+
$(CMD) up -d --build $(FRONTEND_SVC)
9782

98-
.PHONY: fe
99-
fe: ## Run frontend in foreground
100-
$(CMD) up $(FRONTEND_SVC)
83+
.PHONY: rebuild-be
84+
rebuild-be: ## Rebuild backend image only
85+
$(CMD) up -d --build $(BACKEND_SVC)
10186

102-
# ---- Alembic ----
87+
# ---- Alembic & DB helpers ----
10388
.PHONY: migrate
10489
migrate: ## alembic upgrade head
105-
$(CMD) run --rm $(BACKEND_SVC) alembic upgrade head
90+
$(CMD) exec $(BACKEND_SVC) alembic upgrade head
10691

10792
.PHONY: makemigration
10893
makemigration: ## autogen migration (MIG_MSG="message")
@@ -117,52 +102,24 @@ alembic-current: ## show current revision
117102
alembic-history: ## show history (verbose)
118103
$(CMD) exec $(BACKEND_SVC) alembic history --verbose
119104

120-
# ---- Seeds & DB tools ----
121105
.PHONY: seed
122-
seed: ## seed DB (SEED_FILE overrideable)
106+
seed: ## seed DB (override with SEED_FILE=...)
123107
$(CMD) exec $(BACKEND_SVC) python kit-staff/seed_kit_team.py --file $(SEED_FILE)
124108

125-
.PHONY: psql
126-
psql: ## open psql in DB container (uses POSTGRES_* env in container)
127-
$(CMD) exec -e PGPASSWORD=$$POSTGRES_PASSWORD $(DB_SVC) \
128-
sh -lc 'psql -h localhost -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"'
109+
# ---- Health shortcuts ----
110+
.PHONY: health
111+
health: ## GET /api/health (via host)
112+
@curl -s http://localhost:8000/api/health | jq .
129113

130-
# ---- Shells ----
131-
.PHONY: be-sh
132-
be-sh: ## shell into backend
133-
$(CMD) exec $(BACKEND_SVC) sh
114+
.PHONY: ready
115+
ready: ## GET /api/ready (status code)
116+
@curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8000/api/ready
134117

135-
.PHONY: fe-sh
136-
fe-sh: ## shell into frontend
137-
$(CMD) exec $(FRONTEND_SVC) sh
118+
.PHONY: live
119+
live: ## GET /api/live
120+
@curl -s http://localhost:8000/api/live | jq .
138121

139-
# ---- Tests & Format ----
122+
# ---- Tests ----
140123
.PHONY: test
141-
test: ## run pytest in backend (if installed)
124+
test: ## run pytest in backend container
142125
$(CMD) exec $(BACKEND_SVC) pytest -q || true
143-
144-
.PHONY: fmt
145-
fmt: ## run black/isort/ruff if available
146-
$(CMD) exec $(BACKEND_SVC) sh -lc 'black app || true; isort app || true; ruff check app --fix || true'
147-
148-
# ---- Local CI mimic & build ----
149-
.PHONY: ci
150-
ci: ## DB -> migrate -> pytest (quick local CI)
151-
$(CMD) up -d $(DB_SVC)
152-
sleep 3
153-
$(CMD) exec $(BACKEND_SVC) alembic upgrade head
154-
$(CMD) exec $(BACKEND_SVC) pytest -q || true
155-
156-
.PHONY: build-be
157-
build-be: ## build backend dev image
158-
docker build -f backend/Dockerfile.dev -t workmate/backend:dev ./backend
159-
160-
# ---- Convenience ----
161-
.PHONY: health live ready
162-
health:
163-
@curl -s http://localhost:8000/api/health | jq .
164-
live:
165-
@curl -s http://localhost:8000/api/live | jq .
166-
ready:
167-
@curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8000/api/ready
168-

docker-compose.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
2-
31
name: kit_workmate
42

53
networks:
64
kit_net:
75

86
volumes:
97
pg_data:
8+
ui_node_modules: # named volume für node_modules im Container
109

1110
services:
1211
db:
@@ -44,15 +43,15 @@ services:
4443
ports:
4544
- "${BACKEND_PORT:-8000}:8000"
4645
volumes:
47-
- ./backend:/app
46+
- ./backend:/app # Bind-Mount für Hot-Reload
4847
command: >
4948
sh -c "alembic upgrade head &&
50-
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload"
49+
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload --reload-dir /app"
5150
networks:
5251
- kit_net
5352
profiles: ["dev"]
5453
healthcheck:
55-
test: ["CMD", "curl","-fsS","http://localhost:8000/api/ready"]
54+
test: ["CMD", "curl", "-fsS", "http://localhost:8000/api/ready"]
5655
interval: 20s
5756
timeout: 3s
5857
retries: 5
@@ -61,18 +60,22 @@ services:
6160
ui:
6261
build:
6362
context: ./ui
64-
dockerfile: Dockerfile
63+
dockerfile: Dockerfile.dev # ← sicherstellen, dass dein UI-Dockerfile.dev corepack/pnpm o. npm enthält
6564
container_name: kit_ui
6665
environment:
67-
VITE_API_BASE: ${VITE_API_BASE:-http://localhost:8000}
66+
# Nur den Basis-Pfad ans UI geben, den Proxy macht Vite (target=backend:8000)
67+
- VITE_API_BASE=/api
68+
# File-watcher zuverlässig machen
69+
- CHOKIDAR_USEPOLLING=1
6870
ports:
6971
- "${FRONTEND_PORT:-5173}:5173"
7072
volumes:
71-
- ./ui:/usr/src/app
72-
- /usr/src/app/node_modules
73-
command: ["npm", "run", "dev", "--", "--host"]
73+
- ./ui:/app # ← gleich wie WORKDIR im UI-Dockerfile
74+
- ui_node_modules:/app/node_modules
75+
command: ["pnpm", "dev", "--host", "0.0.0.0", "--port", "5173"]
7476
depends_on:
75-
- backend
77+
backend:
78+
condition: service_healthy # warte bis API bereit ist
7679
networks:
7780
- kit_net
7881
profiles: ["dev"]

ui/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# ui/.dockerignore
2+
13
node_modules
24
dist
File renamed without changes.

ui/src/components/HealthDot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ onMounted(async () => {
3636
'text-white/60': status === 'loading',
3737
}"
3838
>
39-
{{ status }}
39+
{{ status }} - Backend | DB Status
4040
</span>
4141
</div>
4242
</template>

ui/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ui/vite.config.ts
2+
13
import { defineConfig } from 'vite'
24
import vue from '@vitejs/plugin-vue'
35
import { fileURLToPath, URL } from 'node:url'

0 commit comments

Comments
 (0)