Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
FROM node:20-alpine AS frontend-build

WORKDIR /build
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install
COPY frontend/ ./
RUN npm run build

# ---

FROM php:8.0-fpm

# Install system packages
RUN apt-get update \
&& apt-get -y install git nano procps unzip default-mysql-client nginx supervisor
&& apt-get -y install git nano procps unzip default-mysql-client nginx supervisor curl

# Install Node.js 20 for frontend builds
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs

# Install 'retry' script
RUN curl https://raw.githubusercontent.com/kadwanev/retry/0b65e6b7f54ed36b492910470157e180bbcc3c84/retry -o /usr/local/bin/retry \
&& chmod +x /usr/local/bin/retry

# Install PHP extensions
RUN docker-php-ext-install mysqli pdo pdo_mysql \
RUN docker-php-ext-install mysqli pdo pdo_mysql opcache \
&& pecl install xdebug-3.1.1 \
&& docker-php-ext-enable pdo_mysql xdebug

# Configure Xdebug
RUN echo "xdebug.mode=develop" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Xdebug and OPcache are configured at runtime by docker-start.sh based on APP_ENV

# Install composer (pinned to 2.2 LTS for compatibility with symfony/flex v1.x)
RUN curl -sSL https://getcomposer.org/download/2.2.24/composer.phar -o /usr/local/bin/composer \
Expand All @@ -24,14 +36,17 @@ RUN curl -sSL https://getcomposer.org/download/2.2.24/composer.phar -o /usr/loca
# Install Symfony CLI
RUN curl -sSL https://get.symfony.com/cli/installer | bash -s -- --install-dir=/usr/local/bin

# Create workspace directory (application code should be attached here using a bind mount)
# Create workspace directory
RUN mkdir /srv/app
WORKDIR /srv/app

# Install dependencies (this will populate the ~/.composer/cache for faster installs later)
# Install PHP dependencies
COPY composer.json composer.lock ./
RUN composer install --no-scripts

# Copy Vue frontend build output
COPY --from=frontend-build /build/dist /srv/app/frontend/dist

# Add project specific nginx config
COPY .devcontainer/nginx.conf /etc/nginx/nginx.conf
RUN rm -f /etc/nginx/sites-enabled/default
Expand Down
36 changes: 36 additions & 0 deletions .devcontainer/docker-start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
#!/bin/bash

APP_ENV="${APP_ENV:-prod}"
echo "==> Starting in $APP_ENV mode"

# Update nginx to match worker_processes to no. of cpu's
procs=$(cat /proc/cpuinfo | grep processor | wc -l)
sed -i -e "s/worker_processes 1/worker_processes $procs/" /etc/nginx/nginx.conf

# Configure PHP based on environment
if [ "$APP_ENV" = "prod" ]; then
echo "==> Enabling OPcache"
cat > /usr/local/etc/php/conf.d/opcache-env.ini <<EOF
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
opcache.save_comments=1
opcache.fast_shutdown=1
EOF

echo "==> Disabling Xdebug"
rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

echo "==> Warming Symfony cache"
php /srv/app/bin/console cache:warmup --env=prod --no-debug 2>/dev/null || true
else
echo "==> OPcache disabled for development"
cat > /usr/local/etc/php/conf.d/opcache-env.ini <<EOF
opcache.enable=0
EOF

echo "==> Xdebug in develop mode"
cat > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini <<EOF
zend_extension=xdebug
xdebug.mode=develop
xdebug.start_with_request=no
xdebug.client_host=host.docker.internal
EOF
fi

# Start supervisord and services
/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf

Expand Down
54 changes: 14 additions & 40 deletions .devcontainer/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ user www-data www-data;

events {
worker_connections 768;
# multi_accept on;
}

http {
# Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
Expand All @@ -19,67 +17,43 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

# Logging Settings
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# Gzip Settings
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;

# Other Configs
include /etc/nginx/conf.d/*.conf;

server {
server_name _;
listen 0.0.0.0:8000;

root /srv/app/public;

location / {
# try to serve file directly, fallback to index.php
# API requests go to Symfony/PHP
location /api {
root /srv/app/public;
try_files $uri /index.php$is_args$args;
}

# optionally disable falling back to PHP script for the asset directories;
# nginx will return a 404 error when files are not found instead of passing the
# request to Symfony (improves performance but Symfony's 404 page is not displayed)
location /bundles {
try_files $uri =404;
}

location ~ ^/index\.php(/|$) {
root /srv/app/public;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /srv/app/public$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /srv/app/public;
internal;
}

# optionally set the value of the environment variables used in the application
# fastcgi_param APP_ENV prod;
# fastcgi_param APP_SECRET <app-secret-id>;
# fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
# Caveat: When PHP-FPM is hosted on a different machine from nginx
# $realpath_root may not resolve as you expect! In this case try using
# $document_root instead.
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Vue.js static files
root /srv/app/frontend/dist;

# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
location / {
try_files $uri $uri/ /index.html;
}

# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
}
}
}
4 changes: 1 addition & 3 deletions .devcontainer/php-fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ pm.start_servers = 3
pm.min_spare_servers = 1
pm.max_spare_servers = 10

; Enable Xdebug
php_value[xdebug.mode] = debug
php_value[xdebug.log] = /var/log/php-fpm/xdebug.log
; Xdebug is configured at runtime by docker-start.sh based on APP_ENV
11 changes: 10 additions & 1 deletion .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ set -e
# These commands will be run by VSCode inside the remote container on first startup.
#

# Install dependencies
# Install PHP dependencies
composer install

# Install and build Vue frontend
if command -v node &> /dev/null; then
cd /srv/app/frontend && npm install && npm run build
cd /srv/app
elif command -v npx &> /dev/null; then
cd /srv/app/frontend && npm install && npm run build
cd /srv/app
fi

# Wait for database to be available
MYSQL_PWD=symfony retry -t 10 -m 1 -- mysqladmin -h database -P 3306 -u symfony status

Expand Down
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
var/
vendor/
frontend/node_modules/
frontend/dist/
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_ENV=prod
APP_SECRET=59db887a5bf81a90b747f4e5002bd30f
###< symfony/framework-bundle ###

Expand Down
Loading
Loading