Skip to content

Commit 73ebe16

Browse files
authored
Merge pull request #1210 from w3bdesign/dev
Update Dockerfile
2 parents 98aa307 + 11d04e1 commit 73ebe16

File tree

1 file changed

+46
-63
lines changed

1 file changed

+46
-63
lines changed

Dockerfile

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,59 @@
1-
FROM php:8.2-fpm
2-
LABEL org.opencontainers.image.authors="stephen@stephenneal.net"
1+
# Stage 1: Compile Frontend Assets
2+
FROM node:20-alpine AS node_builder
33

4-
# Update OS && install utilities
5-
RUN apt-get update -y \
6-
&& apt-get install -y \
7-
expect-dev \
8-
g++ \
9-
git \
10-
imagemagick \
11-
libgmp-dev \
12-
libfreetype6-dev \
13-
libicu-dev \
14-
libjpeg62-turbo-dev \
15-
libzip-dev \
16-
openssl \
17-
procps \
18-
sudo \
19-
supervisor \
20-
unzip \
21-
zip \
22-
zlib1g-dev
4+
WORKDIR /app/frontend
235

24-
# Install Docker PHP extensions
25-
RUN docker-php-ext-configure intl \
26-
&& docker-php-ext-configure gd \
27-
--with-freetype=/usr/include/ \
28-
--with-jpeg=/usr/include/ \
29-
&& docker-php-ext-install -j$(nproc) gd \
30-
&& docker-php-ext-install \
31-
gmp \
32-
intl \
33-
pcntl \
34-
pdo \
35-
pdo_mysql \
36-
zip
6+
# Copy package files and essential build configuration
7+
COPY package.json package-lock.json* webpack.mix.js tailwind.config.js postcss.config.js* .babelrc* ./
8+
# Ensure postcss.config.js and .babelrc are optional by using * in case they don't exist
379

38-
# Copy PHP configuration files
39-
COPY local.ini /usr/local/etc/php/conf.d/local.ini
40-
COPY www.conf /usr/local/etc/php-fpm.d/www.conf
10+
# Install all dependencies (including devDependencies like laravel-mix)
11+
RUN npm ci
4112

42-
# Set working directory
43-
WORKDIR /var/www/html
13+
# Copy frontend source code (js, css, images, etc.)
14+
COPY resources/js ./resources/js
15+
COPY resources/css ./resources/css
16+
COPY resources/img ./resources/img
17+
# Add other relevant resource directories if needed
4418

45-
# Install Nginx
46-
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
19+
# Compile assets for production
20+
RUN npm run production
4721

48-
# Install Composer
49-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
22+
# Stage 2: Setup PHP Application Environment using richarvey/nginx-php-fpm
23+
FROM richarvey/nginx-php-fpm:3.1.6 AS app
5024

51-
# Copy application skeleton (respects .dockerignore)
52-
# Ensure .dockerignore is set up to exclude vendor, node_modules, .env etc.
53-
COPY . .
25+
# Set Laravel Environment Variables as per the article
26+
ENV APP_ENV production
27+
ENV APP_DEBUG false
28+
ENV LOG_CHANNEL stderr
29+
ENV APP_KEY ${APP_KEY} # Will be provided by Render's environment
5430
55-
# Install PHP dependencies
56-
RUN composer install --optimize-autoloader --no-dev --no-interaction --no-progress
31+
# Configure richarvey/nginx-php-fpm specific settings
32+
ENV SKIP_COMPOSER 1 # We run composer via the deploy script
33+
ENV WEBROOT /var/www/html/public # Laravel's public directory
34+
ENV PHP_ERRORS_STDERR 1 # Send PHP errors to stderr for Docker logging
35+
ENV RUN_SCRIPTS 1 # Enable execution of scripts in /scripts directory
36+
ENV REAL_IP_HEADER 1 # If behind a proxy, trust X-Forwarded-For
37+
ENV COMPOSER_ALLOW_SUPERUSER 1 # Allow composer to run as root if needed by scripts
5738

58-
# Set permissions for Laravel
59-
RUN chown -R www-data:www-data storage bootstrap/cache \
60-
&& chmod -R 775 storage bootstrap/cache
39+
# Set working directory
40+
WORKDIR /var/www/html
6141

62-
# Copy Nginx site configuration
63-
# This assumes nginx-site.conf is for Nginx and configured for Laravel
64-
COPY nginx-site.conf /etc/nginx/sites-available/default
65-
RUN ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default || true \
66-
&& rm /etc/nginx/sites-enabled/default.conf || true # Remove default Nginx config if it exists with this name
42+
# Copy all application files
43+
COPY . .
6744

68-
# Copy deploy script (which handles migrations, caching)
69-
COPY deploy.sh /usr/local/bin/deploy.sh
70-
RUN chmod +x /usr/local/bin/deploy.sh
45+
# Copy compiled assets from the node_builder stage
46+
COPY --from=node_builder /app/frontend/public ./public
47+
48+
# Copy our Nginx site configuration to the standard location for richarvey images
49+
COPY nginx-site.conf /etc/nginx/sites-available/default
7150

72-
# Expose port 80 for Nginx
73-
EXPOSE 80
51+
# Copy our deploy script to the location where richarvey image expects to run scripts
52+
# Ensure deploy.sh has necessary commands (composer install, migrations, cache)
53+
RUN mkdir -p /scripts
54+
COPY deploy.sh /scripts/00-laravel-deploy.sh
55+
RUN chmod +x /scripts/00-laravel-deploy.sh
7456

75-
# CMD / ENTRYPOINT to start supervisor (which then starts nginx and php-fpm) will be added later.
76-
# Frontend asset compilation (Node.js multi-stage build) will also be added later.
57+
# The base image (richarvey/nginx-php-fpm) handles starting Nginx, PHP-FPM,
58+
# and running scripts from /scripts. Its default CMD is /start.sh.
59+
CMD ["/start.sh"]

0 commit comments

Comments
 (0)