# Build stage for frontend assets
FROM node:20-alpine AS frontend
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY vite.config.js ./
COPY tailwind.config.js ./
COPY postcss.config.js ./
COPY tsconfig*.json ./
COPY jsconfig.json ./
COPY resources ./resources
RUN npm run build
# PHP Application
FROM php:8.4-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
nginx \
supervisor \
curl \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libzip-dev \
zip \
unzip \
libonig-dev \
libicu-dev \
libpq-dev \
postgresql-client \
netcat-openbsd \
redis-tools \
&& rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) \
pdo \
pdo_mysql \
pdo_pgsql \
mbstring \
exif \
pcntl \
bcmath \
gd \
zip \
intl \
opcache
# Install Redis extension
RUN pecl install redis \
&& docker-php-ext-enable redis
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www/html
# Copy application files
COPY --chown=www-data:www-data . .
# Copy built frontend assets
COPY --from=frontend --chown=www-data:www-data /app/public/build ./public/build
# Install PHP dependencies
RUN composer install --no-dev --optimize-autoloader --no-interaction
# Create required directories
RUN mkdir -p storage/framework/{sessions,views,cache} \
&& mkdir -p storage/logs \
&& mkdir -p bootstrap/cache \
&& chown -R www-data:www-data storage bootstrap/cache
# Copy configuration files
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY docker/php.ini /usr/local/etc/php/conf.d/custom.ini
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Expose port
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost/health || exit 1
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|