74 lines
1.8 KiB
Docker
74 lines
1.8 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 && \
|
|
mv composer.phar /usr/local/bin/composer
|
|
|
|
# Copy project files and install dependencies
|
|
COPY . .
|
|
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 system and PHP dependencies
|
|
RUN apk add --no-cache \
|
|
nginx \
|
|
supervisor \
|
|
bash \
|
|
mysql-client \
|
|
libpng-dev \
|
|
libjpeg-turbo-dev \
|
|
freetype-dev \
|
|
libxml2-dev \
|
|
oniguruma-dev \
|
|
libzip-dev \
|
|
curl \
|
|
git \
|
|
openssh \
|
|
php-pear \
|
|
gcc g++ make autoconf libtool linux-headers
|
|
|
|
# Install PHP extensions
|
|
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
|
|
docker-php-ext-install pdo pdo_mysql mbstring gd xml zip && \
|
|
pecl install redis && \
|
|
docker-php-ext-enable redis
|
|
|
|
|
|
# Clean up build tools
|
|
RUN apk del gcc g++ make autoconf libtool
|
|
|
|
# Install Ansible
|
|
RUN apk add --no-cache 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/storage /var/www/bootstrap/cache /var/www/database && \
|
|
chmod -R 755 /var/www/storage /var/www/bootstrap/cache /var/www/database
|
|
|
|
# Copy config files
|
|
COPY nginx.conf /etc/nginx/nginx.conf
|
|
COPY supervisord.conf /etc/supervisord.conf
|
|
|
|
# Expose HTTP port
|
|
EXPOSE 80
|
|
|
|
# Start services
|
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|