From dcc1ac9ceefd6de7040d432de29c351d6af47d5b Mon Sep 17 00:00:00 2001 From: clara Date: Sun, 26 Apr 2026 21:15:12 +0200 Subject: [PATCH] feat: setup CI/CD, add docker compose, and create CRUD dashboard --- .DS_Store | Bin 8196 -> 8196 bytes .gitea/workflows/deploy.yml | 17 +++ Brainstorm/260426/23_CI_CD_und_GitOps.md | 25 ++++ Brainstorm/260426/24_Dashboard_und_Vault.md | 19 +++ Dockerfile | 8 ++ devV1-Seed/server.ts | 112 ++++++++--------- docker-compose.yml | 9 ++ public/index.html | 128 ++++++++++++++++++++ 8 files changed, 259 insertions(+), 59 deletions(-) create mode 100644 .gitea/workflows/deploy.yml create mode 100755 Brainstorm/260426/23_CI_CD_und_GitOps.md create mode 100755 Brainstorm/260426/24_Dashboard_und_Vault.md create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 public/index.html diff --git a/.DS_Store b/.DS_Store index 58373b3f0e5c09d783065c7ba1d9629e48e123e6..9369674deafa88c8ca2cbd3f16ad02f3c55c8766 100755 GIT binary patch delta 21 ccmZp1XmQxEOn}3}z*tAY*wSG0I)N~L081|hPyhe` delta 21 ccmZp1XmQxEOn}48!c0fO$lP%AI)N~L0854jR{#J2 diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..a91da85 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,17 @@ +name: Deploy API + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Build and Deploy + run: | + docker compose up --build -d diff --git a/Brainstorm/260426/23_CI_CD_und_GitOps.md b/Brainstorm/260426/23_CI_CD_und_GitOps.md new file mode 100755 index 0000000..dbf8a97 --- /dev/null +++ b/Brainstorm/260426/23_CI_CD_und_GitOps.md @@ -0,0 +1,25 @@ +# RoggioApp - CI/CD & GitOps (Von Gitea in die Produktion) + +## Die Herausforderung +Wie kommen wir von "Clara pusht Code ins Gitea" zu "Der Code läuft auf einer Subdomain als Docker-Container"? + +## Die Lösungen + +### 1. Gitea Actions (Der moderne Weg) +Gitea hat "Gitea Actions" eingebaut (ein fast 1:1 Klon von GitHub Actions). +* **Wie es funktioniert:** Wir starten einen zusätzlichen kleinen Container (`act_runner`) auf der Docker-VM. +* **Ablauf:** Wenn ich einen Commit nach Gitea pushe, bemerkt der Runner das, baut ein neues Docker-Image für unseren Node.js-Server und startet den Container neu. + +### 2. Coolify (Der UI-basierte Weg) +Coolify ist eine Open-Source-Alternative zu Vercel/Heroku. +* **Wie es funktioniert:** Man verbindet Coolify mit dem lokalen Gitea. Man sagt Coolify: "Deploye den Ordner `backend`". +* **Ablauf:** Coolify kümmert sich um den Build, den Proxy und SSL. Es ist extrem komfortabel, aber ein recht "fetter" Service, den man hosten muss. + +### 3. Docker Compose Watch / Watchtower (Der Lean-Weg) +Wir bleiben ganz nah am Blech. +* **Wie es funktioniert:** Ein Tool wie "Watchtower" oder ein einfaches Webhook-Skript auf der VM horcht auf Gitea. +* **Ablauf:** Wenn ein Push kommt, macht das Skript `git pull` und `docker compose up --build -d`. + +## Claras Empfehlung für uns +**Gitea Actions!** +Wir haben Gitea sowieso schon laufen. Wenn wir den kleinen `act_runner` daneben setzen, können wir im Repository einfach eine Datei `.gitea/workflows/deploy.yml` anlegen. Das ist der Industrie-Standard (GitOps) und kostet uns keine neuen riesigen Server-Dienste wie Coolify. diff --git a/Brainstorm/260426/24_Dashboard_und_Vault.md b/Brainstorm/260426/24_Dashboard_und_Vault.md new file mode 100755 index 0000000..a96ecf3 --- /dev/null +++ b/Brainstorm/260426/24_Dashboard_und_Vault.md @@ -0,0 +1,19 @@ +# RoggioApp - Infrastruktur: Dashboard & Vault + +## Die Herausforderung +Mit Gitea, Nginx Proxy Manager, pgAdmin, Nextcloud, BookMe-API und bald noch Gitea-Runnern wächst unser Zoo an URLs, IPs, Usernamen und Passwörtern. Wir brauchen ein Cockpit (Dashboard) und einen Tresor (Vault). + +## Die Lösungen für das Kollektiv-Cockpit + +### 1. Das Dashboard (Homepage) +Wir brauchen eine einfache, gut aussehende Startseite (`hub.h80.11112222.net`), auf der alle Links als Kacheln liegen. +* **Empfehlung: Homepage (oder Dashy / Homer).** +* *Homepage* (von benphelps) ist ein extrem beliebtes, leichtgewichtiges Docker-Dashboard, das per YAML-Datei konfiguriert wird. Keine Datenbank nötig, lädt in Millisekunden und zeigt sogar den Status (Online/Offline) der Docker-Container an! + +### 2. Der Passwort-Tresor (Vault) +Wir brauchen einen zentralen Ort, an dem Sev (und später das Kollektiv) die Passwörter (`Clara123!`, `admin`, `aralc`) sicher ablegen können. +* **Empfehlung: Vaultwarden.** +* *Vaultwarden* ist eine in Rust geschriebene, extrem schlanke Version von Bitwarden. Es läuft perfekt in Docker, bietet volle Kompatibilität mit allen Bitwarden-Apps (iOS/Android/Browser-Plugins) und erlaubt das Teilen von Passwörtern in "Organisationen" (ideal für das Kollektiv). + +## Umsetzung +Wir erweitern unser Infra-Docker-Compose-File auf der Docker-VM um diese zwei Services und packen beide über den Nginx Proxy sicher hinter Let's Encrypt SSL-Zertifikate. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1a3a416 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM node:20-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npx prisma generate --schema=schema.prisma +EXPOSE 3000 +CMD ["npx", "tsx", "devV1-Seed/server.ts"] diff --git a/devV1-Seed/server.ts b/devV1-Seed/server.ts index 242986f..4e8d4ce 100755 --- a/devV1-Seed/server.ts +++ b/devV1-Seed/server.ts @@ -1,73 +1,67 @@ import { serve } from '@hono/node-server' +import { serveStatic } from '@hono/node-server/serve-static' import { Hono } from 'hono' import { PrismaClient } from '@prisma/client' const app = new Hono() const prisma = new PrismaClient() -app.get('/', (c) => { - return c.html(` - - - BookMe - Roggio API - - - -

