-
-
Notifications
You must be signed in to change notification settings - Fork 2
feature(app): Implement FrankenPHP classic stack.
#187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d76376
feature(app): Implement `FrankenPHP` classic stack.
terabytesoftw 8409ff7
fix(workflow): Rename job from `nginx` to `franken-php` in build conf…
terabytesoftw 4a0e92e
fix(docker): Update healthcheck configuration and improve container i…
terabytesoftw 13f5ef6
fix(docker): Enhance healthcheck configuration and improve container …
terabytesoftw ca86de1
Apply fixed review coderabbitai nitpick comments.
terabytesoftw 081a5c8
fix(docker): Update healthcheck command and reduce start period in do…
terabytesoftw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 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 | ||
| entrypoint: ["/usr/local/bin/entrypoint.sh"] | ||
| env_file: | ||
| - .env | ||
| environment: | ||
| TZ: "UTC" | ||
| YII_DEBUG: "${YII_DEBUG:-false}" | ||
| YII_ENV: "${YII_ENV:-prod}" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "curl -f http://localhost/ || exit 1"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| start_period: 20s | ||
| ports: | ||
| - '8080:80' | ||
| - '8443:443' | ||
| - '8443:443/udp' | ||
| restart: always | ||
| tty: true | ||
| volumes: | ||
| - ./:/app | ||
| - caddy_config:/config | ||
| - caddy_data:/data | ||
| - composer_cache:/var/www/.composer/cache | ||
| working_dir: /app | ||
|
|
||
| volumes: | ||
| caddy_data: | ||
| caddy_config: | ||
| composer_cache: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| echo "=== Container Starting ===" | ||
| echo "Running initialization script..." | ||
|
|
||
| # Ensure init script is executable | ||
| chmod +x /usr/local/bin/init.sh | ||
|
|
||
| # Execute init script; replace the PID 1 shell | ||
| exec /usr/local/bin/init.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| { | ||
| # Global options | ||
| auto_https off | ||
| } | ||
|
|
||
| # HTTPS server block using mkcert certificates | ||
| https://localhost:443 { | ||
| # Specify mkcert certificates | ||
| tls /app/docker/ssl/localhost.pem /app/docker/ssl/localhost-key.pem | ||
|
|
||
| # Document root | ||
| root * /app/web | ||
|
|
||
| # Enable PHP processing with FrankenPHP | ||
| php_server | ||
|
|
||
| # Security headers | ||
| header { | ||
| X-Frame-Options "SAMEORIGIN" | ||
| X-Content-Type-Options "nosniff" | ||
| Referrer-Policy "strict-origin-when-cross-origin" | ||
| Permissions-Policy "geolocation=(), camera=(), microphone=()" | ||
| # For prod domains only, consider HSTS; avoid for localhost: | ||
| # Strict-Transport-Security "max-age=31536000; includeSubDomains" | ||
| -Server | ||
| } | ||
|
|
||
| # Logging | ||
| log { | ||
| output stdout | ||
| format console | ||
| } | ||
|
|
||
| encode zstd gzip | ||
|
|
||
| # Handle static files | ||
| @static { | ||
| file | ||
| path *.css *.js *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot | ||
| } | ||
| handle @static { | ||
| header Cache-Control "public, max-age=31536000, immutable" | ||
| file_server | ||
| } | ||
|
|
||
| # Block access to sensitive directories | ||
| @forbidden { | ||
| path /.git/* /vendor/* /runtime/* /.env* | ||
| } | ||
| respond @forbidden 404 | ||
|
|
||
| # Deny PHP execution in assets directory (Yii2 security) | ||
| @assets_php { | ||
| path /assets/*.php | ||
| } | ||
| respond @assets_php 403 | ||
|
|
||
| # Try files for Yii2 URL rewriting | ||
| try_files {path} {path}/ /index.php?{query} | ||
| } | ||
|
|
||
| # HTTP server block - redirect to HTTPS | ||
| http://localhost:80 { | ||
| # Redirect all HTTP traffic to HTTPS | ||
| redir https://localhost:8443{uri} permanent | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| 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 | ||
|
|
||
| # Set document root to /app/web (Yii2 structure) | ||
| WORKDIR /app | ||
|
|
||
| # Install required system packages for PHP extensions for Yii 2.0 Framework | ||
| COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ | ||
| RUN install-php-extensions \ | ||
| bcmath \ | ||
| @composer \ | ||
| exif \ | ||
| gd \ | ||
| imagick \ | ||
| intl \ | ||
| opcache \ | ||
| pdo_mysql \ | ||
| pdo_pgsql \ | ||
| soap \ | ||
| xdebug \ | ||
| zip | ||
|
|
||
| # Set composer environment | ||
| ENV COMPOSER_ALLOW_SUPERUSER=1 | ||
|
|
||
| # Change PHP config | ||
| COPY docker/php/php.ini /usr/local/etc/php/conf.d/base.ini | ||
|
|
||
| # Install supervisor, gosu, and Node.js (version simple) | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| supervisor \ | ||
| curl \ | ||
| gosu \ | ||
| && curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \ | ||
| && apt-get install -y nodejs \ | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
|
||
| # Apply the user/group IDs to www-data | ||
| RUN usermod -u ${USER_ID} www-data && groupmod -g ${GROUP_ID} www-data | ||
|
|
||
| # Create composer and npm cache directories with proper ownership | ||
| RUN mkdir -p /var/www/.composer/cache /var/www/.npm && \ | ||
| chown -R www-data:www-data /var/www/.composer /var/www/.npm | ||
|
|
||
| # Copy supervisor program configs | ||
| COPY docker/supervisor/conf.d/frankenphp.conf /etc/supervisor/conf.d/frankenphp.conf | ||
|
|
||
| # Copy queue worker config uncommented for use with yii2-queue | ||
| #COPY docker/supervisor/conf.d/queue.conf /etc/supervisor/conf.d/queue.conf | ||
|
|
||
| # Copy scripts | ||
| COPY docker/init.sh /usr/local/bin/init.sh | ||
| COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh | ||
|
|
||
| # Make scripts executable and validate | ||
| RUN chmod +x /usr/local/bin/init.sh /usr/local/bin/entrypoint.sh && \ | ||
| # Convert any Windows line endings | ||
| sed -i 's/\r$//' /usr/local/bin/init.sh /usr/local/bin/entrypoint.sh && \ | ||
| # Test that scripts have valid syntax | ||
| bash -n /usr/local/bin/init.sh && \ | ||
| bash -n /usr/local/bin/entrypoint.sh && \ | ||
| echo "✓ Scripts validated successfully..." | ||
|
|
||
| # Use ENTRYPOINT to guarantee execution | ||
| ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| NC='\033[0m' | ||
|
|
||
| echo -e "${GREEN}Starting container setup...${NC}" | ||
|
|
||
| # Create necessary Caddy directories with proper permissions | ||
| echo -e "${YELLOW}Creating Caddy directories...${NC}" | ||
| mkdir -p /data/caddy/locks /config/caddy | ||
| chown -R www-data:www-data /data /config | ||
| chmod -R 755 /data /config | ||
|
|
||
| # Create necessary Yii2 directories if they don't exist | ||
| echo -e "${YELLOW}Creating Yii2 directories...${NC}" | ||
| mkdir -p /app/runtime/cache | ||
| mkdir -p /app/runtime/logs | ||
| mkdir -p /app/web/assets | ||
|
|
||
| # Configure permissions for Yii2 directories | ||
| echo -e "${YELLOW}Setting up permissions...${NC}" | ||
|
|
||
| # Try to set permissions and ownership - handle both mounted volumes and container-only scenarios | ||
| if chown -R www-data:www-data /app/runtime 2>/dev/null; then | ||
| chmod -R 775 /app/runtime | ||
| echo -e "${GREEN}✓ Runtime directory configured correctly${NC}" | ||
| else | ||
| # If chown fails (mounted volume), try chmod only | ||
| if chmod -R 777 /app/runtime 2>/dev/null; then | ||
| echo -e "${YELLOW}⚠ Runtime directory permissions set to 777 (mounted volume)${NC}" | ||
| else | ||
| echo -e "${RED}✗ Error: Could not configure runtime directory${NC}" | ||
| fi | ||
| fi | ||
|
|
||
| if chown -R www-data:www-data /app/web/assets 2>/dev/null; then | ||
| chmod -R 775 /app/web/assets | ||
| echo -e "${GREEN}✓ Assets directory configured correctly${NC}" | ||
| else | ||
| # If chown fails (mounted volume), try chmod only | ||
| if chmod -R 777 /app/web/assets 2>/dev/null; then | ||
| echo -e "${YELLOW}⚠ Assets directory permissions set to 777 (mounted volume)${NC}" | ||
| else | ||
| echo -e "${RED}✗ Error: Could not configure assets directory${NC}" | ||
| fi | ||
| fi | ||
|
|
||
| echo -e "${GREEN}Setup completed.${NC}" | ||
|
|
||
| # Check if composer.json exists and vendor directory doesn't exist | ||
| if [ -f "/app/composer.json" ] && [ ! -d "/app/vendor" ]; then | ||
| echo -e "${YELLOW}Installing Composer dependencies...${NC}" | ||
|
|
||
| # Give www-data write access without exposing the tree to everyone | ||
| chown -R www-data:www-data /app && \ | ||
| chmod -R u+rwX,g+rwX /app | ||
|
|
||
terabytesoftw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Create and configure npm cache directory for www-data | ||
| mkdir -p /var/www/.npm | ||
| chown -R www-data:www-data /var/www/.npm | ||
|
|
||
terabytesoftw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Create and own Composer home & cache for www-data | ||
| mkdir -p /var/www/.composer/cache | ||
| chown -R www-data:www-data /var/www/.composer | ||
|
|
||
| # Install dependencies with proper environment variables | ||
| if [ "$YII_ENV" = "prod" ]; then | ||
| # Production: exclude dev dependencies and optimize autoloader | ||
| gosu www-data env \ | ||
| HOME=/var/www \ | ||
| COMPOSER_HOME=/var/www/.composer \ | ||
| COMPOSER_CACHE_DIR=/var/www/.composer/cache \ | ||
| npm_config_cache=/var/www/.npm \ | ||
| composer install --no-dev --optimize-autoloader --no-interaction | ||
| else | ||
| # Development: include dev dependencies | ||
| gosu www-data env \ | ||
| HOME=/var/www \ | ||
| COMPOSER_HOME=/var/www/.composer \ | ||
| COMPOSER_CACHE_DIR=/var/www/.composer/cache \ | ||
| npm_config_cache=/var/www/.npm \ | ||
| composer install --optimize-autoloader --no-interaction | ||
| fi | ||
|
|
||
| echo -e "${GREEN}✓ Composer dependencies installed successfully${NC}" | ||
| fi | ||
|
|
||
| # Copy supervisor configuration | ||
| echo -e "${YELLOW}Configuring supervisor...${NC}" | ||
|
|
||
| if [ -f "/app/docker/supervisor/supervisord.conf" ]; then | ||
| cp /app/docker/supervisor/supervisord.conf /etc/supervisor/supervisord.conf | ||
| echo -e "${GREEN}✓ Supervisor configuration copied successfully${NC}" | ||
| else | ||
| echo -e "${RED}✗ Error: Supervisor configuration file not found${NC}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -e "${GREEN}Starting supervisor daemon...${NC}" | ||
|
|
||
| # Start supervisor daemon | ||
| exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.