28 - Configure postgres, ports and podman dev

This commit is contained in:
myrmidex 2026-06-15 00:57:22 +02:00
parent 9e2f056fff
commit 4e9f4ad449
7 changed files with 57 additions and 66 deletions

2
.env
View file

@ -33,7 +33,7 @@ DEFAULT_URI=http://localhost
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db" # 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=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="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 ### ###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ### ###> nelmio/cors-bundle ###

View file

@ -27,6 +27,7 @@ RUN <<-EOF
apcu \ apcu \
intl \ intl \
opcache \ opcache \
pdo_pgsql \
zip zip
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
EOF EOF

View file

@ -15,7 +15,12 @@ services:
# If you develop on Mac or Windows you can remove the vendor/ directory # 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: # from the bind-mount for better performance by enabling the next line:
#- /app/vendor #- /app/vendor
ports:
# HTTP-only in dev — no 443 mapping (SERVER_NAME ":80" means nothing listens there).
- "${HTTP_PORT:-8100}:80"
environment: 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_WORKER_CONFIG: watch
FRANKENPHP_SITE_CONFIG: hot_reload FRANKENPHP_SITE_CONFIG: hot_reload
MERCURE_EXTRA_DIRECTIVES: demo MERCURE_EXTRA_DIRECTIVES: demo

View file

@ -6,6 +6,10 @@ services:
build: build:
context: . context: .
target: frankenphp_prod target: frankenphp_prod
ports:
- "${HTTP_PORT:-80}:80"
- "${HTTPS_PORT:-443}:443"
- "${HTTP3_PORT:-443}:443/udp"
environment: environment:
APP_SECRET: ${APP_SECRET} APP_SECRET: ${APP_SECRET}
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET} MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}

View file

@ -8,33 +8,37 @@ services:
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!} MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
MERCURE_SUBSCRIBER_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 # 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 # Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure} 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_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}:${HTTPS_PORT:-443}/.well-known/mercure}
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!} 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: volumes:
- caddy_data:/data - caddy_data:/data
- caddy_config:/config - 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: ports:
- name: http - "${DB_PORT:-5433}:5432"
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
# Mercure is installed as a Caddy module, prevent the Flex recipe from installing another service # Mercure is installed as a Caddy module, prevent the Flex recipe from installing another service
###> symfony/mercure-bundle ### ###> symfony/mercure-bundle ###
@ -43,5 +47,6 @@ services:
volumes: volumes:
caddy_data: caddy_data:
caddy_config: caddy_config:
database_data:
###> symfony/mercure-bundle ### ###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ### ###< symfony/mercure-bundle ###

View file

@ -2,32 +2,6 @@
set -e set -e
if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then 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 if [ -z "$(ls -A 'vendor/' 2>/dev/null)" ]; then
composer install --prefer-dist --no-progress --no-interaction composer install --prefer-dist --no-progress --no-interaction
fi fi

View file

@ -15,7 +15,7 @@ pkgs.mkShell {
podman-compose podman-compose
# Database client (for direct DB access) # Database client (for direct DB access)
mariadb.client postgresql
# Utilities # Utilities
git git
@ -28,22 +28,25 @@ pkgs.mkShell {
export GROUP_ID=$(id -g) export GROUP_ID=$(id -g)
export PODMAN_USERNS=keep-id export PODMAN_USERNS=keep-id
# Compose file location # Compose files (symfony-docker convention: root compose.yaml + compose.override.yaml).
COMPOSE_FILE="$PWD/docker/dev/docker-compose.yml" # 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 # ALIASES
# =================== # ===================
alias pc='podman-compose -f $COMPOSE_FILE' alias pc="$COMPOSE"
# =================== # ===================
# DEV COMMANDS # DEV COMMANDS
# =================== # ===================
dev-up() { dev-up() {
echo "Starting services..." echo "Starting services..."
PODMAN_USERNS=keep-id podman-compose -f $COMPOSE_FILE up -d "$@" PODMAN_USERNS=keep-id $COMPOSE up -d "$@"
echo "" echo ""
podman-compose -f $COMPOSE_FILE ps $COMPOSE ps
echo "" echo ""
echo "App available at: http://localhost:8100" echo "App available at: http://localhost:8100"
} }
@ -51,46 +54,46 @@ pkgs.mkShell {
dev-down() { dev-down() {
if [[ "$1" == "-v" ]]; then if [[ "$1" == "-v" ]]; then
echo "Stopping services and removing volumes..." echo "Stopping services and removing volumes..."
podman-compose -f $COMPOSE_FILE down -v $COMPOSE down -v
else else
echo "Stopping services..." echo "Stopping services..."
podman-compose -f $COMPOSE_FILE down $COMPOSE down
fi fi
} }
dev-restart() { dev-restart() {
echo "Restarting services..." echo "Restarting services..."
podman-compose -f $COMPOSE_FILE restart "$@" $COMPOSE restart "$@"
} }
dev-rebuild() { dev-rebuild() {
echo "Rebuilding services (down -v + up)..." echo "Rebuilding services (down -v + up)..."
podman-compose -f $COMPOSE_FILE down -v $COMPOSE down -v
PODMAN_USERNS=keep-id podman-compose -f $COMPOSE_FILE up -d "$@" PODMAN_USERNS=keep-id $COMPOSE up -d "$@"
echo "" echo ""
podman-compose -f $COMPOSE_FILE ps $COMPOSE ps
echo "" echo ""
echo "App available at: http://localhost:8100" echo "App available at: http://localhost:8100"
} }
dev-logs() { dev-logs() {
podman-compose -f $COMPOSE_FILE logs -f app "$@" $COMPOSE logs -f php "$@"
} }
dev-logs-db() { dev-logs-db() {
podman-compose -f $COMPOSE_FILE logs -f db "$@" $COMPOSE logs -f database "$@"
} }
dev-shell() { dev-shell() {
podman-compose -f $COMPOSE_FILE exec app sh $COMPOSE exec php sh
} }
dev-console() { dev-console() {
podman-compose -f $COMPOSE_FILE exec app php bin/console "$@" $COMPOSE exec php php bin/console "$@"
} }
dev-composer() { 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 " base-build Build and push image"
echo "" echo ""
echo "Services:" echo "Services:"
echo " app Symfony + Vite http://localhost:8100" echo " php Symfony/FrankenPHP http://localhost:8100"
echo " db MariaDB localhost:3307" echo " database Postgres 16 localhost:5433"
echo " mailhog Web UI http://localhost:8026"
echo "" echo ""
''; '';
} }