Files
michaelschiemer/docker/php/Dockerfile
Michael Schiemer 3b623e7afb feat(Deployment): Integrate Ansible deployment via PHP deployment pipeline
- Create AnsibleDeployStage using framework's Process module for secure command execution
- Integrate AnsibleDeployStage into DeploymentPipelineCommands for production deployments
- Add force_deploy flag support in Ansible playbook to override stale locks
- Use PHP deployment module as orchestrator (php console.php deploy:production)
- Fix ErrorAggregationInitializer to use Environment class instead of $_ENV superglobal

Architecture:
- BuildStage → AnsibleDeployStage → HealthCheckStage for production
- Process module provides timeout, error handling, and output capture
- Ansible playbook supports rollback via rollback-git-based.yml
- Zero-downtime deployments with health checks
2025-10-26 14:08:07 +01:00

109 lines
3.5 KiB
Docker

# Dockerfile für PHP-FPM
FROM php:8.5.0RC2-fpm AS base
# System-Abhängigkeiten: Werden selten geändert, daher ein eigener Layer
RUN apt-get update && apt-get install -y \
git \
unzip \
libzip-dev \
zip \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libwebp-dev \
libavif-dev \
libxpm-dev \
libsodium-dev \
libpq-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
--with-avif \
--with-xpm \
&& docker-php-ext-install -j$(nproc) gd
# Install PHP extensions (opcache and sodium are already built into PHP 8.5)
RUN docker-php-ext-install -j$(nproc) \
zip \
pdo \
pdo_mysql \
pdo_pgsql \
pcntl \
posix \
shmop \
bcmath
# Skip PECL extensions for PHP 8.5 RC compatibility
# RUN pecl install apcu redis \
# && docker-php-ext-enable apcu redis
# RUN echo "apc.enable_cli=1" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini \
# && echo "apc.shm_size=128M" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini
# Composer installieren
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer
# Installiere Xdebug nur im Entwicklungsmodus
ARG ENV=prod
RUN if [ "$ENV" = "dev" ]; then \
pecl install xdebug \
&& docker-php-ext-enable xdebug; \
fi
WORKDIR /var/www/html
# Composer Dependencies (für besseres Caching)
COPY composer.json ./
COPY composer.lock* ./
RUN composer install --no-scripts --no-autoloader --ignore-platform-reqs || \
(composer install --no-scripts --no-autoloader --no-dev --ignore-platform-reqs || \
echo "Composer install failed, continuing without dependencies")
# Kopiere PHP-Konfigurationen
COPY docker/php/php.common.ini /usr/local/etc/php/php.common.ini
COPY docker/php/php.${ENV}.ini /usr/local/etc/php/php.ini
# Kopiere PHP-FPM Pool-Konfiguration
COPY docker/php/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
# Xdebug-Konfiguration nur wenn dev
RUN if [ "$ENV" = "dev" ] && [ -f docker/php/xdebug.ini ]; then \
cp docker/php/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
fi
# Kopiere den Rest des Projekts
COPY . .
# Optimiere Autoloader
RUN composer dump-autoload --optimize
# <<--- ALLE zusätzlichen System-Dateien und chmod noch als root!
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Remove entire storage directory tree copied from COPY . .
# But we MUST create the empty parent directory so Docker can mount subdirectories
RUN rm -rf /var/www/html/storage && mkdir -p /var/www/html/storage
# CRITICAL: The storage directory must exist as an empty directory in the image
# This allows Docker to mount Named Volumes to subdirectories (storage/cache, storage/logs, etc.)
# without needing to create the parent directory at runtime (which fails due to read-only overlay)
# Create appuser but DON'T switch yet - let entrypoint handle volumes first
RUN groupadd -g 1000 appuser && useradd -u 1000 -g appuser -m appuser
RUN chown -R appuser:appuser /var/www/html
# Install gosu for secure user switching in entrypoint (Debian alternative to su-exec)
RUN apt-get update && apt-get install -y gosu && apt-get clean && rm -rf /var/lib/apt/lists/*
# Note: USER switch happens in entrypoint AFTER volumes are mounted
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["php-fpm"]