diff --git a/.env b/.env index 827e38a..6faaa2b 100644 --- a/.env +++ b/.env @@ -33,7 +33,7 @@ DEFAULT_URI=http://localhost # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4" -DATABASE_URL="postgresql://buckets:buckets@db:5432/buckets?serverVersion=16&charset=utf8" +DATABASE_URL="postgresql://buckets:buckets@database:5432/buckets?serverVersion=16&charset=utf8" ###< doctrine/doctrine-bundle ### ###> nelmio/cors-bundle ### diff --git a/Dockerfile b/Dockerfile index 57c6f28..1ab492a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,7 @@ RUN <<-EOF apcu \ intl \ opcache \ + pdo_pgsql \ zip rm -rf /var/lib/apt/lists/* EOF diff --git a/compose.override.yaml b/compose.override.yaml index 5e4ca2c..e3b6612 100644 --- a/compose.override.yaml +++ b/compose.override.yaml @@ -15,7 +15,12 @@ services: # If you develop on Mac or Windows you can remove the vendor/ directory # from the bind-mount for better performance by enabling the next line: #- /app/vendor + ports: + # HTTP-only in dev — no 443 mapping (SERVER_NAME ":80" means nothing listens there). + - "${HTTP_PORT:-8100}:80" environment: + # HTTP-only in dev (no TLS, no HTTP→HTTPS redirect). App served on http://localhost:8100. + SERVER_NAME: ":80" FRANKENPHP_WORKER_CONFIG: watch FRANKENPHP_SITE_CONFIG: hot_reload MERCURE_EXTRA_DIRECTIVES: demo diff --git a/compose.prod.yaml b/compose.prod.yaml index a3e2163..1c777c3 100644 --- a/compose.prod.yaml +++ b/compose.prod.yaml @@ -6,6 +6,10 @@ services: build: context: . target: frankenphp_prod + ports: + - "${HTTP_PORT:-80}:80" + - "${HTTPS_PORT:-443}:443" + - "${HTTP3_PORT:-443}:443/udp" environment: APP_SECRET: ${APP_SECRET} MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET} diff --git a/compose.yaml b/compose.yaml index f1f05c8..09d7e1b 100644 --- a/compose.yaml +++ b/compose.yaml @@ -8,33 +8,37 @@ services: MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!} MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!} # Run "composer require symfony/orm-pack" to install and configure Doctrine ORM - DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}&charset=${POSTGRES_CHARSET:-utf8} + DATABASE_URL: postgresql://${POSTGRES_USER:-buckets}:${POSTGRES_PASSWORD:-buckets}@database:5432/${POSTGRES_DB:-buckets}?serverVersion=${POSTGRES_VERSION:-16}&charset=${POSTGRES_CHARSET:-utf8} # Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure} MERCURE_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}:${HTTPS_PORT:-443}/.well-known/mercure} MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!} - ###> dunglas/symfony-docker ### - # Next lines are only used during initial installation - # This block will remove itself after the installation - SYMFONY_VERSION: ${SYMFONY_VERSION:-} - STABILITY: ${STABILITY:-stable} - ###< dunglas/symfony-docker ### volumes: - caddy_data:/data - caddy_config:/config + # Ports are declared per-environment: compose.override.yaml (dev, HTTP-only) + # and compose.prod.yaml (prod, HTTPS). Keeps each env from publishing ports + # nothing listens on. + depends_on: + database: + condition: service_healthy + + database: + image: postgres:16-alpine + environment: + POSTGRES_DB: ${POSTGRES_DB:-buckets} + POSTGRES_USER: ${POSTGRES_USER:-buckets} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-buckets} + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-buckets} -d ${POSTGRES_DB:-buckets}"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s + volumes: + - database_data:/var/lib/postgresql/data ports: - - name: http - target: 80 - published: ${HTTP_PORT:-80} - protocol: tcp - - name: https - target: 443 - published: ${HTTPS_PORT:-443} - protocol: tcp - - name: http3 - target: 443 - published: ${HTTP3_PORT:-443} - protocol: udp + - "${DB_PORT:-5433}:5432" # Mercure is installed as a Caddy module, prevent the Flex recipe from installing another service ###> symfony/mercure-bundle ### @@ -43,5 +47,6 @@ services: volumes: caddy_data: caddy_config: + database_data: ###> symfony/mercure-bundle ### ###< symfony/mercure-bundle ### diff --git a/frankenphp/docker-entrypoint.sh b/frankenphp/docker-entrypoint.sh index a73124d..8291910 100644 --- a/frankenphp/docker-entrypoint.sh +++ b/frankenphp/docker-entrypoint.sh @@ -2,32 +2,6 @@ set -e if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then - ###> dunglas/symfony-docker ### - # Install the project the first time PHP is started - # This block will remove itself after the installation - if [ "$(cat composer.json)" = '{}' ]; then - rm -Rf tmp/ - composer create-project "symfony/skeleton $SYMFONY_VERSION" tmp --stability="$STABILITY" --prefer-dist --no-progress --no-interaction --no-install - - cd tmp - cp -Rp . .. - cd - - rm -Rf tmp/ - - composer require "php:>=$PHP_VERSION" - composer config --json extra.symfony.docker 'true' - - # Remove the project install block from this script and the compose.yaml - sed -i '/^\t###> dunglas\/symfony-docker ###/,/^\t###< dunglas\/symfony-docker ###/d' frankenphp/docker-entrypoint.sh - sed -i '/###> dunglas\/symfony-docker ###/,/###< dunglas\/symfony-docker ###/d' compose.yaml - - if grep -q ^DATABASE_URL= .env; then - echo 'To finish the installation please press Ctrl+C to stop Docker Compose and run: docker compose up --build --wait' - sleep infinity - fi - fi - ###< dunglas/symfony-docker ### - if [ -z "$(ls -A 'vendor/' 2>/dev/null)" ]; then composer install --prefer-dist --no-progress --no-interaction fi diff --git a/shell.nix b/shell.nix index 586d816..a4b5711 100644 --- a/shell.nix +++ b/shell.nix @@ -15,7 +15,7 @@ pkgs.mkShell { podman-compose # Database client (for direct DB access) - mariadb.client + postgresql # Utilities git @@ -28,22 +28,25 @@ pkgs.mkShell { export GROUP_ID=$(id -g) export PODMAN_USERNS=keep-id - # Compose file location - COMPOSE_FILE="$PWD/docker/dev/docker-compose.yml" + # Compose files (symfony-docker convention: root compose.yaml + compose.override.yaml). + # Both must be passed explicitly so the dev override is merged. + # NOTE: $COMPOSE is invoked unquoted (word-split into args) — assumes the repo path + # contains no spaces. Fine here; would break if checked out under a path with spaces. + COMPOSE="podman-compose -f $PWD/compose.yaml -f $PWD/compose.override.yaml" # =================== # ALIASES # =================== - alias pc='podman-compose -f $COMPOSE_FILE' + alias pc="$COMPOSE" # =================== # DEV COMMANDS # =================== dev-up() { echo "Starting services..." - PODMAN_USERNS=keep-id podman-compose -f $COMPOSE_FILE up -d "$@" + PODMAN_USERNS=keep-id $COMPOSE up -d "$@" echo "" - podman-compose -f $COMPOSE_FILE ps + $COMPOSE ps echo "" echo "App available at: http://localhost:8100" } @@ -51,46 +54,46 @@ pkgs.mkShell { dev-down() { if [[ "$1" == "-v" ]]; then echo "Stopping services and removing volumes..." - podman-compose -f $COMPOSE_FILE down -v + $COMPOSE down -v else echo "Stopping services..." - podman-compose -f $COMPOSE_FILE down + $COMPOSE down fi } dev-restart() { echo "Restarting services..." - podman-compose -f $COMPOSE_FILE restart "$@" + $COMPOSE restart "$@" } dev-rebuild() { echo "Rebuilding services (down -v + up)..." - podman-compose -f $COMPOSE_FILE down -v - PODMAN_USERNS=keep-id podman-compose -f $COMPOSE_FILE up -d "$@" + $COMPOSE down -v + PODMAN_USERNS=keep-id $COMPOSE up -d "$@" echo "" - podman-compose -f $COMPOSE_FILE ps + $COMPOSE ps echo "" echo "App available at: http://localhost:8100" } dev-logs() { - podman-compose -f $COMPOSE_FILE logs -f app "$@" + $COMPOSE logs -f php "$@" } dev-logs-db() { - podman-compose -f $COMPOSE_FILE logs -f db "$@" + $COMPOSE logs -f database "$@" } dev-shell() { - podman-compose -f $COMPOSE_FILE exec app sh + $COMPOSE exec php sh } dev-console() { - podman-compose -f $COMPOSE_FILE exec app php bin/console "$@" + $COMPOSE exec php php bin/console "$@" } dev-composer() { - podman-compose -f $COMPOSE_FILE exec app composer "$@" + $COMPOSE exec php composer "$@" } # =================== @@ -147,9 +150,8 @@ pkgs.mkShell { echo " base-build Build and push image" echo "" echo "Services:" - echo " app Symfony + Vite http://localhost:8100" - echo " db MariaDB localhost:3307" - echo " mailhog Web UI http://localhost:8026" + echo " php Symfony/FrankenPHP http://localhost:8100" + echo " database Postgres 16 localhost:5433" echo "" ''; }