54 lines
1.4 KiB
Bash
Executable File
54 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
if [[ ! -f .env ]]; then
|
|
cp .env.example .env
|
|
echo "Created .env from .env.example. Edit secrets before production use."
|
|
fi
|
|
|
|
echo "=== build and start database/app ==="
|
|
docker compose up -d --build db app
|
|
|
|
echo "=== wait for database ==="
|
|
attempt=1
|
|
max_attempts=60
|
|
until docker compose exec -T app php -r '
|
|
$host = getenv("DB_HOST") ?: "db";
|
|
$port = (int)(getenv("DB_PORT") ?: 3306);
|
|
$database = getenv("DB_DATABASE") ?: "domovoy";
|
|
$username = getenv("DB_USERNAME") ?: "domovoy";
|
|
$password = getenv("DB_PASSWORD") ?: "domovoy";
|
|
|
|
try {
|
|
new PDO(
|
|
sprintf("mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4", $host, $port, $database),
|
|
$username,
|
|
$password,
|
|
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
|
);
|
|
exit(0);
|
|
} catch (Throwable $e) {
|
|
fwrite(STDERR, $e->getMessage() . PHP_EOL);
|
|
exit(1);
|
|
}
|
|
' >/dev/null 2>&1; do
|
|
if (( attempt >= max_attempts )); then
|
|
echo "Database did not become ready after ${max_attempts} attempts" >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
attempt=$((attempt + 1))
|
|
done
|
|
|
|
echo "=== run database migrations ==="
|
|
docker compose exec -T app php vendor/bin/phinx migrate
|
|
|
|
echo "=== start web and worker ==="
|
|
docker compose up -d --build web worker
|
|
|
|
port="$(grep -E '^DOMOVOY_HTTP_PORT=' .env | tail -n 1 | cut -d= -f2- || true)"
|
|
port="${port:-8080}"
|
|
|
|
echo "=== ready ==="
|
|
echo "Open http://localhost:${port}"
|