Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6adab64bb | ||
|
|
8d904660b9 |
No files matched your search
@@ -0,0 +1,63 @@
|
||||
# Production settings – copy to <DEPLOY_PATH>/shared/.env on the server and fill in.
|
||||
# Generate APP_KEY locally once: php artisan key:generate --show
|
||||
|
||||
APP_NAME="Ferienwohnung Stommer"
|
||||
APP_ENV=production
|
||||
APP_KEY=
|
||||
APP_DEBUG=false
|
||||
APP_URL=https://www.fewo-stommer.de
|
||||
APP_TIMEZONE=Europe/Berlin
|
||||
APP_LOCALE=de
|
||||
APP_FALLBACK_LOCALE=de
|
||||
APP_FAKER_LOCALE=de_DE
|
||||
APP_MAINTENANCE_DRIVER=file
|
||||
|
||||
LOG_CHANNEL=daily
|
||||
LOG_LEVEL=warning
|
||||
|
||||
# Strato MySQL (Kundenlogin › Datenbanken und Webspace › Datenbanken verwalten)
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=
|
||||
DB_USERNAME=
|
||||
DB_PASSWORD=
|
||||
|
||||
SESSION_DRIVER=database
|
||||
SESSION_LIFETIME=120
|
||||
SESSION_SECURE_COOKIE=true
|
||||
CACHE_STORE=database
|
||||
QUEUE_CONNECTION=sync
|
||||
FILESYSTEM_DISK=local
|
||||
|
||||
# Strato mailbox fewo@stommer.de
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=smtp.strato.de
|
||||
MAIL_PORT=465
|
||||
MAIL_SCHEME=smtps
|
||||
MAIL_USERNAME=fewo@stommer.de
|
||||
MAIL_PASSWORD=
|
||||
MAIL_FROM_ADDRESS="fewo@stommer.de"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
FEWO_OWNER_NAME="Brigitte Stommer"
|
||||
FEWO_OWNER_EMAIL=fewo@stommer.de
|
||||
FEWO_NOTIFICATION_EMAIL=fewo@stommer.de
|
||||
FEWO_BANK_ACCOUNT_HOLDER=
|
||||
FEWO_BANK_IBAN=
|
||||
FEWO_BANK_BIC=
|
||||
FEWO_BANK_NAME=
|
||||
|
||||
# Portal booking e-mails (fast path)
|
||||
FEWO_MAILBOX_HOST=imap.strato.de
|
||||
FEWO_MAILBOX_PORT=993
|
||||
FEWO_MAILBOX_ENCRYPTION=ssl
|
||||
FEWO_MAILBOX_USERNAME=fewo@stommer.de
|
||||
FEWO_MAILBOX_PASSWORD=
|
||||
FEWO_MAILBOX_FOLDER=INBOX
|
||||
|
||||
# Monitoring / automation (long random values, e.g. php -r "echo bin2hex(random_bytes(24));")
|
||||
FEWO_HEALTH_TOKEN=
|
||||
FEWO_SCHEDULER_TOKEN=
|
||||
FEWO_AUTOMATION_SECRET=
|
||||
FEWO_AUTOMATION_WEBHOOK_URL=
|
||||
@@ -0,0 +1,85 @@
|
||||
# Tests on every push; deployment to Strato for tags "v*" or by hand (Gitea › Actions › Deploy › Run workflow).
|
||||
# Needs a Gitea act_runner (e.g. on the private server) and these repository secrets:
|
||||
# DEPLOY_SSH_KEY private key whose public key is stored at Strato (SFTP & SSH)
|
||||
# DEPLOY_HOST ssh.strato.de
|
||||
# DEPLOY_USER SSH user from the Strato customer login
|
||||
# DEPLOY_PATH e.g. fewo-production
|
||||
# DEPLOY_PHP e.g. /opt/RZphp84/bin/php-cli
|
||||
# DEPLOY_URL e.g. https://www.fewo-stommer.de
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ['v*']
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
description: Ziel
|
||||
type: choice
|
||||
options: [production, staging]
|
||||
default: production
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring, intl, gd, exif, zip, pdo_sqlite, sqlite3, fileinfo, openssl
|
||||
tools: composer:v2
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: npm
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
composer install --no-interaction --no-progress --prefer-dist
|
||||
npm ci --no-audit --no-fund
|
||||
npm run build
|
||||
cp .env.example .env
|
||||
php artisan key:generate
|
||||
|
||||
- name: Tests
|
||||
run: php artisan test --compact
|
||||
|
||||
deploy:
|
||||
needs: test
|
||||
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring, intl, gd, exif, zip, fileinfo, openssl
|
||||
tools: composer:v2
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: npm
|
||||
|
||||
- name: SSH key
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
printf '%s\n' "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Deploy
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||
DEPLOY_PHP: ${{ secrets.DEPLOY_PHP }}
|
||||
DEPLOY_URL: ${{ secrets.DEPLOY_URL }}
|
||||
run: |
|
||||
export DEPLOY_SSH_KEY="$HOME/.ssh/deploy_key"
|
||||
bash scripts/deploy.sh "${{ inputs.environment || 'production' }}" deploy
|
||||
@@ -28,3 +28,7 @@ _ide_helper.php
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
Thumbs.db
|
||||
|
||||
# Deployment settings with access data
|
||||
/scripts/deploy.*.env
|
||||
!/scripts/deploy.example.env
|
||||
@@ -13,6 +13,7 @@ # Ferienwohnung Stommer
|
||||
- Special offers are evaluated automatically by `PriceCalculator`; discounts are `QuoteLineType::Discount` lines with negative amounts.
|
||||
- Portal sync lives in `app/Channels` (connector interface + registry in `config/channels.php`, iCal connector/parser/feed). Our system leads; `SyncChannel` imports portal occupations as `BlockedPeriod` rows with `channel_id`; each channel's export feed excludes its own blocks. Observers on Booking/BlockedPeriod create `ChannelTask`s for portals with `requires_manual_blocking`. Portal booking e-mails are a fast path (`app/Channels/Mail`, `ProcessPortalMail`): they create blocks with source `email`, which `SyncChannel` later confirms/replaces and never removes as stale. Portal analysis: `docs/PORTALE.md`.
|
||||
- Website = theme system (`docs/THEMES.md`): themes live in `resources/themes/<key>` (theme.json, theme.css, theme.js, views); views resolve via the `theme::` namespace (theme → parent → base `ostsee-licht`). Pages are lists of sections (`app/Themes/Sections`, catalogue in `config/themes.php`); seasonal `Appearance`s override tokens/texts/hero photo. Theme views use only token colour classes (`bg-accent`, `text-muted`, …). Resolve `Theme` lazily (`app(Theme::class)`), never in constructors – middleware `ResolveTheme` replaces it per request.
|
||||
- Deployment: `scripts/deploy.sh <env> setup|deploy|rollback|releases|artisan` (atomic releases on Strato, docs/DEPLOYMENT.md); CI `.gitea/workflows/deploy.yml`. Production has no dev packages (no factories/Faker) – production seeding via `ProductionSeeder`.
|
||||
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
||||
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
||||
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
||||
|
||||
@@ -13,6 +13,7 @@ # Ferienwohnung Stommer
|
||||
- Special offers are evaluated automatically by `PriceCalculator`; discounts are `QuoteLineType::Discount` lines with negative amounts.
|
||||
- Portal sync lives in `app/Channels` (connector interface + registry in `config/channels.php`, iCal connector/parser/feed). Our system leads; `SyncChannel` imports portal occupations as `BlockedPeriod` rows with `channel_id`; each channel's export feed excludes its own blocks. Observers on Booking/BlockedPeriod create `ChannelTask`s for portals with `requires_manual_blocking`. Portal booking e-mails are a fast path (`app/Channels/Mail`, `ProcessPortalMail`): they create blocks with source `email`, which `SyncChannel` later confirms/replaces and never removes as stale. Portal analysis: `docs/PORTALE.md`.
|
||||
- Website = theme system (`docs/THEMES.md`): themes live in `resources/themes/<key>` (theme.json, theme.css, theme.js, views); views resolve via the `theme::` namespace (theme → parent → base `ostsee-licht`). Pages are lists of sections (`app/Themes/Sections`, catalogue in `config/themes.php`); seasonal `Appearance`s override tokens/texts/hero photo. Theme views use only token colour classes (`bg-accent`, `text-muted`, …). Resolve `Theme` lazily (`app(Theme::class)`), never in constructors – middleware `ResolveTheme` replaces it per request.
|
||||
- Deployment: `scripts/deploy.sh <env> setup|deploy|rollback|releases|artisan` (atomic releases on Strato, docs/DEPLOYMENT.md); CI `.gitea/workflows/deploy.yml`. Production has no dev packages (no factories/Faker) – production seeding via `ProductionSeeder`.
|
||||
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
||||
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
||||
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
@@ -63,6 +64,19 @@ public function health(Request $request): JsonResponse
|
||||
], $ok ? 200 : 503);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the task scheduler once (fallback for hosting without suitable cron jobs).
|
||||
*/
|
||||
public function scheduler(Request $request): JsonResponse
|
||||
{
|
||||
$token = config('fewo.scheduler_token');
|
||||
abort_if(blank($token) || ! hash_equals($token, (string) $request->query('token')), 404);
|
||||
|
||||
Artisan::call('schedule:run');
|
||||
|
||||
return response()->json(['ran_at' => now()->toIso8601String(), 'output' => trim(Artisan::output())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push variant of the e-mail fast path, e.g. from an n8n IMAP trigger:
|
||||
* JSON {message_id, from, subject, text, received_at}, signed like the automation webhook.
|
||||
|
||||
@@ -76,6 +76,12 @@
|
||||
'stale_after_minutes' => (int) env('FEWO_MAILBOX_STALE_AFTER_MINUTES', 15),
|
||||
],
|
||||
|
||||
/*
|
||||
| Fallback trigger for the task scheduler (e.g. from n8n every minute) if the hosting's cron jobs
|
||||
| are not available or not frequent enough: GET /automation/scheduler?token=… . Empty = disabled.
|
||||
*/
|
||||
'scheduler_token' => env('FEWO_SCHEDULER_TOKEN'),
|
||||
|
||||
/*
|
||||
| Optional external automation (e.g. a browser bot on a private server) that carries out
|
||||
| manual blocking tasks. Tasks are POSTed signed with HMAC-SHA256 of the body.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Site;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
* Initial data for a fresh production installation (no test data, no factories – they are not deployed).
|
||||
* Run once: scripts/deploy.sh production artisan db:seed --class=ProductionSeeder --force
|
||||
* Create the first administrator afterwards: scripts/deploy.sh production artisan make:filament-user
|
||||
*/
|
||||
class ProductionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
if (Site::query()->exists()) {
|
||||
$this->command?->warn('Es gibt bereits eine Website – Ersteinrichtung übersprungen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->call([PropertySeeder::class, WebsiteContentSeeder::class, SiteSeeder::class]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
# Deployment auf Strato
|
||||
|
||||
Stand: 22.10.2026 · Skript: `scripts/deploy.sh` · CI: `.gitea/workflows/deploy.yml`
|
||||
|
||||
## 1. Prinzip
|
||||
|
||||
```
|
||||
Gitea (main/Tag) ──► Build (CI oder lokal): git-Stand · composer --no-dev · npm run build
|
||||
│ tar.gz
|
||||
▼ SSH
|
||||
Strato <DEPLOY_PATH>/
|
||||
releases/20261022…/ ◄─ entpackt
|
||||
shared/.env ◄─ einmalig von Hand
|
||||
shared/storage/ ◄─ Uploads, Logs, Sessions (bleiben)
|
||||
current ──► releases/… ◄─ atomar umgeschaltet nach migrate + optimize
|
||||
Domain-Zielverzeichnis = <DEPLOY_PATH>/current/public
|
||||
│
|
||||
▼ https://…/up – Gesundheitscheck, bei Fehler automatischer Rollback
|
||||
```
|
||||
|
||||
Auf dem Server werden nur **bash, tar und PHP-CLI** gebraucht – kein Composer, kein Node, kein Git, kein rsync.
|
||||
|
||||
## 2. SSH oder SFTP?
|
||||
|
||||
**Empfehlung: SSH.** Das Skript führt nach dem Hochladen Befehle auf dem Server aus (Archiv entpacken, Datenbank migrieren, Caches erzeugen, Version umschalten, ggf. zurückschalten). Das geht nur mit SSH.
|
||||
|
||||
Nur mit SFTP wäre ein Deployment möglich, aber deutlich schwächer:
|
||||
- Kein Entpacken auf dem Server → jede Datei einzeln übertragen (über 10.000 Dateien, mehrere Minuten pro Update, unterbrechungsanfällig).
|
||||
- Migrationen und Caches müssten über einen gesicherten Web-Aufruf angestoßen werden; kein `artisan` für Wartung und Fehlersuche.
|
||||
- Umschalten wäre per SFTP-Symlink möglich, aber ohne sauberen Rückfall bei Fehlern.
|
||||
|
||||
Strato richtet beide Zugänge im selben Menü ein (Kundenlogin › Datenbanken und Webspace › **SFTP & SSH**). Bei Hosting Pro sollte SSH enthalten sein – bitte dort prüfen. Falls nicht: Bescheid geben, dann ergänze ich einen SFTP-Modus.
|
||||
|
||||
## 3. Einmalige Einrichtung bei Strato
|
||||
|
||||
1. **PHP-Version** auf 8.4 stellen (Datenbanken und Webspace › PHP-Version).
|
||||
2. **SSH-Zugang** anlegen (SFTP & SSH); Benutzername notieren. Eigenen SSH-Schlüssel hinterlegen oder einmalig `ssh-copy-id <benutzer>@ssh.strato.de`.
|
||||
3. Per SSH prüfen:
|
||||
```bash
|
||||
ssh <benutzer>@ssh.strato.de
|
||||
ls /opt | grep RZphp # PHP-CLI-Pfad, z. B. /opt/RZphp84/bin/php-cli
|
||||
/opt/RZphp84/bin/php-cli -v
|
||||
```
|
||||
4. **MySQL-Datenbank** anlegen (Datenbanken verwalten); Host, Name, Benutzer, Passwort notieren.
|
||||
5. Lokal `scripts/deploy.example.env` nach `scripts/deploy.production.env` kopieren und ausfüllen (wird nicht committet).
|
||||
6. `bash scripts/deploy.sh production setup` – legt die Ordner an und zeigt die PHP-Version.
|
||||
7. `.env.production.example` ausfüllen (u. a. `APP_KEY` via `php artisan key:generate --show`, Datenbank, SMTP/IMAP-Passwort, Tokens) und auf den Server nach `<DEPLOY_PATH>/shared/.env` kopieren (z. B. per SFTP).
|
||||
8. Erstes Deployment: `bash scripts/deploy.sh production deploy`
|
||||
9. Ersteinrichtung der Daten und erster Admin:
|
||||
```bash
|
||||
bash scripts/deploy.sh production artisan db:seed --class=ProductionSeeder --force
|
||||
bash scripts/deploy.sh production artisan make:filament-user
|
||||
```
|
||||
10. **Domain-Zielverzeichnis** (Domains › Domain verwalten › Ziel) auf `<DEPLOY_PATH>/current/public` setzen; SSL-Zertifikat aktivieren.
|
||||
11. **Cronjob** (Kundenlogin › Cronjobs), jede Minute:
|
||||
```
|
||||
/opt/RZphp84/bin/php-cli <home>/<DEPLOY_PATH>/current/artisan schedule:run
|
||||
```
|
||||
Falls Cronjobs nicht minütlich möglich sind: `FEWO_SCHEDULER_TOKEN` setzen und n8n jede Minute `GET https://…/automation/scheduler?token=…` aufrufen lassen.
|
||||
12. Überwachung: n8n alle 5 Min. `GET https://…/health/sync?token=<FEWO_HEALTH_TOKEN>` (200 = ok, 503 = Störung).
|
||||
|
||||
**Testbetrieb zuerst:** Für eine Subdomain (z. B. `test.fewo-stommer.de`) eine zweite Konfiguration `scripts/deploy.staging.env` mit eigenem `DEPLOY_PATH`, eigener Datenbank und eigenem `shared/.env` anlegen; `bash scripts/deploy.sh staging deploy`.
|
||||
|
||||
## 4. Tägliche Nutzung
|
||||
|
||||
| Aufgabe | Befehl |
|
||||
|---|---|
|
||||
| Neue Version ausliefern | `bash scripts/deploy.sh production deploy` (baut den **letzten Commit**) |
|
||||
| Zurück zur vorigen Version | `bash scripts/deploy.sh production rollback` (Migrationen bleiben bestehen) |
|
||||
| Versionen anzeigen | `bash scripts/deploy.sh production releases` |
|
||||
| Artisan auf dem Server | `bash scripts/deploy.sh production artisan about` |
|
||||
|
||||
Windows: in Git Bash ausführen; `COMPOSER_BIN="php /c/…/composer.phar"` in der `.env`-Datei des Deployments setzen, falls `composer` nicht im PATH ist.
|
||||
|
||||
## 5. Automatisch über Gitea Actions
|
||||
|
||||
- Workflow `.gitea/workflows/deploy.yml`: **Tests bei jedem Push**; **Deployment** bei Tags `v*` (z. B. `git tag v1.0.0 && git push --tags`) oder per Knopfdruck (Actions › Deploy › Run workflow, Ziel production/staging).
|
||||
- Voraussetzung: Gitea Actions aktiviert und ein **act_runner** registriert – passt gut auf den privaten Server (Docker). Anleitung: Gitea-Doku „Act Runner“.
|
||||
- Repository-Secrets: `DEPLOY_SSH_KEY` (privater Schlüssel, dessen öffentlicher Teil bei Strato hinterlegt ist), `DEPLOY_HOST`, `DEPLOY_USER`, `DEPLOY_PATH`, `DEPLOY_PHP`, `DEPLOY_URL`.
|
||||
|
||||
## 6. Getestet / offen
|
||||
|
||||
- Lokal im Testmodus (`DEPLOY_HOST=local`) erfolgreich: Build (~19 MB), Upload, Entpacken, alle Migrationen auf frischer Datenbank, `optimize`, Ersteinrichtung per `ProductionSeeder`, alle Seiten und Admin-Login liefern 200.
|
||||
- **Nicht** unter Windows prüfbar: der Symlink-Wechsel von `current` (Git Bash legt Kopien statt Symlinks an). Unter Linux (Strato) ist das Standardverhalten; der erste Lauf auf dem Testbetrieb bestätigt es – bei Fehler greift der automatische Rollback.
|
||||
- Bei Strato zu prüfen: SSH im Tarif, PHP-CLI-Pfad, ob das Domain-Ziel einem Symlink (`current`) folgt, minütliche Cronjobs.
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
Route::get('/kalender/{token}.ics', [ChannelController::class, 'feed'])->name('channels.feed')->middleware('throttle:60,1');
|
||||
Route::get('/health/sync', [ChannelController::class, 'health'])->name('health.sync');
|
||||
Route::get('/automation/scheduler', [ChannelController::class, 'scheduler'])->name('automation.scheduler')->middleware('throttle:10,1');
|
||||
Route::post('/automation/portal-mail', [ChannelController::class, 'portalMail'])
|
||||
->name('channels.portal-mail')
|
||||
->withoutMiddleware(PreventRequestForgery::class)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# Copy to scripts/deploy.production.env (or deploy.staging.env) and fill in. These files are not committed.
|
||||
|
||||
# SSH access (Strato: Kundenlogin › Datenbanken und Webspace › SFTP & SSH)
|
||||
DEPLOY_HOST=ssh.strato.de
|
||||
DEPLOY_USER=www.fewo-stommer.de
|
||||
DEPLOY_PORT=22
|
||||
# Optional: private key file (otherwise the SSH agent / default key is used)
|
||||
# DEPLOY_SSH_KEY=~/.ssh/strato_fewo
|
||||
|
||||
# Folder below the SSH start directory. The domain's target directory must be <DEPLOY_PATH>/current/public.
|
||||
DEPLOY_PATH=fewo-production
|
||||
|
||||
# PHP CLI on Strato shared hosting: /opt/RZphp<major><minor>/bin/php-cli (check with: ls /opt)
|
||||
DEPLOY_PHP=/opt/RZphp84/bin/php-cli
|
||||
|
||||
# Public address for the health check after switching (empty = no check, no automatic rollback)
|
||||
DEPLOY_URL=https://www.fewo-stommer.de
|
||||
|
||||
# Number of releases kept on the server for rollbacks
|
||||
DEPLOY_KEEP=5
|
||||
|
||||
# Local build: how Composer is called (Windows example: "php /c/path/to/composer.phar")
|
||||
# COMPOSER_BIN=composer
|
||||
@@ -0,0 +1,211 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Deployment to Strato (or any SSH host offering bash, tar and a PHP CLI) with atomic releases.
|
||||
#
|
||||
# scripts/deploy.sh <environment> setup create the folder structure on the server (once)
|
||||
# scripts/deploy.sh <environment> deploy build, upload, migrate, switch, health check (rollback on failure)
|
||||
# scripts/deploy.sh <environment> rollback switch back to the previous release
|
||||
# scripts/deploy.sh <environment> releases list releases on the server
|
||||
# scripts/deploy.sh <environment> artisan <args> run an artisan command in the active release
|
||||
#
|
||||
# Settings come from scripts/deploy.<environment>.env (not committed, see scripts/deploy.example.env)
|
||||
# or from environment variables (CI). Server layout below DEPLOY_PATH:
|
||||
#
|
||||
# releases/<timestamp>/ one folder per release (code, vendor, built assets)
|
||||
# shared/.env production settings – created by hand once
|
||||
# shared/storage/ uploads, logs, sessions, cache – survive every release
|
||||
# current -> releases/… active release; the domain's target directory is current/public
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
ENVIRONMENT="${1:?Bitte Umgebung angeben, z. B.: scripts/deploy.sh production deploy}"
|
||||
COMMAND="${2:-deploy}"
|
||||
shift $(($# >= 2 ? 2 : 1))
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
CONFIG="$ROOT/scripts/deploy.$ENVIRONMENT.env"
|
||||
if [[ -f "$CONFIG" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$CONFIG"
|
||||
fi
|
||||
|
||||
: "${DEPLOY_HOST:?DEPLOY_HOST fehlt (z. B. ssh.strato.de oder local)}"
|
||||
: "${DEPLOY_PATH:?DEPLOY_PATH fehlt (Ordner auf dem Server, z. B. fewo-production)}"
|
||||
DEPLOY_USER="${DEPLOY_USER:-}"
|
||||
DEPLOY_PORT="${DEPLOY_PORT:-22}"
|
||||
DEPLOY_PHP="${DEPLOY_PHP:-/opt/RZphp84/bin/php-cli}"
|
||||
DEPLOY_KEEP="${DEPLOY_KEEP:-5}"
|
||||
DEPLOY_URL="${DEPLOY_URL:-}"
|
||||
DEPLOY_SSH_KEY="${DEPLOY_SSH_KEY:-}"
|
||||
COMPOSER_BIN="${COMPOSER_BIN:-composer}"
|
||||
|
||||
say() { printf '\n\033[1;34m▶ %s\033[0m\n' "$*"; }
|
||||
fail() { printf '\n\033[1;31m✗ %s\033[0m\n' "$*" >&2; exit 1; }
|
||||
|
||||
# The script executed on the server. Arguments: <base path> <php binary> <command> [args…]
|
||||
remote_script() {
|
||||
cat <<'REMOTE'
|
||||
set -euo pipefail
|
||||
base="$1"; php="$2"; cmd="$3"; shift 3
|
||||
mkdir -p "$base"
|
||||
cd "$base"
|
||||
|
||||
switch_to() {
|
||||
ln -sfn "$1" current.new
|
||||
mv -Tf current.new current
|
||||
}
|
||||
|
||||
case "$cmd" in
|
||||
setup)
|
||||
mkdir -p releases shared/storage/app/public shared/storage/framework/cache/data shared/storage/framework/sessions shared/storage/framework/views shared/storage/logs
|
||||
if [[ -f shared/.env ]]; then echo "shared/.env vorhanden."; else echo "HINWEIS: Bitte $base/shared/.env anlegen (Vorlage: .env.production.example)."; fi
|
||||
echo "PHP: $("$php" -v | head -n 1)"
|
||||
;;
|
||||
receive)
|
||||
release="$1"
|
||||
mkdir -p "releases/$release"
|
||||
tar -xzf "upload-$release.tgz" -C "releases/$release"
|
||||
rm -f "upload-$release.tgz"
|
||||
;;
|
||||
activate)
|
||||
release="$1"; keep="$2"; dir="releases/$release"
|
||||
[[ -f shared/.env ]] || { echo "shared/.env fehlt – erst anlegen (siehe docs/DEPLOYMENT.md)." >&2; exit 1; }
|
||||
rm -rf "$dir/storage"
|
||||
ln -s ../../shared/storage "$dir/storage"
|
||||
ln -sfn ../../shared/.env "$dir/.env"
|
||||
mkdir -p "$dir/bootstrap/cache"
|
||||
ln -sfn ../storage/app/public "$dir/public/storage"
|
||||
(
|
||||
cd "$dir"
|
||||
"$php" artisan migrate --force --no-interaction
|
||||
"$php" artisan optimize --no-interaction
|
||||
"$php" artisan filament:optimize --no-interaction >/dev/null 2>&1 || true
|
||||
)
|
||||
readlink current > .previous_release 2>/dev/null || true
|
||||
switch_to "$dir"
|
||||
ls -1d releases/* | sort | head -n -"$keep" | xargs -r rm -rf
|
||||
echo "Aktiv: $release"
|
||||
;;
|
||||
rollback)
|
||||
active="$(readlink current 2>/dev/null || true)"
|
||||
target="$(cat .previous_release 2>/dev/null || true)"
|
||||
if [[ -z "$target" || "$target" == "$active" || ! -d "$target" ]]; then
|
||||
target="$(ls -1d releases/* | sort | grep -vx "$active" | tail -n 1 || true)"
|
||||
fi
|
||||
[[ -n "$target" && -d "$target" ]] || { echo "Keine frühere Version vorhanden." >&2; exit 1; }
|
||||
switch_to "$target"
|
||||
echo "$active" > .previous_release
|
||||
echo "Zurückgeschaltet auf: $target (Datenbank-Migrationen werden dabei nicht zurückgenommen)"
|
||||
;;
|
||||
releases)
|
||||
ls -1 releases
|
||||
echo "Aktiv: $(readlink current 2>/dev/null || echo '–')"
|
||||
;;
|
||||
artisan)
|
||||
cd current
|
||||
"$php" artisan "$@"
|
||||
;;
|
||||
*)
|
||||
echo "Unbekannter Befehl: $cmd" >&2; exit 1
|
||||
;;
|
||||
esac
|
||||
REMOTE
|
||||
}
|
||||
|
||||
run_remote() {
|
||||
if [[ "$DEPLOY_HOST" == "local" ]]; then
|
||||
bash -s -- "$DEPLOY_PATH" "$DEPLOY_PHP" "$@"
|
||||
else
|
||||
local ssh_args=(-p "$DEPLOY_PORT" -o BatchMode=yes -o ServerAliveInterval=30)
|
||||
[[ -n "$DEPLOY_SSH_KEY" ]] && ssh_args+=(-i "$DEPLOY_SSH_KEY")
|
||||
ssh "${ssh_args[@]}" "${DEPLOY_USER:+$DEPLOY_USER@}$DEPLOY_HOST" bash -s -- "$DEPLOY_PATH" "$DEPLOY_PHP" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Runs the remote script (sent via stdin) with the given command.
|
||||
remote() {
|
||||
run_remote "$@" < <(remote_script)
|
||||
}
|
||||
|
||||
# Copies the release archive to <DEPLOY_PATH>/upload-<release>.tgz on the server.
|
||||
upload() {
|
||||
local archive="$1" release="$2"
|
||||
if [[ "$DEPLOY_HOST" == "local" ]]; then
|
||||
mkdir -p "$DEPLOY_PATH"
|
||||
cp "$archive" "$DEPLOY_PATH/upload-$release.tgz"
|
||||
else
|
||||
local ssh_args=(-p "$DEPLOY_PORT" -o BatchMode=yes)
|
||||
[[ -n "$DEPLOY_SSH_KEY" ]] && ssh_args+=(-i "$DEPLOY_SSH_KEY")
|
||||
ssh "${ssh_args[@]}" "${DEPLOY_USER:+$DEPLOY_USER@}$DEPLOY_HOST" "mkdir -p '$DEPLOY_PATH' && cat > '$DEPLOY_PATH/upload-$release.tgz'" < "$archive"
|
||||
fi
|
||||
}
|
||||
|
||||
build() {
|
||||
say "Baue Version aus Git-Stand $(git -C "$ROOT" rev-parse --short HEAD)"
|
||||
if [[ -n "$(git -C "$ROOT" status --porcelain)" ]]; then
|
||||
echo "Hinweis: Nicht committete Änderungen werden NICHT ausgeliefert (gebaut wird der letzte Commit)."
|
||||
fi
|
||||
|
||||
BUILD_DIR="$(mktemp -d)"
|
||||
git -C "$ROOT" archive --format=tar HEAD | tar -x -C "$BUILD_DIR"
|
||||
(
|
||||
cd "$BUILD_DIR"
|
||||
$COMPOSER_BIN install --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progress
|
||||
npm ci --no-audit --no-fund
|
||||
npm run build
|
||||
rm -rf node_modules tests docs .gitea .github scripts storage .env.example .env.production.example .ai .claude .cursor AGENTS.md CLAUDE.md boost.json phpunit.xml
|
||||
git -C "$ROOT" rev-parse HEAD > REVISION
|
||||
)
|
||||
ARCHIVE="$BUILD_DIR.tgz"
|
||||
tar -czf "$ARCHIVE" -C "$BUILD_DIR" .
|
||||
echo "Paket: $(du -h "$ARCHIVE" | cut -f1)"
|
||||
}
|
||||
|
||||
health_check() {
|
||||
[[ -n "$DEPLOY_URL" ]] || { echo "Kein DEPLOY_URL gesetzt – Gesundheitscheck übersprungen."; return 0; }
|
||||
say "Prüfe $DEPLOY_URL/up"
|
||||
for attempt in 1 2 3 4 5; do
|
||||
if curl -fsS --max-time 15 "$DEPLOY_URL/up" > /dev/null; then
|
||||
echo "Webseite antwortet."
|
||||
return 0
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
case "$COMMAND" in
|
||||
setup)
|
||||
say "Lege Ordnerstruktur in $DEPLOY_PATH an"
|
||||
remote setup
|
||||
;;
|
||||
deploy)
|
||||
build
|
||||
RELEASE="$(date -u +%Y%m%d%H%M%S)"
|
||||
say "Übertrage Version $RELEASE"
|
||||
upload "$ARCHIVE" "$RELEASE"
|
||||
remote receive "$RELEASE"
|
||||
say "Migrieren, Caches aufwärmen, umschalten"
|
||||
remote activate "$RELEASE" "$DEPLOY_KEEP"
|
||||
if ! health_check; then
|
||||
say "Gesundheitscheck fehlgeschlagen – schalte zurück"
|
||||
remote rollback
|
||||
fail "Deployment zurückgerollt. Logs: scripts/deploy.sh $ENVIRONMENT artisan about / shared/storage/logs"
|
||||
fi
|
||||
rm -rf "$BUILD_DIR" "$ARCHIVE"
|
||||
say "Fertig: Version $RELEASE ist live."
|
||||
;;
|
||||
rollback)
|
||||
remote rollback
|
||||
health_check || fail "Auch die vorige Version antwortet nicht – bitte Logs prüfen."
|
||||
;;
|
||||
releases)
|
||||
remote releases
|
||||
;;
|
||||
artisan)
|
||||
remote artisan "$@"
|
||||
;;
|
||||
*)
|
||||
fail "Unbekannter Befehl: $COMMAND (setup | deploy | rollback | releases | artisan …)"
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchedulerEndpointTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_scheduler_endpoint_is_disabled_without_token(): void
|
||||
{
|
||||
$this->get('/automation/scheduler')->assertNotFound();
|
||||
$this->get('/automation/scheduler?token=irgendwas')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_scheduler_runs_with_the_configured_token(): void
|
||||
{
|
||||
config(['fewo.scheduler_token' => 'geheim']);
|
||||
|
||||
$this->get('/automation/scheduler?token=falsch')->assertNotFound();
|
||||
$this->getJson('/automation/scheduler?token=geheim')->assertOk()->assertJsonStructure(['ran_at', 'output']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user