feat: setup CI/CD, add docker compose, and create CRUD dashboard
Deploy API / deploy (push) Failing after 2m12s
Deploy API / deploy (push) Failing after 2m12s
This commit is contained in:
@@ -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
|
||||||
Executable
+25
@@ -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.
|
||||||
Executable
+19
@@ -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.
|
||||||
@@ -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"]
|
||||||
+49
-55
@@ -1,73 +1,67 @@
|
|||||||
import { serve } from '@hono/node-server'
|
import { serve } from '@hono/node-server'
|
||||||
|
import { serveStatic } from '@hono/node-server/serve-static'
|
||||||
import { Hono } from 'hono'
|
import { Hono } from 'hono'
|
||||||
import { PrismaClient } from '@prisma/client'
|
import { PrismaClient } from '@prisma/client'
|
||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
app.get('/', (c) => {
|
// API: Alle Units abrufen
|
||||||
return c.html(`
|
app.get('/api/units', async (c) => {
|
||||||
<html>
|
const units = await prisma.unit.findMany()
|
||||||
<head>
|
return c.json(units)
|
||||||
<title>BookMe - Roggio API</title>
|
|
||||||
<style>
|
|
||||||
body { font-family: monospace; background: #282a36; color: #f8f8f2; padding: 2rem; }
|
|
||||||
h1 { color: #50fa7b; }
|
|
||||||
.unit { border: 1px solid #6272a4; padding: 1rem; margin-bottom: 1rem; border-radius: 8px; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>BookMe API (RoggioApp MVP)</h1>
|
|
||||||
<p>Willkommen an der API-Schnittstelle. Test-Endpunkte:</p>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/api/apartments" style="color: #ff79c6;">/api/apartments</a> - Zeigt alle mietbaren Einheiten (dynamisch berechnet)</li>
|
|
||||||
</ul>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/api/apartments', async (c) => {
|
// API: Eine Unit erstellen
|
||||||
const units = await prisma.unit.findMany({
|
app.post('/api/units', async (c) => {
|
||||||
include: {
|
const body = await c.req.json()
|
||||||
children: {
|
const unit = await prisma.unit.create({ data: body })
|
||||||
include: { children: true }
|
return c.json(unit)
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const apartments = units.filter(u => {
|
// API: Eine Unit bearbeiten
|
||||||
const traits = u.traits as any
|
app.put('/api/units/:id', async (c) => {
|
||||||
return traits && traits.is_rentable === true
|
const id = c.req.param('id')
|
||||||
}).map(apartment => {
|
const body = await c.req.json()
|
||||||
let totalArea = 0;
|
const unit = await prisma.unit.update({
|
||||||
let totalSleepCapacity = 0;
|
where: { id },
|
||||||
|
data: body
|
||||||
apartment.children.forEach(room => {
|
})
|
||||||
const rTraits = room.traits as any;
|
return c.json(unit)
|
||||||
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 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
|
const port = 3000
|
||||||
console.log(`Server is running on port ${port}`)
|
console.log(`Server is running on port ${port}`)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>RoggioApp - API Dashboard</title>
|
||||||
|
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
</head>
|
||||||
|
<body class="bg-gray-100 text-gray-800">
|
||||||
|
<div id="app" class="container mx-auto p-8">
|
||||||
|
<h1 class="text-4xl font-bold mb-8 text-indigo-600">RoggioApp Dashboard</h1>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||||
|
|
||||||
|
<!-- UNITS SECTION -->
|
||||||
|
<div class="bg-white p-6 rounded-lg shadow">
|
||||||
|
<h2 class="text-2xl font-bold mb-4">Units (Räume/Objekte)</h2>
|
||||||
|
|
||||||
|
<form @submit.prevent="createUnit" class="mb-4 flex gap-2">
|
||||||
|
<input v-model="newUnit.name" placeholder="Name (z.B. Appartement 1)" class="border p-2 rounded flex-1" required>
|
||||||
|
<input v-model="newUnit.traits" placeholder="Traits (JSON)" class="border p-2 rounded flex-1">
|
||||||
|
<button type="submit" class="bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700">Neu</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<ul class="space-y-2">
|
||||||
|
<li v-for="unit in units" :key="unit.id" class="border p-4 rounded flex flex-col gap-2 bg-gray-50">
|
||||||
|
<div class="flex justify-between items-center">
|
||||||
|
<strong>{{ unit.name }}</strong>
|
||||||
|
<button @click="deleteUnit(unit.id)" class="text-red-500 hover:underline">Löschen</button>
|
||||||
|
</div>
|
||||||
|
<textarea v-model="unit.traitsRaw" class="w-full border p-2 text-sm font-mono rounded" rows="3"></textarea>
|
||||||
|
<button @click="updateUnit(unit)" class="bg-green-500 text-white px-2 py-1 rounded text-sm self-end hover:bg-green-600">Speichern</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- EVENTS SECTION -->
|
||||||
|
<div class="bg-white p-6 rounded-lg shadow">
|
||||||
|
<h2 class="text-2xl font-bold mb-4">Events (Buchungen/Aufgaben)</h2>
|
||||||
|
|
||||||
|
<form @submit.prevent="createEvent" class="mb-4 flex flex-col gap-2">
|
||||||
|
<select v-model="newEvent.unitId" class="border p-2 rounded" required>
|
||||||
|
<option disabled value="">Unit auswählen...</option>
|
||||||
|
<option v-for="u in units" :value="u.id">{{ u.name }}</option>
|
||||||
|
</select>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<input v-model="newEvent.type" placeholder="Type (z.B. booking)" class="border p-2 rounded flex-1" required>
|
||||||
|
<button type="submit" class="bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700">Neu</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<ul class="space-y-2">
|
||||||
|
<li v-for="event in events" :key="event.id" class="border p-4 rounded flex justify-between items-center bg-gray-50">
|
||||||
|
<div>
|
||||||
|
<span class="bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs font-bold">{{ event.type }}</span>
|
||||||
|
<span class="ml-2 text-sm text-gray-600">Unit: {{ getUnitName(event.unitId) }}</span>
|
||||||
|
</div>
|
||||||
|
<button @click="deleteEvent(event.id)" class="text-red-500 hover:underline text-sm">Löschen</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const { createApp } = Vue
|
||||||
|
|
||||||
|
createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
units: [],
|
||||||
|
events: [],
|
||||||
|
newUnit: { name: '', traits: '{"is_rentable": true}' },
|
||||||
|
newEvent: { unitId: '', type: 'booking' }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async fetchUnits() {
|
||||||
|
const res = await fetch('/api/units');
|
||||||
|
const data = await res.json();
|
||||||
|
this.units = data.map(u => ({ ...u, traitsRaw: JSON.stringify(u.traits, null, 2) }));
|
||||||
|
},
|
||||||
|
async fetchEvents() {
|
||||||
|
const res = await fetch('/api/events');
|
||||||
|
this.events = await res.json();
|
||||||
|
},
|
||||||
|
getUnitName(id) {
|
||||||
|
const u = this.units.find(u => u.id === id);
|
||||||
|
return u ? u.name : id;
|
||||||
|
},
|
||||||
|
async createUnit() {
|
||||||
|
try {
|
||||||
|
const body = { name: this.newUnit.name, traits: JSON.parse(this.newUnit.traits || '{}') };
|
||||||
|
await fetch('/api/units', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
||||||
|
this.newUnit.name = '';
|
||||||
|
this.fetchUnits();
|
||||||
|
} catch(e) { alert("Invalid JSON in Traits"); }
|
||||||
|
},
|
||||||
|
async updateUnit(unit) {
|
||||||
|
try {
|
||||||
|
const body = { name: unit.name, traits: JSON.parse(unit.traitsRaw) };
|
||||||
|
await fetch(\`/api/units/\${unit.id}\`, { method: 'PUT', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
||||||
|
alert("Gespeichert!");
|
||||||
|
} catch(e) { alert("Invalid JSON"); }
|
||||||
|
},
|
||||||
|
async deleteUnit(id) {
|
||||||
|
await fetch(\`/api/units/\${id}\`, { method: 'DELETE' });
|
||||||
|
this.fetchUnits();
|
||||||
|
},
|
||||||
|
async createEvent() {
|
||||||
|
const body = { unitId: this.newEvent.unitId, type: this.newEvent.type, traits: {} };
|
||||||
|
await fetch('/api/events', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
||||||
|
this.fetchEvents();
|
||||||
|
},
|
||||||
|
async deleteEvent(id) {
|
||||||
|
await fetch(\`/api/events/\${id}\`, { method: 'DELETE' });
|
||||||
|
this.fetchEvents();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.fetchUnits();
|
||||||
|
this.fetchEvents();
|
||||||
|
}
|
||||||
|
}).mount('#app')
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user