refactored dockerfile

This commit is contained in:
Alex Justesen 2025-03-27 21:20:03 -04:00
parent eee79fd11f
commit 26c752d2e3

View file

@ -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 WORKDIR /var/www/html
# Create required directories # Copy the application files
RUN mkdir -p storage/logs \ COPY --chown=www-data:www-data . /var/www/html
&& mkdir -p storage/framework/{cache,sessions,views} \ COPY --chown=www-data:www-data .env.example .env
&& mkdir -p bootstrap/cache \
&& mkdir -p database
COPY --chown=www-data:www-data ./.env.example ./.env # Install the composer dependencies
# Install application dependencies
COPY --chown=www-data:www-data composer.json composer.lock ./
RUN composer install --no-interaction --prefer-dist --optimize-autoloader 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 the application
COPY --chown=www-data:www-data . . COPY --from=base /var/www/html /app
RUN npm run build
ENV AUTORUN_ENABLED=true # Set the working directory
# Expose port 80 WORKDIR /app
EXPOSE 8080
# 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');"