Features:
- Health endpoint now returns git_commit SHA and version
- Auto-detects git commit during Docker build
- Falls back to 'unknown' if git info unavailable
- Allows AI agents to verify deployed version
Changes:
1. server.js: Add git_commit and version to /health response
2. Dockerfile: Add git installation and commit detection
3. Dockerfile: Accept GIT_COMMIT and APP_VERSION build args
4. docker-compose.yml: Pass build args and env vars for versioning
5. README.md: Document version tracking in health endpoint
Example response:
{
"status": "healthy",
"postgres": "connected",
"redis": "connected",
"timestamp": "2026-02-14T10:30:00.000Z",
"git_commit": "eb6b6e0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q",
"version": "1.0.0"
}
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
90 lines
2.1 KiB
YAML
90 lines
2.1 KiB
YAML
version: '3.8'
|
|
|
|
services:
|
|
app:
|
|
build:
|
|
context: .
|
|
args:
|
|
GIT_COMMIT: ${GIT_COMMIT:-unknown}
|
|
APP_VERSION: ${APP_VERSION:-1.0.0}
|
|
restart: unless-stopped
|
|
environment:
|
|
- NODE_ENV=production
|
|
- PORT=3000
|
|
- POSTGRES_HOST=postgres
|
|
- POSTGRES_PORT=5432
|
|
- POSTGRES_USER=postgres
|
|
- POSTGRES_PASSWORD=postgres
|
|
- POSTGRES_DB=template_db
|
|
- REDIS_HOST=redis
|
|
- REDIS_PORT=6379
|
|
- GIT_COMMIT=${GIT_COMMIT:-unknown}
|
|
- APP_VERSION=${APP_VERSION:-1.0.0}
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
networks:
|
|
- app-network
|
|
expose:
|
|
- "3000"
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
start_period: 5s
|
|
retries: 2
|
|
labels:
|
|
- "traefik.enable=true"
|
|
- "traefik.http.routers.template-001.rule=Host(`template-001.startanaicompany.com`)"
|
|
- "traefik.http.routers.template-001.entrypoints=websecure"
|
|
- "traefik.http.routers.template-001.tls=true"
|
|
- "traefik.http.routers.template-001.tls.certresolver=letsencrypt"
|
|
- "traefik.http.services.template-001.loadbalancer.server.port=3000"
|
|
|
|
postgres:
|
|
image: postgres:15-alpine
|
|
restart: unless-stopped
|
|
environment:
|
|
- POSTGRES_USER=postgres
|
|
- POSTGRES_PASSWORD=postgres
|
|
- POSTGRES_DB=template_db
|
|
volumes:
|
|
- postgres-data:/var/lib/postgresql/data
|
|
networks:
|
|
- app-network
|
|
expose:
|
|
- "5432"
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 3
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
restart: unless-stopped
|
|
command: redis-server --appendonly yes
|
|
volumes:
|
|
- redis-data:/data
|
|
networks:
|
|
- app-network
|
|
expose:
|
|
- "6379"
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 3
|
|
|
|
volumes:
|
|
postgres-data:
|
|
driver: local
|
|
redis-data:
|
|
driver: local
|
|
|
|
networks:
|
|
app-network:
|
|
driver: bridge
|