Startup
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
php:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: php/Dockerfile
|
||||
container_name: escapepage-php
|
||||
volumes:
|
||||
- ../:/var/www/html:delegated
|
||||
environment:
|
||||
APP_ENV: dev
|
||||
depends_on:
|
||||
- database
|
||||
networks:
|
||||
- backend
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
image: nginx:1.27-alpine
|
||||
container_name: escapepage-nginx
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
@@ -20,26 +27,50 @@ services:
|
||||
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
depends_on:
|
||||
- php
|
||||
networks:
|
||||
- backend
|
||||
restart: unless-stopped
|
||||
|
||||
mailer:
|
||||
image: axllent/mailpit:latest
|
||||
container_name: escapepage-mailer
|
||||
ports:
|
||||
- "8025:8025"
|
||||
networks:
|
||||
- backend
|
||||
restart: unless-stopped
|
||||
|
||||
###> doctrine/doctrine-bundle ###
|
||||
database:
|
||||
image: mysql:8.0
|
||||
container_name: escapepage-db
|
||||
environment:
|
||||
MYSQL_DATABASE: ${MYSQL_DATABASE:-app}
|
||||
MYSQL_USER: ${MYSQL_USER:-app}
|
||||
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-!ChangeMe!}
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
|
||||
command: ["--default-authentication-plugin=mysql_native_password", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-p${MYSQL_ROOT_PASSWORD:-root}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 60s
|
||||
start_period: 30s
|
||||
command: ["--default-authentication-plugin=mysql_native_password", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
|
||||
volumes:
|
||||
- database_data:/var/lib/mysql:rw
|
||||
# Uncomment the two lines below if you need to access MySQL from your host (workbench, etc.)
|
||||
# ports:
|
||||
# - "3306:3306"
|
||||
networks:
|
||||
- backend
|
||||
restart: unless-stopped
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
||||
volumes:
|
||||
###> doctrine/doctrine-bundle ###
|
||||
database_data:
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
||||
networks:
|
||||
backend:
|
||||
driver: bridge
|
||||
|
||||
28
docker/nginx/default.conf
Normal file
28
docker/nginx/default.conf
Normal file
@@ -0,0 +1,28 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /var/www/html/public;
|
||||
index index.php index.html;
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
location / {
|
||||
try_files $uri /index.php$is_args$args;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||
fastcgi_param DOCUMENT_ROOT $realpath_root;
|
||||
fastcgi_pass php:9000;
|
||||
fastcgi_read_timeout 120;
|
||||
}
|
||||
|
||||
location ~ /\.ht {
|
||||
deny all;
|
||||
}
|
||||
|
||||
client_max_body_size 32m;
|
||||
}
|
||||
21
docker/php/Dockerfile
Normal file
21
docker/php/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
FROM php:8.2-fpm-alpine
|
||||
|
||||
# Install system deps
|
||||
RUN apk add --no-cache bash git icu-dev libzip-dev oniguruma-dev
|
||||
|
||||
# Install PHP extensions
|
||||
RUN docker-php-ext-configure intl \
|
||||
&& docker-php-ext-install -j$(nproc) intl pdo pdo_mysql opcache
|
||||
|
||||
# Install composer
|
||||
ENV COMPOSER_ALLOW_SUPERUSER=1 \
|
||||
COMPOSER_HOME=/tmp/composer
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# Configure PHP
|
||||
COPY php.ini $PHP_INI_DIR/conf.d/zz-custom.ini
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Default command
|
||||
CMD ["php-fpm"]
|
||||
9
docker/php/php.ini
Normal file
9
docker/php/php.ini
Normal file
@@ -0,0 +1,9 @@
|
||||
memory_limit=512M
|
||||
post_max_size=32M
|
||||
upload_max_filesize=32M
|
||||
max_execution_time=60
|
||||
; For Symfony dev
|
||||
opcache.enable=1
|
||||
opcache.enable_cli=1
|
||||
opcache.validate_timestamps=1
|
||||
opcache.revalidate_freq=0
|
||||
126
docker/setup.sh
Normal file
126
docker/setup.sh
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Simple setup script to bootstrap the Dockerized dev stack for this project.
|
||||
# - Builds and starts containers (php, nginx, mariadb, mailpit via override)
|
||||
# - Installs composer dependencies
|
||||
# - Ensures APP_SECRET is set (generates if empty)
|
||||
# - Creates and migrates the database
|
||||
# - Installs/imports JS dependencies
|
||||
# - Prints helpful info on success
|
||||
|
||||
# Usage:
|
||||
# ./docker/setup.sh # full setup
|
||||
# ./docker/setup.sh --no-build # skip image rebuild
|
||||
# ./docker/setup.sh --down # stop and remove containers (down)
|
||||
# ./docker/setup.sh --recreate # force recreate containers
|
||||
|
||||
ROOT_DIR=$(cd "$(dirname "$0")"/.. && pwd)
|
||||
DOCKER_DIR="$ROOT_DIR/docker"
|
||||
# Determine the docker compose command (V2 'docker compose' or V1 'docker-compose')
|
||||
if docker compose version >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE="docker compose"
|
||||
elif command -v docker-compose >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE="docker-compose"
|
||||
else
|
||||
echo "Error: Neither 'docker compose' nor 'docker-compose' was found. Please install Docker Compose." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Helper to run docker compose from the docker/ directory
|
||||
dc() { (cd "$DOCKER_DIR" && $DOCKER_COMPOSE -f compose.yaml "$@"); }
|
||||
|
||||
REBUILD=1
|
||||
RECREATE=0
|
||||
DOWN_ONLY=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--no-build) REBUILD=0 ;;
|
||||
--recreate) RECREATE=1 ;;
|
||||
--down) DOWN_ONLY=1 ;;
|
||||
*) echo "Unknown option: $arg" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
need() { command -v "$1" >/dev/null 2>&1 || { echo "Error: '$1' is required but not installed." >&2; exit 1; }; }
|
||||
|
||||
need docker
|
||||
|
||||
if [ "$DOWN_ONLY" -eq 1 ]; then
|
||||
dc down
|
||||
exit 0
|
||||
fi
|
||||
|
||||
BUILD_ARGS=()
|
||||
if [ "$REBUILD" -eq 1 ]; then
|
||||
BUILD_ARGS+=("--build")
|
||||
fi
|
||||
if [ "$RECREATE" -eq 1 ]; then
|
||||
BUILD_ARGS+=("--force-recreate")
|
||||
fi
|
||||
|
||||
# Start stack
|
||||
dc up "${BUILD_ARGS[@]}"
|
||||
|
||||
# Helper to run commands in php container
|
||||
pexec() { dc exec -T php "$@"; }
|
||||
|
||||
# Wait for database to be healthy (mariadb)
|
||||
printf "Waiting for database to be healthy..."
|
||||
# Use docker inspect health status
|
||||
DB_HEALTH=""
|
||||
for i in {1..60}; do
|
||||
DB_HEALTH=$(docker inspect -f '{{.State.Health.Status}}' "$(docker ps --filter name=_database_ --format '{{.ID}}' | head -n1)" 2>/dev/null || true)
|
||||
if [ "$DB_HEALTH" = "healthy" ]; then
|
||||
echo " OK"
|
||||
break
|
||||
fi
|
||||
printf "."
|
||||
sleep 2
|
||||
if [ "$i" -eq 60 ]; then
|
||||
echo "\nWarning: database health check not healthy yet, continuing anyway."
|
||||
fi
|
||||
done
|
||||
|
||||
# Ensure composer is available and install dependencies
|
||||
pexec composer install --no-interaction
|
||||
|
||||
# Ensure APP_SECRET is set
|
||||
if grep -q '^APP_SECRET=$' "$ROOT_DIR/.env" 2>/dev/null; then
|
||||
echo "Generating APP_SECRET in .env.local..."
|
||||
mkdir -p "$ROOT_DIR"
|
||||
SECRET=$(openssl rand -hex 16)
|
||||
# Write to .env.local so we don't commit it
|
||||
if [ ! -f "$ROOT_DIR/.env.local" ]; then
|
||||
printf "APP_SECRET=%s\n" "$SECRET" > "$ROOT_DIR/.env.local"
|
||||
elif ! grep -q '^APP_SECRET=' "$ROOT_DIR/.env.local"; then
|
||||
printf "APP_SECRET=%s\n" "$SECRET" >> "$ROOT_DIR/.env.local"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Prepare DB
|
||||
pexec php bin/console doctrine:database:create --if-not-exists || true
|
||||
pexec php bin/console doctrine:migrations:migrate -n || true
|
||||
|
||||
# Import JS deps (Importmap/Asset Mapper)
|
||||
pexec php bin/console importmap:install || true
|
||||
|
||||
APP_URL=http://localhost:8080
|
||||
MAILPIT_URL=http://localhost:8025
|
||||
|
||||
cat <<EOT
|
||||
|
||||
Setup complete!
|
||||
|
||||
Open the app: $APP_URL
|
||||
Mailpit (dev): $MAILPIT_URL
|
||||
|
||||
Common commands:
|
||||
(cd docker && $DOCKER_COMPOSE logs -f nginx)
|
||||
(cd docker && $DOCKER_COMPOSE logs -f php)
|
||||
(cd docker && $DOCKER_COMPOSE exec php bash)
|
||||
(cd docker && $DOCKER_COMPOSE down)
|
||||
|
||||
You can re-run this script any time. Use --no-build to skip rebuilding images.
|
||||
EOT
|
||||
Reference in New Issue
Block a user