feat: production docker stack with nightly backups and README
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8201496bb6
commit
a0bcea4eb1
7 files changed
+218
-2
No files matched your search
@@ -0,0 +1,12 @@
|
||||
node_modules
|
||||
.next
|
||||
.git
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.superpowers
|
||||
backups
|
||||
dist
|
||||
tests
|
||||
docs
|
||||
*.log
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
# Développement local (voir docker-compose.dev.yml)
|
||||
# --- Production (docker-compose.yml) ---
|
||||
# Générer chaque secret avec : openssl rand -hex 32
|
||||
MARIADB_ROOT_PASSWORD=
|
||||
MARIADB_PASSWORD=
|
||||
SESSION_SECRET=
|
||||
APP_PORT=3000
|
||||
|
||||
# --- Développement local uniquement (docker-compose.dev.yml + npm run dev) ---
|
||||
DATABASE_URL="mysql://root:dev@localhost:3307/finances"
|
||||
TEST_DATABASE_URL="mysql://root:dev@localhost:3307/finances_test"
|
||||
SESSION_SECRET="change-me-to-32+chars-random-string-xxxxxxxx"
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
# --- Dépendances ---
|
||||
FROM node:24-alpine AS deps
|
||||
WORKDIR /app
|
||||
RUN apk add --no-cache openssl
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
# --- Build Next.js (standalone) + scripts compilés ---
|
||||
FROM node:24-alpine AS build
|
||||
WORKDIR /app
|
||||
RUN apk add --no-cache openssl
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
RUN npx prisma generate \
|
||||
&& npm run build \
|
||||
&& npx esbuild prisma/seed.ts scripts/reset-password.ts --bundle --platform=node --format=cjs \
|
||||
--packages=external --entry-names=[name] --outdir=dist
|
||||
|
||||
# --- Image finale ---
|
||||
FROM node:24-alpine AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production TZ=Europe/Paris PORT=3000 HOSTNAME=0.0.0.0 NEXT_TELEMETRY_DISABLED=1
|
||||
RUN apk add --no-cache openssl tzdata \
|
||||
&& npm install -g prisma@6.19.3 \
|
||||
&& addgroup -S app && adduser -S app -G app
|
||||
COPY --from=build --chown=app:app /app/.next/standalone ./
|
||||
COPY --from=build --chown=app:app /app/.next/static ./.next/static
|
||||
COPY --from=build --chown=app:app /app/public ./public
|
||||
COPY --from=build --chown=app:app /app/prisma ./prisma
|
||||
COPY --from=build --chown=app:app /app/dist ./dist
|
||||
COPY --from=build --chown=app:app /app/node_modules/.prisma ./node_modules/.prisma
|
||||
COPY --from=build --chown=app:app /app/node_modules/@prisma/client ./node_modules/@prisma/client
|
||||
COPY --from=build --chown=app:app /app/node_modules/bcryptjs ./node_modules/bcryptjs
|
||||
COPY --chmod=755 docker/entrypoint.sh /entrypoint.sh
|
||||
USER app
|
||||
EXPOSE 3000
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,80 @@
|
||||
# Finances du foyer
|
||||
|
||||
Suivi des entrées, dépenses et charges partagées d'un foyer de deux personnes :
|
||||
répartition en %, « qui doit combien à qui », récurrents, dépenses prévues, budgets,
|
||||
remboursements employeur affectés à une charge (IK, part de loyer…) et crédits.
|
||||
|
||||
Stack : Next.js 15 (TypeScript) + MariaDB, le tout sous Docker Compose. Accès réseau local uniquement (HTTP).
|
||||
|
||||
## Installation sur la VM
|
||||
|
||||
Prérequis : Docker et le plugin `docker compose`, git, et un accès Internet pendant le build (paquets npm, police Inter).
|
||||
|
||||
```bash
|
||||
git clone git@git.fabout.it:hcloez/hcl-finances-manager.git
|
||||
cd hcl-finances-manager
|
||||
cp .env.example .env
|
||||
# Renseigner les 3 secrets dans .env (un par ligne) :
|
||||
openssl rand -hex 32 # → MARIADB_ROOT_PASSWORD
|
||||
openssl rand -hex 32 # → MARIADB_PASSWORD
|
||||
openssl rand -hex 32 # → SESSION_SECRET
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
Ouvrir ensuite **http://192.168.1.211:3000**. Au premier accès, un écran d'installation crée les deux comptes
|
||||
(prénom, identifiant, mot de passe, couleur), la répartition par défaut et un éventuel solde d'ouverture.
|
||||
|
||||
Les variables `DATABASE_URL` / `TEST_DATABASE_URL` de `.env` ne servent qu'au développement local ; elles sont ignorées par la stack de production.
|
||||
|
||||
## Mise à jour
|
||||
|
||||
```bash
|
||||
git pull
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
Les migrations de la base s'appliquent automatiquement au démarrage du conteneur `app`.
|
||||
|
||||
## Sauvegardes
|
||||
|
||||
- Le service `backup` fait un dump compressé de la base **au démarrage puis chaque nuit à 03:00** (heure de Paris)
|
||||
dans `./backups/finances-AAAA-MM-JJ_HHMM.sql.gz`. Les dumps de plus de **30 jours** sont supprimés.
|
||||
- La VM entière est par ailleurs sauvegardée par Proxmox Backup Server.
|
||||
- Vérifier les sauvegardes : `ls -lh backups/` et `docker compose logs backup`.
|
||||
|
||||
### Restaurer un dump
|
||||
|
||||
```bash
|
||||
docker compose stop app
|
||||
gunzip -c backups/finances-AAAA-MM-JJ_HHMM.sql.gz \
|
||||
| docker compose exec -T db sh -c 'mariadb -u root -p"$MARIADB_ROOT_PASSWORD" finances'
|
||||
docker compose start app
|
||||
```
|
||||
|
||||
## Mot de passe oublié
|
||||
|
||||
Chacun change son propre mot de passe dans **Réglages**. En cas d'oubli :
|
||||
|
||||
```bash
|
||||
docker compose exec app node dist/reset-password.js <identifiant> <nouveau-mot-de-passe>
|
||||
```
|
||||
|
||||
## Développement local
|
||||
|
||||
```bash
|
||||
npm install
|
||||
cp .env.example .env # garder les variables de la section « Développement local », ajouter SESSION_SECRET
|
||||
docker compose -f docker-compose.dev.yml up -d # MariaDB sur le port 3307 (bases finances et finances_test)
|
||||
npx prisma migrate dev
|
||||
npm run db:seed
|
||||
npm run dev # http://localhost:3000
|
||||
npm test # tests unitaires + intégration (base finances_test)
|
||||
```
|
||||
|
||||
Organisation du code :
|
||||
|
||||
- `src/domain/` : règles de calcul pures et testées (centimes entiers, répartitions en points de base) :
|
||||
équilibre entre personnes, flux mensuels, charges nettes, budgets, amortissement, récurrences.
|
||||
- `src/server/` : accès base (Prisma), authentification, services métier (`services/`) et Server Actions (`actions/`).
|
||||
- `src/app/` : pages (tableau de bord, opérations, récurrents & prévu, budgets, crédits, réglages).
|
||||
- `docs/superpowers/specs/` : document de conception ; `docs/superpowers/plans/` : plan d'implémentation.
|
||||
@@ -0,0 +1,48 @@
|
||||
# Stack de production : docker compose up -d --build
|
||||
services:
|
||||
db:
|
||||
image: mariadb:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MARIADB_DATABASE: finances
|
||||
MARIADB_USER: finances
|
||||
MARIADB_PASSWORD: ${MARIADB_PASSWORD:?à définir dans .env}
|
||||
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:?à définir dans .env}
|
||||
TZ: Europe/Paris
|
||||
volumes:
|
||||
- db_data:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 20s
|
||||
|
||||
app:
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
DATABASE_URL: mysql://finances:${MARIADB_PASSWORD}@db:3306/finances
|
||||
SESSION_SECRET: ${SESSION_SECRET:?à définir dans .env (32 caractères minimum)}
|
||||
ports:
|
||||
- "${APP_PORT:-3000}:3000"
|
||||
|
||||
backup:
|
||||
image: mariadb:latest
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
entrypoint: ["bash", "/backup.sh"]
|
||||
environment:
|
||||
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
|
||||
TZ: Europe/Paris
|
||||
volumes:
|
||||
- ./docker/backup.sh:/backup.sh:ro
|
||||
- ./backups:/backups
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
# Sauvegarde quotidienne de la base (03:00, heure de Paris), rétention 30 jours.
|
||||
set -u
|
||||
|
||||
dump() {
|
||||
local file="/backups/finances-$(date +%F_%H%M).sql.gz"
|
||||
if mariadb-dump -h db -u root -p"$MARIADB_ROOT_PASSWORD" --single-transaction --routines finances | gzip > "$file.tmp"; then
|
||||
mv "$file.tmp" "$file"
|
||||
echo "$(date '+%F %T') sauvegarde OK : $file"
|
||||
else
|
||||
rm -f "$file.tmp"
|
||||
echo "$(date '+%F %T') ÉCHEC de la sauvegarde" >&2
|
||||
fi
|
||||
find /backups -name 'finances-*.sql.gz' -mtime +30 -delete
|
||||
}
|
||||
|
||||
# Attend que la base réponde, puis une première sauvegarde au démarrage.
|
||||
until mariadb-admin ping -h db -u root -p"$MARIADB_ROOT_PASSWORD" --silent; do sleep 5; done
|
||||
dump
|
||||
|
||||
while true; do
|
||||
now=$(date +%s)
|
||||
next=$(date -d "tomorrow 03:00" +%s)
|
||||
[ "$(date +%H)" -lt 3 ] && next=$(date -d "today 03:00" +%s)
|
||||
sleep $((next - now))
|
||||
dump
|
||||
done
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
# Migrations du schéma puis catégories de départ (idempotent), puis serveur Next.js.
|
||||
prisma migrate deploy --schema prisma/schema.prisma
|
||||
node dist/seed.js
|
||||
exec node server.js
|
||||
Reference in new issue
Block a user