diff --git a/Dockerfile b/Dockerfile index 6778b72..85dd17d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,48 @@ -FROM bnussbau/serversideup-php:8.3-fpm-nginx-alpine-imagick-chromium +######################## +# Base Image +######################## +FROM bnussbau/serversideup-php:8.3-fpm-nginx-alpine-imagick-chromium AS base -USER www-data +ENV AUTORUN_ENABLED="true" -# Set working directory +# Switch to the root user so we can do root things +USER root + +# Set the working directory WORKDIR /var/www/html -# Create required directories -RUN mkdir -p storage/logs \ - && mkdir -p storage/framework/{cache,sessions,views} \ - && mkdir -p bootstrap/cache \ - && mkdir -p database +# Copy the application files +COPY --chown=www-data:www-data . /var/www/html +COPY --chown=www-data:www-data .env.example .env -COPY --chown=www-data:www-data ./.env.example ./.env - -# Install application dependencies -COPY --chown=www-data:www-data composer.json composer.lock ./ +# Install the composer dependencies RUN composer install --no-interaction --prefer-dist --optimize-autoloader -COPY --chown=www-data:www-data package.json package-lock.json ./ -RUN npm ci +######################## +# Assets Image +######################## +FROM node:22-alpine AS assets -# Copy application files -COPY --chown=www-data:www-data . . -RUN npm run build +# Copy the application +COPY --from=base /var/www/html /app -ENV AUTORUN_ENABLED=true -# Expose port 80 -EXPOSE 8080 +# Set the working directory +WORKDIR /app + +# Install the node dependencies and build the assets +RUN npm ci --no-audit \ + && npm run build + +######################## +# Production Image +######################## +FROM base AS production + +# Copy the assets from the assets image +COPY --chown=www-data:www-data --from=assets /app/public/build /var/www/html/public/build + +# Drop back to the www-data user +USER www-data + +# Create the sqlite database +RUN php -r "file_exists('database/database.sqlite') || touch('database/database.sqlite');"