diff --git a/.env b/.env new file mode 100644 index 0000000..81ff7ce --- /dev/null +++ b/.env @@ -0,0 +1,9 @@ +# User and Group settings +GROUP_ID=1000 +GROUP_NAME=www-data +USER_ID=1000 +USER_NAME=www-data + +# Yii2 environment settings +YII_DEBUG=true +YII_ENV=dev diff --git a/codeception.yml b/codeception.yml index f05a2ae..5732d5a 100644 --- a/codeception.yml +++ b/codeception.yml @@ -3,10 +3,10 @@ bootstrap: _bootstrap.php support_namespace: Support paths: tests: tests - output: runtime/output + output: public/runtime/output data: tests/Support/data support: tests/Support - envs: runtime/_envs + envs: public/runtime/_envs actor_suffix: Tester settings: memory_limit: 1024M diff --git a/docker-compose.frankenphp.yml b/docker-compose.frankenphp.yml index a6559c1..b1f2171 100644 --- a/docker-compose.frankenphp.yml +++ b/docker-compose.frankenphp.yml @@ -1,8 +1,16 @@ services: yii2-frankenphp: build: + args: + USER_ID: ${USER_ID:-1000} + GROUP_ID: ${GROUP_ID:-1000} + USER_NAME: ${USER_NAME:-www-data} + GROUP_NAME: ${GROUP_NAME:-www-data} + context: . dockerfile: docker/frankenphp/Dockerfile container_name: yii2-frankenphp + env_file: + - .env restart: always working_dir: /app volumes: @@ -16,6 +24,8 @@ services: - '8444:443/udp' environment: TZ: "UTC" + YII_DEBUG: "${YII_DEBUG:-false}" + YII_ENV: "${YII_ENV:-prod}" tty: true # Volumes needed for Caddy certificates and configuration diff --git a/docker/frankenphp/Dockerfile b/docker/frankenphp/Dockerfile index 118869c..f46ab27 100644 --- a/docker/frankenphp/Dockerfile +++ b/docker/frankenphp/Dockerfile @@ -1,5 +1,11 @@ FROM dunglas/frankenphp:1.8-php8.4 +# Build arguments for user/group +ARG USER_ID=1000 +ARG GROUP_ID=1000 +ARG USER_NAME=www-data +ARG GROUP_NAME=www-data + # Change web server config COPY docker/frankenphp/Caddyfile /etc/caddy/Caddyfile @@ -47,7 +53,18 @@ COPY docker/frankenphp/supervisord/conf.d/frankenphp.conf /etc/supervisor/conf.d # Copy queue worker config uncommented for use with yii2-queue #COPY docker/frankenphp/supervisord/conf.d/queue.conf /etc/supervisor/conf.d/queue.conf -RUN mkdir -p /var/run && chown -R www-data:www-data /var/run +# Create necessary directories and set permissions +RUN mkdir -p /app/runtime/cache /app/runtime/logs && \ + chown -R ${USER_NAME}:${GROUP_NAME} /var/run /app && \ + chown -R ${USER_NAME}:${GROUP_NAME} /app/public /app/runtime && \ + chmod -R 755 /app && \ + chmod -R 775 /app/runtime /app/public + +# Copy init script +COPY docker/init.sh /usr/local/bin/init.sh + +# Make init script executable +RUN chmod +x /usr/local/bin/init.sh -# Run supervisord -CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"] +# Run initialization script and then supervisord +CMD ["/usr/local/bin/init.sh"] diff --git a/docker/init.sh b/docker/init.sh new file mode 100644 index 0000000..8c3de96 --- /dev/null +++ b/docker/init.sh @@ -0,0 +1,21 @@ +# Check if composer.json exists and vendor directory doesn't exist +if [ -f "/app/composer.json" ] && [ ! -d "/app/vendor" ]; then + echo "Installing Composer dependencies..." + + # Install dependencies based on environment + if [ "$YII_ENV" = "prod" ]; then + # Production: exclude dev dependencies and optimize autoloader + composer install --no-dev --optimize-autoloader --no-interaction + else + # Development: include dev dependencies + composer install --optimize-autoloader --no-interaction + fi + + # Set proper ownership for vendor directory + chown -R $USER_NAME:$GROUP_NAME /app/vendor + + echo "Composer dependencies installed successfully." +fi + +# Start supervisord +exec supervisord -c /etc/supervisor/supervisord.conf diff --git a/docker/php/php.ini b/docker/php/php.ini index 4f7adf6..92fe1f7 100644 --- a/docker/php/php.ini +++ b/docker/php/php.ini @@ -1,18 +1,23 @@ -;apc.enable_cli = 1 +# Global PHP configuration for the Docker container date.timezone = UTC +display_errors = Off +expose_php = Off +memory_limit = 512M +post_max_size = 150M session.auto_start = Off short_open_tag = Off -expose_php = Off upload_max_filesize = 15M -post_max_size = 150M -memory_limit = 512M -display_errors = Off # https://symfony.com/doc/current/performance.html +# OPcache optimizations +opcache.enable = 1 +opcache.enable_cli = 1 opcache.interned_strings_buffer = 16 +opcache.jit = tracing +opcache.jit_buffer_size = 64M opcache.max_accelerated_files = 20000 opcache.memory_consumption = 256 -opcache.validate_timestamps = 0 +opcache.revalidate_freq = 2 +opcache.validate_timestamps = 1 realpath_cache_size = 4096K -realpath_cache_ttl = 600 -opcache.preload_user = www-data \ No newline at end of file +realpath_cache_ttl = 120 diff --git a/phpstan.neon b/phpstan.neon index ced0425..b0c30f3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,7 +14,7 @@ parameters: - tests/Functional - tests/Unit - tmpDir: %currentWorkingDirectory%/runtime + tmpDir: %currentWorkingDirectory%/public/runtime yii2: config_path: %currentWorkingDirectory%/config/web/app.php diff --git a/runtime/.gitignore b/runtime/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/runtime/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/runtime/output/.gitkeep b/runtime/output/.gitkeep deleted file mode 100644 index e69de29..0000000