feat(docker): aggiungi flusso di sviluppo con hot reload via compose
Dockerfile diventa multi-stage con target `dev` (Vite + bind-mount) oltre a `builder`/`runtime`; docker-compose.dev.yml lo usa per un ambiente di sviluppo containerizzato equivalente a `npm run dev`, senza toccare il compose di produzione (che resta pull-only dal registry). Documentato in README e CLAUDE.md.
This commit is contained in:
@@ -84,12 +84,22 @@ Copertura statement/linee Vitest oltre il 99%. Per testare `startServer()` (`ser
|
||||
|
||||
## Deploy
|
||||
|
||||
Docker, immagine pubblicata sul registry Gitea self-hosted (`santantonio.sytes.net`):
|
||||
`Dockerfile` è multi-stage con 4 target: `deps` (dipendenze condivise), `dev` (hot reload Vite), `builder` (build frontend), `runtime` (immagine di produzione, target di default).
|
||||
|
||||
**Produzione** — `docker-compose.yml` usa l'immagine già pubblicata sul registry Gitea self-hosted (`santantonio.sytes.net`), niente build locale:
|
||||
|
||||
```bash
|
||||
docker compose up -d # Avvia con immagine dal registry privato (porta 3000)
|
||||
```
|
||||
|
||||
**Sviluppo** — `docker-compose.dev.yml` builda il target `dev` in locale e monta il codice sorgente per l'hot reload (Vite su porta 5173); `node_modules` resta un volume anonimo del container per non farsi sovrascrivere dal bind-mount (evita anche problemi di binari nativi arch-specific tra host e container):
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.dev.yml up --build
|
||||
```
|
||||
|
||||
Per buildare in locale l'immagine di produzione (es. per testarla prima del push sul registry): `docker build -t segnapunti:local .` (usa il target `runtime` di default).
|
||||
|
||||
Volume `./.segnapunti` persiste lo stato tra i riavvii del container.
|
||||
|
||||
## Istruzioni operative
|
||||
|
||||
+13
-4
@@ -1,13 +1,22 @@
|
||||
# Stage 1: build frontend
|
||||
FROM node:20-alpine AS builder
|
||||
# Stage 1: dipendenze condivise (build + dev)
|
||||
FROM node:20-alpine AS deps
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Stage 2: dev — hot reload via Vite, sorgente montato da bind-mount
|
||||
FROM deps AS dev
|
||||
ENV NODE_ENV=development
|
||||
EXPOSE 5173
|
||||
CMD ["npm", "run", "dev"]
|
||||
|
||||
# Stage 3: build frontend
|
||||
FROM deps AS builder
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: runtime
|
||||
FROM node:20-alpine
|
||||
# Stage 4: runtime di produzione
|
||||
FROM node:20-alpine AS runtime
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production PORT=3000
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ Segnapunti digitale in tempo reale per partite di pallavolo. Un server centrale
|
||||
- [Funzionalità](#funzionalità)
|
||||
- [Deploy con Docker](#deploy-con-docker)
|
||||
- [Sviluppo](#sviluppo)
|
||||
- [Sviluppo con Docker](#sviluppo-con-docker)
|
||||
- [Test](#test)
|
||||
|
||||
---
|
||||
@@ -186,6 +187,8 @@ docker compose pull && docker compose up -d
|
||||
|
||||
### Build e pubblicazione immagine
|
||||
|
||||
Il `Dockerfile` è multi-stage (`deps` → `dev` / `builder` → `runtime`); senza specificare `--target`, il build produce l'ultimo stage (`runtime`), l'immagine di produzione:
|
||||
|
||||
```bash
|
||||
docker build \
|
||||
-t santantonio.sytes.net/attilio/segnapunti:2.0.0 \
|
||||
@@ -195,6 +198,13 @@ docker push santantonio.sytes.net/attilio/segnapunti:2.0.0
|
||||
docker push santantonio.sytes.net/attilio/segnapunti:latest
|
||||
```
|
||||
|
||||
Per testare in locale l'immagine di produzione senza pubblicarla:
|
||||
|
||||
```bash
|
||||
docker build -t segnapunti:local .
|
||||
docker run --rm -p 3000:3000 -v ./.segnapunti:/app/.segnapunti segnapunti:local
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Sviluppo
|
||||
@@ -230,6 +240,29 @@ Lo stato viene salvato in `.segnapunti/state.json` anche in modalità dev.
|
||||
|
||||
---
|
||||
|
||||
## Sviluppo con Docker
|
||||
|
||||
In alternativa a Node.js installato in locale, `docker-compose.dev.yml` builda il target `dev` del `Dockerfile` e monta il codice sorgente nel container, con hot reload identico a `npm run dev`:
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.dev.yml up --build
|
||||
```
|
||||
|
||||
| URL | Interfaccia |
|
||||
|---|---|
|
||||
| `http://localhost:5173/display` | Display |
|
||||
| `http://localhost:5173/controller` | Controller |
|
||||
|
||||
Le modifiche ai file sorgente sull'host si riflettono subito nel container (bind-mount); `node_modules` resta invece un volume anonimo del container, per non farsi sovrascrivere dal bind-mount e per evitare incompatibilità tra i binari nativi installati sull'host e quelli richiesti dal container (es. host ARM / container `node:20-alpine` su x86).
|
||||
|
||||
Per fermare e rimuovere il container:
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.dev.yml down
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Test
|
||||
|
||||
| Comando | Descrizione |
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
services:
|
||||
segnapunti:
|
||||
build:
|
||||
context: .
|
||||
target: dev
|
||||
container_name: segnapunti-dev
|
||||
ports:
|
||||
- "5173:5173"
|
||||
volumes:
|
||||
- .:/app
|
||||
- /app/node_modules
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
Reference in New Issue
Block a user