From 3519a5bc91fb75edea56b59e39fba764f3f09c1a Mon Sep 17 00:00:00 2001 From: Danny Harpigny Date: Wed, 17 Jul 2024 20:42:17 +0200 Subject: [PATCH] Optimize Docker builds --- Dockerfile | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index aae05a526e..9f386b78c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,39 +2,48 @@ # Build the assets that are needed for the frontend. This build stage is then discarded # since we won't need NodeJS anymore in the future. This Docker image ships a final production # level distribution of Pterodactyl. -FROM --platform=$TARGETOS/$TARGETARCH mhart/alpine-node:14 +FROM mhart/alpine-node:14 + WORKDIR /app -COPY . ./ -RUN yarn install --frozen-lockfile \ - && yarn run build:production + +# Install dependencies +COPY package.json . +RUN yarn install --frozen-lockfile + +# Build assets +COPY . . +RUN yarn run build:production # Stage 1: -# Build the actual container with all of the needed PHP dependencies that will run the application. -FROM --platform=$TARGETOS/$TARGETARCH php:8.1-fpm-alpine +# Build the actual container with all of the needed dependencies that will run the application. +FROM php:8.1-fpm-alpine + WORKDIR /app -COPY . ./ + +# System dependencies +RUN apk add --no-cache --update ca-certificates dcron curl git supervisor tar unzip nginx libpng-dev libxml2-dev libzip-dev certbot certbot-nginx + +# PHP dependencies +RUN docker-php-ext-install bcmath gd pdo_mysql zip + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +COPY . . COPY --from=0 /app/public/assets ./public/assets -RUN apk add --no-cache --update ca-certificates dcron curl git supervisor tar unzip nginx libpng-dev libxml2-dev libzip-dev certbot certbot-nginx \ - && docker-php-ext-configure zip \ - && docker-php-ext-install bcmath gd pdo_mysql zip \ - && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ - && cp .env.example .env \ - && mkdir -p bootstrap/cache/ storage/logs storage/framework/sessions storage/framework/views storage/framework/cache \ - && chmod 777 -R bootstrap storage \ +RUN mkdir -p bootstrap/cache/ storage/logs storage/framework/sessions storage/framework/views storage/framework/cache \ && composer install --no-dev --optimize-autoloader \ - && rm -rf .env bootstrap/cache/*.php \ - && mkdir -p /app/storage/logs/ \ + && rm -rf bootstrap/cache/*.php \ && chown -R nginx:nginx . -RUN rm /usr/local/etc/php-fpm.conf \ - && echo "* * * * * /usr/local/bin/php /app/artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root \ +RUN echo "* * * * * /usr/local/bin/php /app/artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root \ && echo "0 23 * * * certbot renew --nginx --quiet" >> /var/spool/cron/crontabs/root \ && sed -i s/ssl_session_cache/#ssl_session_cache/g /etc/nginx/nginx.conf \ && mkdir -p /var/run/php /var/run/nginx -COPY .github/docker/default.conf /etc/nginx/http.d/default.conf -COPY .github/docker/www.conf /usr/local/etc/php-fpm.conf -COPY .github/docker/supervisord.conf /etc/supervisord.conf +COPY --link .github/docker/default.conf /etc/nginx/http.d/default.conf +COPY --link .github/docker/www.conf /usr/local/etc/php-fpm.conf +COPY --link .github/docker/supervisord.conf /etc/supervisord.conf EXPOSE 80 443 ENTRYPOINT [ "/bin/ash", ".github/docker/entrypoint.sh" ]