trypost/docker/postgres-init.sh
André Dantas 4ce5c9173f feat(docker): add multi-stage Dockerfile with dev and production targets
Introduces a self-contained Docker build under docker/ that boots the
full Laravel + Vite + Reverb + Horizon + scheduler stack inside a
single container.

The Dockerfile exposes two targets sharing a common system-base layer
(PHP 8.4-FPM Alpine + Postgres/Redis/intl/sockets/redis extensions):

  - dev: bind-mount source at runtime, runs Vite via supervisord, hot
    reloads PHP via opcache.validate_timestamps=1, UID/GID build args
    align container writes with the host user.

  - production: ships the prebuilt application — composer --no-dev,
    npm run build + build:ssr, wayfinder TS pre-generated, OpCache
    hardened, fixed UID 1000.

Sidecar configs (nginx, php.{dev,prod}.ini, supervisord.{dev,prod}.conf,
entrypoint, postgres-init for the test DB) live next to the Dockerfile
so the build context is self-describing. The entrypoint is idempotent
and handles APP_KEY generation, migrations, storage:link, Passport
keys, Wayfinder regen, and dependency reinstall on every boot.
2026-05-12 23:44:55 -03:00

11 lines
442 B
Bash
Executable file

#!/bin/sh
# Creates the test database expected by phpunit.xml on first Postgres boot.
# Postgres-alpine runs every *.sh / *.sql in /docker-entrypoint-initdb.d/ once,
# right after the primary database (POSTGRES_DB) is initialized.
set -e
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" <<-EOSQL
CREATE DATABASE trypost_test;
GRANT ALL PRIVILEGES ON DATABASE trypost_test TO "${POSTGRES_USER}";
EOSQL