hosting-backend/Dockerfile
Alexis Bruneteau 9b52ede032
Some checks failed
Build and Deploy to k3s / build-and-deploy (push) Failing after 19s
Fix Dockerfile build: add dev headers to .build-deps
- Added oniguruma-dev, libxml2-dev, libzip-dev to .build-deps
- These headers are required for compiling mbstring, xml, and zip extensions
- Headers are correctly removed after compilation via 'apk del .build-deps'
- Fixes: 'Package requirements (oniguruma) were not met' error
2025-10-17 23:29:39 +02:00

98 lines
2.5 KiB
Docker

# ---------- Stage 1: Build with Composer ----------
FROM php:8.2-cli-alpine AS build
WORKDIR /app
# Install Composer and build dependencies
RUN apk add --no-cache \
libzip-dev zip unzip curl git oniguruma-dev libxml2-dev
# Install PHP extensions for Laravel
RUN docker-php-ext-install zip mbstring xml
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy only dependency files first for better caching
COPY composer.json composer.lock ./
# Install dependencies
RUN composer install --no-dev --optimize-autoloader --no-interaction --no-scripts
# Copy project files
COPY . .
# Run post-install scripts
RUN composer install --no-dev --optimize-autoloader --no-interaction
# ---------- Stage 2: Production Image ----------
FROM php:8.2-fpm-alpine
# Set working directory
WORKDIR /var/www
# Install build dependencies first (will be removed later)
RUN apk add --no-cache --virtual .build-deps \
gcc g++ make autoconf libtool linux-headers \
libpng-dev libjpeg-turbo-dev freetype-dev \
oniguruma-dev libxml2-dev libzip-dev
# Install runtime dependencies
RUN apk add --no-cache \
nginx \
supervisor \
bash \
curl \
libpng libjpeg-turbo freetype \
libxml2 oniguruma libzip \
mysql-client \
openssh \
python3 py3-pip py3-jinja2
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install \
pdo pdo_mysql \
mbstring \
gd \
xml \
zip \
sockets
# Install Redis extension
RUN pecl install redis && \
docker-php-ext-enable redis
# Clean up build dependencies
RUN apk del .build-deps
# Install Ansible
RUN pip3 install --no-cache-dir ansible
# Copy built app from previous stage
COPY --from=build /app /var/www
# Set proper permissions for Laravel
RUN chown -R www-data:www-data /var/www && \
chmod -R 755 /var/www/storage /var/www/bootstrap/cache && \
chmod -R 775 /var/www/database
# Copy config files
COPY deploy/nginx.conf /etc/nginx/nginx.conf
COPY deploy/supervisord.conf /etc/supervisord.conf
# Create log directory
RUN mkdir -p /var/log/laravel && \
chown -R www-data:www-data /var/log/laravel
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost/api/ping || exit 1
# Expose HTTP port
EXPOSE 80
# Start services
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]