Files
website/docker/app/entrypoint.sh
Andrew dfdef3d7f4 feat: docker compose dev environment
Replaces the bare-metal `composer run dev` workflow with a fully
containerized 9-service stack orchestrated by docker compose. Single
command brings up the full app — three subdomains (marketing /
account / admin) reachable via Traefik with TLS, MariaDB + Valkey
+ Mailpit + Vite HMR + Horizon + scheduler all wired in.

Components:
- docker-compose.yml: traefik, app (php-fpm), web (nginx), mariadb,
  valkey, mailpit, vite, horizon, scheduler.
- docker/: Dockerfiles, nginx config, entrypoint scripts.
- Makefile: convenience targets (up / down / logs / shell / migrate
  / seed / test / pint / etc).
- .env.docker.example: template for Docker-stack environment vars
  (separate from website/.env so bare-metal devs aren't disrupted).
- website/vite.config.ts: server.host / origin / hmr / cors hooks
  driven by VITE_HOST / VITE_ORIGIN / VITE_HMR_HOST so the same
  config serves both bare-metal and Docker.
- website/bootstrap/app.php: redirectGuestsTo() now uses
  request()->getScheme() so http: dev hosts don't get force-https
  redirects.
- composer.json: drops laravel/sail (replaced by this stack).
- docs/superpowers/specs/2026-04-25-docker-compose-dev-environment-design.md:
  full design spec.

Bare-metal `composer run dev` workflow stays usable for anyone who
prefers it — Docker stack reads .env.docker, doesn't fight
website/.env.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 22:10:53 -04:00

56 lines
2.0 KiB
Bash

#!/bin/sh
set -e
# ==============================================================================
# EZSCALE app container entrypoint
# Used by `app`, `horizon`, and `scheduler` services. Idempotent.
# ==============================================================================
cd /var/www/html
# Wait for MariaDB. depends_on: condition: service_healthy already gates this,
# but the belt-and-braces loop is cheap and survives healthcheck regressions.
if [ -n "${DB_HOST:-}" ]; then
echo "[entrypoint] waiting for ${DB_HOST}:${DB_PORT:-3306}..."
until php -r "new PDO('mysql:host=${DB_HOST};port=${DB_PORT:-3306}', '${DB_USERNAME}', '${DB_PASSWORD}');" 2>/dev/null; do
sleep 1
done
echo "[entrypoint] mariadb is up."
fi
# Bootstrap .env on first boot. We bind-mount the website/ source, so .env may
# already exist from a previous bare-metal `composer run dev` workflow.
if [ ! -f .env ]; then
if [ -f /var/www/html/.env.docker ]; then
echo "[entrypoint] copying .env.docker -> .env"
cp /var/www/html/.env.docker .env
elif [ -f .env.example ]; then
echo "[entrypoint] copying .env.example -> .env (fallback)"
cp .env.example .env
fi
fi
# Vendor dir bootstrapping — first-clone convenience. Skipped if already present.
if [ ! -d vendor ] || [ ! -f vendor/autoload.php ]; then
echo "[entrypoint] vendor/ missing; running composer install"
composer install --no-interaction --prefer-dist --no-progress
fi
# Generate APP_KEY if blank. `key:generate` writes to .env in place.
if ! grep -qE '^APP_KEY=base64:' .env; then
echo "[entrypoint] generating APP_KEY"
php artisan key:generate --force --no-interaction
fi
# Run migrations only when this container is the `app` (php-fpm) role.
# Horizon and scheduler share this image but skip migrations to avoid races.
case "$1" in
php-fpm|php-fpm*)
echo "[entrypoint] running migrations"
php artisan migrate --force --no-interaction || true
php artisan storage:link || true
;;
esac
exec "$@"