From efbf4df2a25ac372cc2b91c41d9a75fbda0fe29a Mon Sep 17 00:00:00 2001 From: Quinten <67589015+QuintenQVD0@users.noreply.github.com> Date: Thu, 16 Jan 2025 08:24:58 +0100 Subject: [PATCH] Fix the docker build --- Dockerfile | 71 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3e2da6482..403aaa1e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,65 @@ # Pelican Production Dockerfile -FROM node:20-alpine AS yarn -#FROM --platform=$TARGETOS/$TARGETARCH node:20-alpine AS yarn +# ================================ +# Stage 1: Build PHP Dependencies +# ================================ +FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine AS composer WORKDIR /build COPY . ./ - -RUN yarn config set network-timeout 300000 \ - && yarn install --frozen-lockfile \ - && yarn run build:production - -FROM php:8.3-fpm-alpine -# FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine - COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer -WORKDIR /var/www/html - -# Install dependencies +# Install required libraries and PHP extensions RUN apk update && apk add --no-cache \ libpng-dev libjpeg-turbo-dev freetype-dev libzip-dev icu-dev \ zip unzip curl \ - caddy ca-certificates supervisor \ - && docker-php-ext-install bcmath gd intl zip opcache pcntl posix pdo_mysql - -# Copy the Caddyfile to the container -COPY Caddyfile /etc/caddy/Caddyfile - -# Copy the application code to the container -COPY . . - -COPY --from=yarn /build/public/assets ./public/assets - -RUN touch .env + && docker-php-ext-install \ + bcmath gd intl zip opcache pcntl posix pdo_mysql RUN composer install --no-dev --optimize-autoloader -# Set file permissions +# ================================ +# Stage 2: Build Frontend Assets +# ================================ +FROM --platform=$TARGETOS/$TARGETARCH node:20-alpine AS yarn + +WORKDIR /build + +COPY --from=composer /build . + +RUN yarn config set network-timeout 300000 \ + && yarn install --frozen-lockfile \ + && yarn run build + +# ================================ +# Stage 3: Build Final Application Image +# ================================ +FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine + +WORKDIR /var/www/html + +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer + +# Install required libraries and PHP extensions +RUN apk update && apk add --no-cache \ + libpng-dev libjpeg-turbo-dev freetype-dev libzip-dev icu-dev \ + zip unzip curl caddy ca-certificates supervisor \ + && docker-php-ext-install bcmath gd intl zip opcache pcntl posix pdo_mysql + +COPY Caddyfile /etc/caddy/Caddyfile +COPY --from=yarn /build . + +RUN touch .env + +# Set permissions for Laravel directories RUN chmod -R 755 storage bootstrap/cache \ && chown -R www-data:www-data ./ -# Add scheduler to cron +# Add Laravel scheduler to crontab RUN echo "* * * * * php /var/www/html/artisan schedule:run >> /dev/null 2>&1" | crontab -u www-data - -## supervisord config and log dir +# Configure Supervisor RUN cp .github/docker/supervisord.conf /etc/supervisord.conf && \ mkdir /var/log/supervisord/