feat(docker): finalise le déploiement compose (sqlite + postgres)
- Compose nettoyé en deux profils isolés (sqlite, postgres) avec healthcheck HTTP et network_mode host pour la découverte LAN. - Override docker-compose.bridge.yml pour les environnements où host mode n'est pas disponible (macOS/Windows). - Entrypoint tolérant : fallback prisma db push quand aucune migration n'existe encore. - Dockerfile robuste sans package-lock.json (npm install fallback). - .env.docker.example et docker/README.md pour un démarrage en une commande. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,60 +2,115 @@
|
||||
# IPAM — Docker Compose
|
||||
# ---------------------------------------------------------------
|
||||
# Deux profils :
|
||||
# - `sqlite` → ipam seul, base dans un volume
|
||||
# - `postgres` → ipam + postgres
|
||||
# - `sqlite` → ipam seul, base SQLite dans un volume
|
||||
# - `postgres` → ipam + postgres
|
||||
#
|
||||
# Usage :
|
||||
# docker compose --profile sqlite up -d
|
||||
# docker compose --profile postgres up -d
|
||||
# docker compose -f docker/docker-compose.yml --profile sqlite up -d
|
||||
# docker compose -f docker/docker-compose.yml --profile postgres up -d
|
||||
#
|
||||
# Le mode `network_mode: host` est indispensable pour que la découverte
|
||||
# (ARP, mDNS, ping sweep, port scan) atteigne le LAN. Sans lui, le
|
||||
# container ne voit que le bridge Docker.
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
services:
|
||||
# =========================================================
|
||||
# Service IPAM — variante SQLite (autonome, sans PostgreSQL)
|
||||
# =========================================================
|
||||
ipam:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
args:
|
||||
DATABASE_PROVIDER: sqlite
|
||||
image: ipam-homelab:sqlite
|
||||
container_name: ipam
|
||||
restart: unless-stopped
|
||||
# Network mode host : indispensable pour ARP / mDNS / ping sweep
|
||||
# sur le réseau local. Commenter cette ligne si non nécessaire.
|
||||
network_mode: host
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
PORT: 3000
|
||||
HOSTNAME: 0.0.0.0
|
||||
DATABASE_PROVIDER: sqlite
|
||||
DATABASE_URL: "file:/app/data/ipam.db"
|
||||
RUN_SEED: "${RUN_SEED:-false}"
|
||||
env_file:
|
||||
- ../.env
|
||||
volumes:
|
||||
- ipam-data:/app/data
|
||||
# Capabilities requises pour le ping ICMP raw
|
||||
cap_add:
|
||||
- NET_RAW
|
||||
- NET_ADMIN
|
||||
profiles: [sqlite, postgres]
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q --spider http://localhost:3000/ || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 30s
|
||||
profiles: ["sqlite"]
|
||||
|
||||
# =========================================================
|
||||
# Service IPAM — variante PostgreSQL
|
||||
# =========================================================
|
||||
ipam-pg:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
args:
|
||||
DATABASE_PROVIDER: postgresql
|
||||
image: ipam-homelab:postgres
|
||||
container_name: ipam
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
PORT: 3000
|
||||
HOSTNAME: 0.0.0.0
|
||||
DATABASE_PROVIDER: postgresql
|
||||
DATABASE_URL: "postgresql://ipam:${POSTGRES_PASSWORD:-ipam}@127.0.0.1:5432/ipam?schema=public"
|
||||
RUN_SEED: "${RUN_SEED:-false}"
|
||||
env_file:
|
||||
- ../.env
|
||||
cap_add:
|
||||
- NET_RAW
|
||||
- NET_ADMIN
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
required: false
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q --spider http://localhost:3000/ || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 30s
|
||||
profiles: ["postgres"]
|
||||
|
||||
# =========================================================
|
||||
# PostgreSQL (profil "postgres" uniquement)
|
||||
# =========================================================
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
container_name: ipam-postgres
|
||||
restart: unless-stopped
|
||||
# network_mode host → expose le port 5432 directement sur l'hôte.
|
||||
network_mode: host
|
||||
environment:
|
||||
POSTGRES_USER: ipam
|
||||
POSTGRES_PASSWORD: ipam
|
||||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-ipam}"
|
||||
POSTGRES_DB: ipam
|
||||
PGPORT: 5432
|
||||
volumes:
|
||||
- ipam-postgres:/var/lib/postgresql/data
|
||||
ports:
|
||||
- '5432:5432'
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'pg_isready -U ipam']
|
||||
test: ["CMD-SHELL", "pg_isready -U ipam -d ipam"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
profiles: [postgres]
|
||||
profiles: ["postgres"]
|
||||
|
||||
volumes:
|
||||
ipam-data:
|
||||
driver: local
|
||||
ipam-postgres:
|
||||
driver: local
|
||||
|
||||
Reference in New Issue
Block a user