Drop app_local.php from production and show the mail transport in polls remind
app_local.php takes precedence over config/.env, so a copy made from an older template forced the file transport and reminders never left the server. Release package and Docker image now ship without it; app.php reads the database from DATABASE_URL (SQLite default). app_local.example.php keeps development defaults only. polls remind prints the transport and warns when SMTP_HOST is set but SMTP is not used. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f21aead039
commit
7fa33bbbdd
10 files changed
+65
-50
No files matched your search
@@ -85,9 +85,9 @@ jobs:
|
||||
index.php .htaccess composer.json composer.lock | tar -x -C build
|
||||
cd "build/$NAME"
|
||||
rm -f bin/cake.bat bin/bash_completion.sh
|
||||
# --no-scripts: the installer must not bake a random salt into app_local.php (SECURITY_SALT comes from config/.env)
|
||||
# --no-scripts: no app_local.php in the package; everything comes from config/.env (see app_local.example.php)
|
||||
composer install --no-dev --no-scripts --no-interaction --no-progress --prefer-dist --optimize-autoloader
|
||||
cp config/app_local.example.php config/app_local.php
|
||||
rm -f config/app_local.example.php
|
||||
mkdir -p tmp/cache/models tmp/cache/persistent tmp/cache/views tmp/sessions logs data
|
||||
printf '%s\n' "$VERSION" > VERSION
|
||||
cd ../..
|
||||
|
||||
@@ -62,7 +62,7 @@ passende Dokument und pflegt es danach** (Details zu Verhalten, Settings, Tests
|
||||
## Architektur in Kürze
|
||||
|
||||
```
|
||||
config/ app.php (Block 'Plenario'), app_local.php (gitignored), .env.example,
|
||||
config/ app.php (Block 'Plenario'), app_local.php (nur lokal, gitignored; Produktion nur .env), .env.example,
|
||||
routes.php (alle Routen benannt, KEINE Fallbacks), Migrations/ (Schema = einzige Quelle der Wahrheit)
|
||||
src/
|
||||
Controller/ AppController (Basis), Home, Admin (+ AdminAppController), Slides, Participate, Embed, Error
|
||||
|
||||
+2
-3
@@ -15,11 +15,10 @@ FROM base AS build
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||
WORKDIR /app
|
||||
COPY composer.json composer.lock ./
|
||||
# --no-scripts: the installer must not bake a random salt into app_local.php (SECURITY_SALT comes at runtime)
|
||||
# --no-scripts: no app_local.php in the image; everything comes from the environment at runtime
|
||||
RUN composer install --no-dev --no-scripts --no-progress --prefer-dist --optimize-autoloader
|
||||
COPY . .
|
||||
RUN composer dump-autoload --no-dev --optimize \
|
||||
&& cp config/app_local.example.php config/app_local.php
|
||||
RUN composer dump-autoload --no-dev --optimize
|
||||
|
||||
FROM base
|
||||
WORKDIR /app
|
||||
|
||||
@@ -372,6 +372,10 @@ return [
|
||||
'default' => [
|
||||
'className' => Connection::class,
|
||||
'driver' => Sqlite::class,
|
||||
// Default: SQLite file in data/. For MySQL/MariaDB/PostgreSQL set DATABASE_URL, e.g.
|
||||
// mysql://user:pass@localhost/plenario?encoding=utf8mb4
|
||||
'database' => ROOT . DS . 'data' . DS . 'plenario.sqlite',
|
||||
'url' => env('DATABASE_URL', null),
|
||||
'persistent' => false,
|
||||
'timezone' => 'UTC',
|
||||
|
||||
@@ -415,6 +419,8 @@ return [
|
||||
'test' => [
|
||||
'className' => Connection::class,
|
||||
'driver' => Sqlite::class,
|
||||
'database' => ROOT . DS . 'tmp' . DS . 'tests.sqlite',
|
||||
'url' => env('DATABASE_TEST_URL', null),
|
||||
'persistent' => false,
|
||||
'timezone' => 'UTC',
|
||||
'encoding' => 'utf8',
|
||||
|
||||
@@ -1,65 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* Local configuration overrides for Plenario.
|
||||
* Development defaults for PlenarIO. Only for local work: `composer install` copies this file to
|
||||
* config/app_local.php (gitignored, never overwritten afterwards).
|
||||
*
|
||||
* Copy this file to config/app_local.php (done automatically by
|
||||
* `composer install`) and adjust it. app_local.php is NOT committed.
|
||||
*
|
||||
* Every value can alternatively be provided via environment variables.
|
||||
* Production does NOT use app_local.php. Everything is configured in config/.env or real environment
|
||||
* variables (see config/.env.example); config/app.php reads them. The release package and the Docker image
|
||||
* ship without app_local.php on purpose: it takes precedence over the environment, so a stale copy would
|
||||
* silently override settings (e.g. force the file mail transport).
|
||||
*/
|
||||
|
||||
use Cake\Database\Driver\Sqlite;
|
||||
use function Cake\Core\env;
|
||||
|
||||
return [
|
||||
'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),
|
||||
|
||||
'App' => [
|
||||
// Absolute base URL used for links in e-mails, e.g. https://plenario.example.org
|
||||
'fullBaseUrl' => env('APP_FULL_BASE_URL', 'http://localhost:8765'),
|
||||
],
|
||||
|
||||
'Security' => [
|
||||
// Replaced by a random value during `composer install`
|
||||
'salt' => env('SECURITY_SALT', '__SALT__'),
|
||||
],
|
||||
|
||||
'Plenario' => [
|
||||
'captcha' => [
|
||||
// 'none' | 'math' | 'recaptcha'
|
||||
'type' => env('CAPTCHA_TYPE', 'math'),
|
||||
'recaptcha' => [
|
||||
'siteKey' => env('RECAPTCHA_SITE_KEY', ''),
|
||||
'secretKey' => env('RECAPTCHA_SECRET_KEY', ''),
|
||||
],
|
||||
],
|
||||
// Shows the admin link on the confirmation page. Development only!
|
||||
'showAdminLinkAfterCreate' => filter_var(env('SHOW_ADMIN_LINK_AFTER_CREATE', env('DEBUG', true)), FILTER_VALIDATE_BOOLEAN),
|
||||
],
|
||||
|
||||
'Datasources' => [
|
||||
/*
|
||||
* Default: SQLite file in data/. For MySQL/MariaDB/PostgreSQL set
|
||||
* DATABASE_URL, e.g.
|
||||
* mysql://user:pass@localhost/plenario?encoding=utf8mb4
|
||||
*/
|
||||
'default' => [
|
||||
'driver' => Sqlite::class,
|
||||
'database' => ROOT . DS . 'data' . DS . 'plenario.sqlite',
|
||||
'url' => env('DATABASE_URL', null),
|
||||
],
|
||||
'test' => [
|
||||
'driver' => Sqlite::class,
|
||||
'database' => ROOT . DS . 'tmp' . DS . 'tests.sqlite',
|
||||
'url' => env('DATABASE_TEST_URL', null),
|
||||
],
|
||||
],
|
||||
|
||||
'EmailTransport' => [
|
||||
/*
|
||||
* Local default: mails are written as .eml files to tmp/mails/.
|
||||
* For real delivery set SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD and SMTP_TLS
|
||||
* (see config/.env.example); then this override is skipped.
|
||||
*/
|
||||
// Mails are written as .eml files to tmp/mails/ unless an SMTP server is configured
|
||||
'default' => env('SMTP_HOST') || env('EMAIL_TRANSPORT_DEFAULT_URL') ? [] : [
|
||||
'className' => \App\Mailer\Transport\FileTransport::class,
|
||||
],
|
||||
|
||||
@@ -5,7 +5,7 @@ Verzeichnisstruktur, Klassen und Tabellen im Detail.
|
||||
```
|
||||
config/
|
||||
app.php Defaults inkl. Block 'Plenario' (Captcha, Throttle, Polling) und Cache 'throttle'
|
||||
app_local.example.php Vorlage für app_local.php (SQLite, FileTransport) – app_local.php ist gitignored
|
||||
app_local.example.php Dev-Defaults (debug, FileTransport), von `composer install` nach app_local.php kopiert (gitignored, nur lokal, nie in Produktion)
|
||||
.env.example Alle Umgebungsvariablen (config/.env wird optional geladen)
|
||||
routes.php Alle Routen benannt, KEINE Fallback-Routen
|
||||
Migrations/ Schema (einzige Quelle der Wahrheit, auch für Tests)
|
||||
|
||||
@@ -11,11 +11,11 @@ Alles andere ist optional und hat einen Standardwert. In der Spalte „Standard
|
||||
|
||||
| Variable | Pflicht? | Standard | Bedeutung |
|
||||
|---|---|---|---|
|
||||
| `DEBUG` | Produktion: ja | `false` (per Composer erzeugte `app_local.php`: `true`) | In Produktion auf `false` setzen, sonst werden Admin-Links direkt angezeigt |
|
||||
| `DEBUG` | Produktion: ja | `false` (lokal: die von Composer erzeugte `app_local.php` setzt `true`) | In Produktion `false` lassen, sonst werden Admin-Links direkt angezeigt |
|
||||
| `APP_FULL_BASE_URL` | Produktion: ja | – (lokal `http://localhost:8765`) | Öffentliche URL inkl. `https://`, wird für Links in E-Mails gebraucht. In Produktion wird außerdem der Host-Header dagegen geprüft |
|
||||
| `SECURITY_SALT` | ja | – (lokal wird er von Composer erzeugt) | Langer Zufallswert. **Nicht nachträglich ändern** – damit werden Admin-Tokens verschlüsselt und Teilnehmer-IDs gehasht |
|
||||
| `DATABASE_URL` | optional | leer = SQLite in `data/` | Sonst z. B. `mysql://user:pw@host/plenario?encoding=utf8mb4` oder `postgres://user:pw@host/plenario` |
|
||||
| `SMTP_HOST` | Produktion: ja | leer = Mails nur als Datei in `tmp/mails/` | Mailserver. Ohne ihn kommt der Admin-Link nie bei den Nutzenden an |
|
||||
| `SMTP_HOST` | Produktion: ja | leer = Mails nur als Datei in `tmp/mails/` (per `app_local.php`), sonst PHP `mail()` | Mailserver. Ohne ihn kommt der Admin-Link nie bei den Nutzenden an. **Achtung:** Eine `config/app_local.php` hat Vorrang vor `.env`; ein `FileTransport` darin (ältere Vorlage) überschreibt SMTP, die Mails landen dann nur in `tmp/mails/`. Auf Servern gehört keine `app_local.php` hin, sie ist nur für die lokale Entwicklung. `bin/cake polls remind` zeigt den verwendeten Transport an und warnt davor |
|
||||
| `SMTP_PORT` | optional | `587` | Port 465 nutzt automatisch SSL |
|
||||
| `SMTP_USER`, `SMTP_PASSWORD` | optional | leer | Zugangsdaten, falls der Mailserver sie verlangt |
|
||||
| `SMTP_TLS` | optional | `true` | `true` = STARTTLS, `false` = unverschlüsselt |
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ sowie [Composer](https://getcomposer.org/).
|
||||
```bash
|
||||
git clone https://gitea.gnilebein.de/gnilebein/Plenario.git
|
||||
cd Plenario
|
||||
composer install # legt config/app_local.php an (SQLite, Mails als Datei)
|
||||
composer install # legt config/app_local.php an (nur Dev-Defaults: debug, Mails als Datei)
|
||||
bin/cake migrations migrate # erstellt data/plenario.sqlite
|
||||
bin/cake server -p 8765 # http://localhost:8765
|
||||
```
|
||||
|
||||
+2
-2
@@ -53,7 +53,7 @@ Beispiel: `docker-compose.yml`. Image und App-Paket entstehen nur bei Releases (
|
||||
|
||||
**Releases (SemVer):** `.gitea/workflows/release.yml` läuft nur bei Tags `vMAJOR.MINOR.PATCH[-suffix]` (kein Build bei normalen
|
||||
Pushes). Job `test` (PHPUnit + phpcs) gatet `package` und `image`. `package` baut `plenario-<version>.tar.gz` (git archive des Tags,
|
||||
`composer install --no-dev --no-scripts`, `app_local.php` aus dem Example, leere `tmp/`/`logs/`/`data/`, Datei `VERSION`; nur per Whitelist: bin, config, plugins, resources, src, templates, webroot, index.php, .htaccess, composer-Dateien;
|
||||
`composer install --no-dev --no-scripts`, **ohne** `app_local.php` (nur `.env`), leere `tmp/`/`logs/`/`data/`, Datei `VERSION`; nur per Whitelist: bin, config, plugins, resources, src, templates, webroot, index.php, .htaccess, composer-Dateien;
|
||||
kein tests/CI/Docker/README) + `SHA256SUMS` und hängt sie an das Gitea-Release (wird angelegt bzw. aktualisiert, Changelog = Commit-Betreffs
|
||||
seit dem letzten Tag, Suffix = Pre-Release). `image` pusht `:<version>`, `:<major>.<minor>`, `:<major>` und `:latest` (die
|
||||
beiden letzten nicht bei Pre-Releases bzw. `v0.`) in die Gitea-Registry (Variablen `DOCKER_REPO`, `IMAGE_NAME`, Secret `PAT`).
|
||||
@@ -63,6 +63,6 @@ Wer das Paket ändert (z. B. weitere Dateien ausschließen), pflegt den Schritt
|
||||
|
||||
Produktiv auf dem Server in `config/.env`: `DEBUG=false`, `APP_FULL_BASE_URL`, `SECURITY_SALT`, SMTP
|
||||
(`SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`, `SMTP_TLS` – einzelne Variablen statt URL; `EMAIL_TRANSPORT_DEFAULT_URL` geht weiter als Altlast).
|
||||
Ohne `DEBUG=false` steht die per Composer erzeugte `app_local.php` auf debug=true und zeigt Admin-Links direkt an.
|
||||
Produktion kennt keine `app_local.php`: Paket und Docker-Image liefern sie nicht mit, `app.php` liest alles aus der Umgebung (Standard `DEBUG=false`). Eine `app_local.php` hätte Vorrang vor `.env` und überschreibt still einzelne Werte (z. B. den Mail-Transport); auf bestehenden Servern aus der Zeit vor diesem Stand löschen.
|
||||
Document-Root zeigt idealerweise auf `webroot/`; liegt die App direkt im Document-Root (z. B. `public_html`),
|
||||
leiten `.htaccess` + `index.php` im Projektroot alles nach `webroot/` weiter.
|
||||
@@ -9,6 +9,10 @@ use Cake\Console\Arguments;
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\Console\ConsoleOptionParser;
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\Mailer\Transport\SmtpTransport;
|
||||
use Cake\Mailer\TransportFactory;
|
||||
use ReflectionClass;
|
||||
use function Cake\Core\env;
|
||||
|
||||
/**
|
||||
* Mails the owners of polls that expire soon (POLL_REMINDER_DAYS before the end), once per poll.
|
||||
@@ -82,6 +86,10 @@ class PollsRemindCommand extends PollsCommand
|
||||
$due = $this->polls()->find('reminderDue')->orderBy(['Polls.id' => 'ASC'])->all()->toList();
|
||||
}
|
||||
|
||||
if (!$dryRun && $due !== []) {
|
||||
$io->out($this->describeTransport());
|
||||
}
|
||||
|
||||
$sent = 0;
|
||||
$failed = 0;
|
||||
foreach ($due as $poll) {
|
||||
@@ -116,4 +124,36 @@ class PollsRemindCommand extends PollsCommand
|
||||
|
||||
return $failed === 0 ? static::CODE_SUCCESS : static::CODE_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* One line about the mail transport in use (never the password), so a misconfiguration is visible at once.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function describeTransport(): string
|
||||
{
|
||||
$transport = TransportFactory::get('default');
|
||||
$config = $transport->getConfig();
|
||||
$class = (new ReflectionClass($transport))->getShortName();
|
||||
if ($transport instanceof SmtpTransport) {
|
||||
return __(
|
||||
'Mail-Transport: {0} {1}:{2}, Benutzer {3}, TLS {4}',
|
||||
$class,
|
||||
$config['host'],
|
||||
$config['port'],
|
||||
$config['username'] ?? __('(keiner)'),
|
||||
$config['tls'] ? __('ja') : __('nein'),
|
||||
);
|
||||
}
|
||||
|
||||
if (trim((string)env('SMTP_HOST', '')) !== '') {
|
||||
return __(
|
||||
'WARNUNG: SMTP_HOST ist gesetzt, aber der Transport ist {0}. Vermutlich überschreibt config/app_local.php ' .
|
||||
'den Transport (auf Servern config/app_local.php löschen, Konfiguration nur über .env). Es wird nichts verschickt.',
|
||||
$class,
|
||||
);
|
||||
}
|
||||
|
||||
return __('Mail-Transport: {0} (kein SMTP, SMTP_HOST nicht gesetzt)', $class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user