From 24ca5679212e86b463d5d4fb9d8821eb2ded55fe Mon Sep 17 00:00:00 2001 From: Luca Banfi Date: Mon, 18 May 2026 15:06:58 +0200 Subject: [PATCH] docs + woodpecker --- .woodpecker.yml | 104 ++++++++++++++++++++++++++++++++ DEV memo.md => Docs/DEV memo.md | 0 DEV.md => Docs/DEV.md | 0 Docs/autodeploy.md | 104 ++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 .woodpecker.yml rename DEV memo.md => Docs/DEV memo.md (100%) rename DEV.md => Docs/DEV.md (100%) create mode 100644 Docs/autodeploy.md diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..1f5e9c3 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,104 @@ +--- +# .woodpecker.yml — RPA TDI Dashboard Service +# Forge: Gitea — Runner: Ubuntu cloud + Docker +# +# Flusso: +# push / PR → lint + syntax +# tag prod → lint + syntax + build + deploy (automatico) +# +# Per pubblicare: +# git tag prod && git push --tags + +when: + event: [push, pull_request, tag] + +steps: + - name: lint + image: python:3.12-slim + when: + event: [push, pull_request, tag] + commands: + - pip install flake8 --quiet + - flake8 . --max-line-length=120 --exclude=__pycache__ + + - name: syntax + image: python:3.12-slim + when: + event: [push, pull_request, tag] + depends_on: [lint] + commands: + - pip install python-dotenv --quiet + - python -m compileall -q . + + - name: build + image: python:3.12-slim + when: + event: tag + tag: prod + commands: + - apt-get update -qq && apt-get install -y zip --quiet + - pip install python-dotenv rcssmin rjsmin --quiet + - | + python - <<'EOF' + import os, zipfile, fnmatch + + EXCLUDE_FILES = ["tmp_*", "*.md"] + EXCLUDE_DIRS = {".git", "__pycache__", "data", "tests", "docs", "secrets"} + EXCLUDE_EXACTLY = {".env"} + OUT = "rpa-tdi-dashboard-prod.zip" + + def is_excluded(rel): + parts = rel.replace("\\", "/").split("/") + if parts[0] in EXCLUDE_DIRS: + return True + name = parts[-1] + if name in EXCLUDE_EXACTLY: + return True + for pat in EXCLUDE_FILES: + if fnmatch.fnmatch(name, pat): + return True + return False + + with zipfile.ZipFile(OUT, "w", zipfile.ZIP_DEFLATED) as zf: + for root, dirs, files in os.walk("."): + dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS and not d.startswith(".")] + for f in files: + path = os.path.join(root, f) + rel = os.path.relpath(path, ".") + if not is_excluded(rel): + zf.write(path, rel) + print(f" + {rel}") + print(f"\n✓ {OUT}") + EOF + - ls -lh rpa-tdi-dashboard-prod.zip + + # Copia i file su /ATG_RUN_TEST/Dashboard e riavvia il container + # Prerequisiti sulla VM: + # - /ATG_RUN_TEST/Dashboard/.env → già presente con le variabili locali + # - Woodpecker runner configurato con volumes abilitati (WOODPECKER_BACKEND_DOCKER_VOLUMES=true) + - name: deploy + image: docker:cli + when: + event: tag + tag: prod + depends_on: [build] + volumes: + - /ATG_RUN_TEST/Dashboard:/app + - /var/run/docker.sock:/var/run/docker.sock + commands: + - apk add --no-cache unzip --quiet + - unzip -o rpa-tdi-dashboard-prod.zip -d /app + - echo "✓ File estratti in /ATG_RUN_TEST/Dashboard" + - docker stop rpa-dashboard-test 2>/dev/null || true + - docker rm rpa-dashboard-test 2>/dev/null || true + - docker run -d + --name rpa-dashboard-test + --restart unless-stopped + -v /ATG_RUN_TEST/Dashboard:/app + -v /ATG_RUN_TEST/db:/rpa-db + -w /app + -e RPA_DB_DIR=/rpa-db + -p 8473:8473 + python:3.12-slim + sh -c "pip install -r requirements.txt -q && python Dashboard.py" + - echo "✓ Container avviato su http://57.131.52.95:8473" diff --git a/DEV memo.md b/Docs/DEV memo.md similarity index 100% rename from DEV memo.md rename to Docs/DEV memo.md diff --git a/DEV.md b/Docs/DEV.md similarity index 100% rename from DEV.md rename to Docs/DEV.md diff --git a/Docs/autodeploy.md b/Docs/autodeploy.md new file mode 100644 index 0000000..9ca10fd --- /dev/null +++ b/Docs/autodeploy.md @@ -0,0 +1,104 @@ +# RPA Dashboard — Autodeploy con Woodpecker CI + +## Panoramica + +Il deploy avviene automaticamente tramite **Woodpecker CI** collegato a **Gitea**. +Non serve nessun intervento manuale: basta taggare un commit con `prod`. + +--- + +## Flusso + +``` +push / PR → lint + syntax check (verifica automatica ad ogni commit) + +tag prod → lint → syntax → build → deploy + └─ estrae i file su /ATG_RUN_TEST/Dashboard + └─ riavvia il container Docker + └─ dashboard live su http://57.131.52.95:8473 +``` + +--- + +## Pubblicare una nuova versione + +```bash +# 1. Commit delle modifiche +git add . +git commit -m "descrizione modifica" + +# 2. Spostare il tag prod sul commit corrente +git tag -f prod +git push --force --tags +``` + +Woodpecker riceve il webhook da Gitea e avvia la pipeline in automatico. + +--- + +## Step della pipeline (`.woodpecker.yml`) + +| Step | Trigger | Cosa fa | +|---|---|---| +| `lint` | push / PR / tag | flake8 — controlla stile e errori Python | +| `syntax` | push / PR / tag | `py_compile` su tutti i `.py` | +| `build` | tag `prod` | crea `rpa-tdi-dashboard-prod.zip` (esclude `.env`, `__pycache__`, `*.md`, ecc.) | +| `deploy` | tag `prod` | estrae lo zip in `/ATG_RUN_TEST/Dashboard`, riavvia il container | + +--- + +## Infrastruttura + +| Componente | Dettaglio | +|---|---| +| Forge | Gitea (self-hosted) | +| CI | Woodpecker CI — Ubuntu cloud + Docker | +| VM | `57.131.52.95` | +| Porta dashboard | `8473` | +| Cartella deploy | `/ATG_RUN_TEST/Dashboard` | +| Cartella DB | `/ATG_RUN_TEST/db` | +| Container | `rpa-dashboard-test` | + +--- + +## Prerequisiti sulla VM (setup iniziale, una tantum) + +```bash +# Creare le cartelle +mkdir -p /ATG_RUN_TEST/Dashboard +mkdir -p /ATG_RUN_TEST/db + +# Creare il .env con le variabili locali Linux +cat > /ATG_RUN_TEST/Dashboard/.env <