diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3dd506a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +node_modules +dist +.astro +.git +.env +.env.* +design +docs +coordination +.claude diff --git a/CLAUDE.md b/CLAUDE.md index 19d7ab7..a281143 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -43,6 +43,7 @@ Stack: Astro (static) — see `docs/adr/0003-stack-astro-statico.md`. Node.js re - Dev: `npm run dev` (http://localhost:4321) - Build: `npm run build` (output in `dist/`) - Preview build: `npm run preview` +- Deploy: `./deploy.sh` (Docker on the a75 server, see `docs/runbooks/deploy.md`) - Test / Lint / Typecheck: not set up yet (`npm run check` needs `@astrojs/check`) - Design proposals: `python3 -m http.server 4173 --directory design` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1dd4666 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# syntax=docker/dockerfile:1 + +# Sito statico Astro servito da nginx (ADR 0003, deploy come cam85: ADR 0004). +# Stage 1: build con Node; stage 2: solo i file di dist/ dentro nginx. + +FROM node:22-alpine AS build +WORKDIR /app +COPY package.json package-lock.json ./ +RUN --mount=type=cache,target=/root/.npm npm ci --no-audit --no-fund +COPY astro.config.mjs tsconfig.json ./ +COPY public ./public +COPY src ./src +RUN npm run build + +FROM nginx:1.27-alpine AS runner +COPY docker/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build /app/dist /usr/share/nginx/html +EXPOSE 3000 diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..a3da292 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -euo pipefail + +# Deploy sullo stesso server di cam85, con la stessa modalità (ADR 0004): +# build dell'immagine in locale, trasferimento via docker save/load, +# avvio con docker compose sulla rete "a75" dietro Nginx Proxy Manager. + +SERVER="217.76.62.220" +SSH_USER="root" +APP_DIR="/home/ubuntu/officinezuliani" +IMAGE_TAG="officinezuliani-web:latest" +TARGET_PLATFORM="linux/amd64" # server x86_64 (verificato con uname -m) + +cd "$(dirname "$0")" + +# Il sito non ha bisogno di variabili d'ambiente: il .env locale contiene solo +# il token Gitea e NON va mai copiato sul server. + +echo "→ Build di verifica in locale..." +npm run build + +echo "→ Build immagine (piattaforma $TARGET_PLATFORM)..." +docker buildx build --platform "$TARGET_PLATFORM" -t "$IMAGE_TAG" --load . + +echo "→ Preparazione cartella e compose su $SERVER..." +ssh "$SSH_USER@$SERVER" "mkdir -p '$APP_DIR'" +rsync -az docker-compose.yml "$SSH_USER@$SERVER:$APP_DIR/docker-compose.yml" + +echo "→ Trasferimento immagine..." +docker save "$IMAGE_TAG" | gzip | ssh "$SSH_USER@$SERVER" "gunzip | docker load" + +echo "→ Avvio container..." +ssh "$SSH_USER@$SERVER" " + set -e + cd '$APP_DIR' + docker compose up -d + docker compose ps +" + +echo "→ Verifica interna (dalla rete a75)..." +ssh "$SSH_USER@$SERVER" "docker exec nginx-app-1 curl -s -o /dev/null -w 'HTTP %{http_code}\n' http://officinezuliani-site:3000/" || true + +echo "→ Pulizia layer immagine inutilizzati..." +ssh "$SSH_USER@$SERVER" "docker image prune -f" || true + +echo "✓ Deploy completato — il container è raggiungibile come officinezuliani-site:3000 sulla rete \"a75\";" +echo " il dominio pubblico va configurato come Proxy Host in Nginx Proxy Manager." diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..028cd21 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + # Immagine costruita in locale e caricata sul server da deploy.sh + # (docker save | docker load), come cam85: `up -d` senza --build usa + # quella già presente; `build:` resta solo come fallback manuale. + build: . + image: officinezuliani-web:latest + container_name: officinezuliani-site + restart: always + # Nessuna porta pubblicata: Nginx Proxy Manager raggiunge il container + # sulla rete Docker condivisa "a75" come officinezuliani-site:3000. + networks: + - a75 + +networks: + a75: + external: true diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..3283a29 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,45 @@ +# Configurazione del container: Nginx Proxy Manager (rete Docker "a75") +# termina HTTPS e inoltra qui in HTTP sulla porta 3000 (come cam85). +# Solo il dominio definitivo è indicizzabile: gli altri host (es. il test +# officinezuliani.a75.eu) ricevono noindex. Valore vuoto = header non inviato. +map $http_host $robots_tag { + default "noindex, nofollow"; + ~*(^|\.)officinezulianiudine\.it$ ""; +} + +server { + listen 3000; + server_name _; + root /usr/share/nginx/html; + + # URL puliti come sul sito attuale: /officina → officina.html + location / { + try_files $uri $uri.html $uri/ =404; + } + + # Vecchi link con .html → URL pulito (evita contenuti duplicati). + # Su $request_uri e non con una location: altrimenti colpirebbe anche + # il rimando interno di "index" e "/" andrebbe in loop. + if ($request_uri ~ ^/index\.html) { return 301 /; } + if ($request_uri ~ ^/(.+)\.html(\?.*)?$) { return 301 /$1; } + + # Asset con hash nel nome: cache lunga + location /_astro/ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + + location /img/ { + expires 30d; + } + + gzip on; + gzip_types text/css application/javascript application/json image/svg+xml application/xml text/plain; + + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "strict-origin-when-cross-origin" always; + add_header X-Robots-Tag $robots_tag always; + + # Il proxy davanti fa da origine pubblica: niente porta interna nei redirect + absolute_redirect off; +} diff --git a/docs/adr/0004-hosting-docker-server-a75.md b/docs/adr/0004-hosting-docker-server-a75.md new file mode 100644 index 0000000..6094748 --- /dev/null +++ b/docs/adr/0004-hosting-docker-server-a75.md @@ -0,0 +1,20 @@ +# ADR 0004: Host the site in Docker on the a75 server, deployed like cam85 + +## Status +Accepted (2026-11-04) — supersedes the "hosting not decided" note in ADR 0003 + +## Context +The site is static (ADR 0003). The owner already runs other sites on the VPS `217.76.62.220` (x86_64) with the same pattern as cam85: Docker containers on the shared network `a75`, published through Nginx Proxy Manager (container `nginx-app-1`), images built locally and loaded on the server. + +## Decision +- Image: multi-stage `Dockerfile` (Node 22 build → `nginx:1.27-alpine`) serving `dist/` with `docker/nginx.conf` (clean URLs, `.html` → 301, long cache for hashed assets) +- `docker-compose.yml`: container `officinezuliani-site`, image `officinezuliani-web:latest`, no published ports, external network `a75` +- `deploy.sh` (same flow as cam85): local `npm run build` check → `docker buildx --platform linux/amd64` → `docker save | ssh docker load` → `docker compose up -d` in `/home/ubuntu/officinezuliani` +- The container listens on port 3000 (same convention as cam85); the public hostname is a Proxy Host in Nginx Proxy Manager pointing to `officinezuliani-site:3000`, with Let's Encrypt +- Test hostname: `https://officinezuliani.a75.eu`. Every host except `officinezulianiudine.it` gets `X-Robots-Tag: noindex, nofollow` so the test copy is not indexed +- No `.env` is copied: the site needs none, and the local `.env` holds only the Gitea token + +## Consequences +- Deploys need SSH access as root to the server and a local Docker with buildx +- No registry: rollback means rebuilding an older commit and redeploying +- DNS for the final domain (`officinezulianiudine.it`, today on Italiaonline/Duda) must be moved to the server only at launch; until then a test hostname can be used diff --git a/docs/context/known-constraints.md b/docs/context/known-constraints.md index 22a1dfe..7334274 100644 --- a/docs/context/known-constraints.md +++ b/docs/context/known-constraints.md @@ -2,5 +2,5 @@ - The Gitea repository (`andrearuffini/officinazuliani` on git.a75.it) is public: no secrets in commits; `.env` stays git-ignored. - Gitea Issues are the task board; no external tracker. -- Stack: Astro static (`docs/adr/0003-stack-astro-statico.md`). Hosting and deploy target: not decided yet (record as an ADR). +- Stack: Astro static (`docs/adr/0003-stack-astro-statico.md`). Hosting: Docker on the a75 server behind Nginx Proxy Manager (`docs/adr/0004-hosting-docker-server-a75.md`). - Visual direction: proposal 02 "Bottega" (`docs/adr/0002-direzione-visiva-bottega.md`). diff --git a/docs/context/module-map.md b/docs/context/module-map.md index aee0769..3b0f31b 100644 --- a/docs/context/module-map.md +++ b/docs/context/module-map.md @@ -11,6 +11,7 @@ - `design/assets/sito-attuale/` → images downloaded from the current site - `docs/analisi/`, `docs/progetto/` → audit and development plan - `docs/` (adr, context, runbooks, handoffs), `coordination/`, `.gitea/` → workflow +- `Dockerfile`, `docker/nginx.conf`, `docker-compose.yml`, `deploy.sh` → container image and deploy (ADR 0004) - `.claude/launch.json` → preview configs: `sito` (Astro dev, 4321), `proposte` (4173) ## Important flows diff --git a/docs/handoffs/2026-11-04-deploy-docker.md b/docs/handoffs/2026-11-04-deploy-docker.md new file mode 100644 index 0000000..8619799 --- /dev/null +++ b/docs/handoffs/2026-11-04-deploy-docker.md @@ -0,0 +1,31 @@ +# Handoff + +## Issue +None (explicit user instruction: deploy like cam85, same server, Docker) + +## Goal +Containerize the static site and deploy it on the a75 server with the cam85 flow. + +## Status +ready-for-review — live on https://officinezuliani.a75.eu + +## What changed +- `Dockerfile` (Node build → nginx), `docker/nginx.conf`, `.dockerignore`, `docker-compose.yml`, `deploy.sh` +- ADR 0004, runbook deploy, module map, constraints, CLAUDE.md + +## Files touched +- see above + +## Tests +- Run: local container on :8089 — all pages 200, `/officina.html` → 301 `/officina`, `/index.html` → 301 `/`, unknown URL 404 +- Run: `./deploy.sh` → container `officinezuliani-site` up, internal check from `nginx-app-1` HTTP 200 +- Run: public HTTPS on https://officinezuliani.a75.eu — all pages 200, `.html` → 301, 404 for unknown, `X-Robots-Tag: noindex` present; real-domain Host header gets no noindex + +## Risks / open questions +- NPM proxy host forwards to port 3000: container switched to 3000 to match (cam85 convention) +- HTTP is not redirected to HTTPS on the test host (NPM "Force SSL" off) +- Real domain still points to Italiaonline/Duda: switch only at launch +- No custom 404 page yet (nginx default) + +## Suggested next step +- Phase 2 content (service pages, FAQ page), contact form decision, custom 404 page diff --git a/docs/runbooks/deploy.md b/docs/runbooks/deploy.md index 3fe93c7..00d86f9 100644 --- a/docs/runbooks/deploy.md +++ b/docs/runbooks/deploy.md @@ -1,7 +1,33 @@ # Deploy -Hosting not decided yet (see `docs/adr/0003-stack-astro-statico.md`). Record the choice as a new ADR, then document here: -- Build: `npm run build` → upload `dist/` -- Server rule: serve `/` from `/.html` (e.g. nginx `try_files $uri $uri.html $uri/ =404;`) -- Keep the current URLs (`/officina`, `/servizi`, `/dove-siamo`, `/contatti`) so no redirects are needed -- Rollback procedure: TBD +Hosting: Docker on the a75 server, same flow as cam85 (`docs/adr/0004-hosting-docker-server-a75.md`). + +## Deploy +``` +./deploy.sh +``` +It builds locally, builds the amd64 image, loads it on `217.76.62.220`, runs `docker compose up -d` in `/home/ubuntu/officinezuliani` and checks `http://officinezuliani-site:3000/` from the Nginx Proxy Manager container. + +Requirements: SSH key access as `root@217.76.62.220`, Docker with buildx, Node/npm. + +## Publish a hostname (one-time, Nginx Proxy Manager UI) +1. DNS: A record of the hostname → `217.76.62.220` +2. NPM → Proxy Hosts → Add: forward hostname `officinezuliani-site`, port `3000`, scheme `http` +3. SSL tab: request a Let's Encrypt certificate, force SSL + +## Test the image locally +``` +docker buildx build --platform linux/amd64 -t officinezuliani-web:latest --load . +docker run --rm -p 8089:3000 officinezuliani-web:latest # http://localhost:8089 +``` + +## Rollback +Check out the previous good commit and run `./deploy.sh` again. + +## Server layout +- `/home/ubuntu/officinezuliani/docker-compose.yml` (copied by deploy.sh) +- Container `officinezuliani-site` on network `a75`, port 3000, no host ports + +## Hostnames +- Test: https://officinezuliani.a75.eu (NPM proxy host #35, Let's Encrypt) — served with `noindex` +- Production: `www.officinezulianiudine.it` — still on Italiaonline/Duda; at launch point DNS to `217.76.62.220`, add it to the NPM proxy host with a certificate, and redirect `officinezulianiudine.it` → `www`