Skip to content

Commit 6b74197

Browse files
refactor: Add environment configuration and initialization script for Docker setup, including user permissions and Composer dependency management. (#109)
1 parent 1af4d4d commit 6b74197

File tree

9 files changed

+76
-16
lines changed

9 files changed

+76
-16
lines changed

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# User and Group settings
2+
GROUP_ID=1000
3+
GROUP_NAME=www-data
4+
USER_ID=1000
5+
USER_NAME=www-data
6+
7+
# Yii2 environment settings
8+
YII_DEBUG=true
9+
YII_ENV=dev

codeception.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ bootstrap: _bootstrap.php
33
support_namespace: Support
44
paths:
55
tests: tests
6-
output: runtime/output
6+
output: public/runtime/output
77
data: tests/Support/data
88
support: tests/Support
9-
envs: runtime/_envs
9+
envs: public/runtime/_envs
1010
actor_suffix: Tester
1111
settings:
1212
memory_limit: 1024M

docker-compose.frankenphp.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
services:
22
yii2-frankenphp:
33
build:
4+
args:
5+
USER_ID: ${USER_ID:-1000}
6+
GROUP_ID: ${GROUP_ID:-1000}
7+
USER_NAME: ${USER_NAME:-www-data}
8+
GROUP_NAME: ${GROUP_NAME:-www-data}
9+
context: .
410
dockerfile: docker/frankenphp/Dockerfile
511
container_name: yii2-frankenphp
12+
env_file:
13+
- .env
614
restart: always
715
working_dir: /app
816
volumes:
@@ -16,6 +24,8 @@ services:
1624
- '8444:443/udp'
1725
environment:
1826
TZ: "UTC"
27+
YII_DEBUG: "${YII_DEBUG:-false}"
28+
YII_ENV: "${YII_ENV:-prod}"
1929
tty: true
2030

2131
# Volumes needed for Caddy certificates and configuration

docker/frankenphp/Dockerfile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
FROM dunglas/frankenphp:1.8-php8.4
22

3+
# Build arguments for user/group
4+
ARG USER_ID=1000
5+
ARG GROUP_ID=1000
6+
ARG USER_NAME=www-data
7+
ARG GROUP_NAME=www-data
8+
39
# Change web server config
410
COPY docker/frankenphp/Caddyfile /etc/caddy/Caddyfile
511

@@ -47,7 +53,18 @@ COPY docker/frankenphp/supervisord/conf.d/frankenphp.conf /etc/supervisor/conf.d
4753
# Copy queue worker config uncommented for use with yii2-queue
4854
#COPY docker/frankenphp/supervisord/conf.d/queue.conf /etc/supervisor/conf.d/queue.conf
4955

50-
RUN mkdir -p /var/run && chown -R www-data:www-data /var/run
56+
# Create necessary directories and set permissions
57+
RUN mkdir -p /app/runtime/cache /app/runtime/logs && \
58+
chown -R ${USER_NAME}:${GROUP_NAME} /var/run /app && \
59+
chown -R ${USER_NAME}:${GROUP_NAME} /app/public /app/runtime && \
60+
chmod -R 755 /app && \
61+
chmod -R 775 /app/runtime /app/public
62+
63+
# Copy init script
64+
COPY docker/init.sh /usr/local/bin/init.sh
65+
66+
# Make init script executable
67+
RUN chmod +x /usr/local/bin/init.sh
5168

52-
# Run supervisord
53-
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
69+
# Run initialization script and then supervisord
70+
CMD ["/usr/local/bin/init.sh"]

docker/init.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Check if composer.json exists and vendor directory doesn't exist
2+
if [ -f "/app/composer.json" ] && [ ! -d "/app/vendor" ]; then
3+
echo "Installing Composer dependencies..."
4+
5+
# Install dependencies based on environment
6+
if [ "$YII_ENV" = "prod" ]; then
7+
# Production: exclude dev dependencies and optimize autoloader
8+
composer install --no-dev --optimize-autoloader --no-interaction
9+
else
10+
# Development: include dev dependencies
11+
composer install --optimize-autoloader --no-interaction
12+
fi
13+
14+
# Set proper ownership for vendor directory
15+
chown -R $USER_NAME:$GROUP_NAME /app/vendor
16+
17+
echo "Composer dependencies installed successfully."
18+
fi
19+
20+
# Start supervisord
21+
exec supervisord -c /etc/supervisor/supervisord.conf

docker/php/php.ini

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
;apc.enable_cli = 1
1+
# Global PHP configuration for the Docker container
22
date.timezone = UTC
3+
display_errors = Off
4+
expose_php = Off
5+
memory_limit = 512M
6+
post_max_size = 150M
37
session.auto_start = Off
48
short_open_tag = Off
5-
expose_php = Off
69
upload_max_filesize = 15M
7-
post_max_size = 150M
8-
memory_limit = 512M
9-
display_errors = Off
1010

1111
# https://symfony.com/doc/current/performance.html
12+
# OPcache optimizations
13+
opcache.enable = 1
14+
opcache.enable_cli = 1
1215
opcache.interned_strings_buffer = 16
16+
opcache.jit = tracing
17+
opcache.jit_buffer_size = 64M
1318
opcache.max_accelerated_files = 20000
1419
opcache.memory_consumption = 256
15-
opcache.validate_timestamps = 0
20+
opcache.revalidate_freq = 2
21+
opcache.validate_timestamps = 1
1622
realpath_cache_size = 4096K
17-
realpath_cache_ttl = 600
18-
opcache.preload_user = www-data
23+
realpath_cache_ttl = 120

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ parameters:
1414
- tests/Functional
1515
- tests/Unit
1616

17-
tmpDir: %currentWorkingDirectory%/runtime
17+
tmpDir: %currentWorkingDirectory%/public/runtime
1818

1919
yii2:
2020
config_path: %currentWorkingDirectory%/config/web/app.php

runtime/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

runtime/output/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)