BookMe API (RoggioApp MVP)

-

Willkommen an der API-Schnittstelle. Test-Endpunkte:

- - - - `) +// API: Alle Units abrufen +app.get('/api/units', async (c) => { + const units = await prisma.unit.findMany() + return c.json(units) }) -app.get('/api/apartments', async (c) => { - const units = await prisma.unit.findMany({ - include: { - children: { - include: { children: true } - } - } - }) - - const apartments = units.filter(u => { - const traits = u.traits as any - return traits && traits.is_rentable === true - }).map(apartment => { - let totalArea = 0; - let totalSleepCapacity = 0; - - apartment.children.forEach(room => { - const rTraits = room.traits as any; - if (rTraits?.area_sqm) totalArea += rTraits.area_sqm; - - room.children.forEach(inv => { - const iTraits = inv.traits as any; - if (iTraits?.sleep_capacity) totalSleepCapacity += iTraits.sleep_capacity; - }); - }); - - return { - id: apartment.id, - name: apartment.name, - base_price: (apartment.traits as any).base_price, - calculated_stats: { - area_sqm: totalArea, - sleep_capacity: totalSleepCapacity - }, - rooms: apartment.children.map(r => r.name) - } - }) - - return c.json(apartments) +// API: Eine Unit erstellen +app.post('/api/units', async (c) => { + const body = await c.req.json() + const unit = await prisma.unit.create({ data: body }) + return c.json(unit) }) +// API: Eine Unit bearbeiten +app.put('/api/units/:id', async (c) => { + const id = c.req.param('id') + const body = await c.req.json() + const unit = await prisma.unit.update({ + where: { id }, + data: body + }) + return c.json(unit) +}) + +// API: Eine Unit löschen +app.delete('/api/units/:id', async (c) => { + const id = c.req.param('id') + await prisma.unit.delete({ where: { id } }) + return c.json({ success: true }) +}) + +// API: Events (Identisch zu Units) +app.get('/api/events', async (c) => { + const events = await prisma.event.findMany() + return c.json(events) +}) +app.post('/api/events', async (c) => { + const body = await c.req.json() + const event = await prisma.event.create({ data: body }) + return c.json(event) +}) +app.put('/api/events/:id', async (c) => { + const id = c.req.param('id') + const body = await c.req.json() + const event = await prisma.event.update({ where: { id }, data: body }) + return c.json(event) +}) +app.delete('/api/events/:id', async (c) => { + const id = c.req.param('id') + await prisma.event.delete({ where: { id } }) + return c.json({ success: true }) +}) + +// Statische Dateien (Unser Dashboard) +app.use('/*', serveStatic({ root: './public' })) + const port = 3000 console.log(`Server is running on port ${port}`) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0bc692d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + api: + build: . + container_name: roggio_api + ports: + - "3000:3000" + restart: unless-stopped + environment: + - DATABASE_URL=postgresql://roggio:roggio_secret@192.168.20.252:5432/roggiodb diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..cbefc3d --- /dev/null +++ b/public/index.html @@ -0,0 +1,128 @@ + + + + + RoggioApp - API Dashboard + + + + +
+

RoggioApp Dashboard

+ +
+ + +
+

Units (Räume/Objekte)

+ +
+ + + +
+ +
    +
  • +
    + {{ unit.name }} + +
    + + +
  • +
+
+ + +
+

Events (Buchungen/Aufgaben)

+ +
+ +
+ + +
+
+ +
    +
  • +
    + {{ event.type }} + Unit: {{ getUnitName(event.unitId) }} +
    + +
  • +
+
+ +
+
+ + + +