Skip to content

Commit ef19c3d

Browse files
authored
Merge pull request #1216 from w3bdesign/dev
Laradock
2 parents fa5e198 + 553a566 commit ef19c3d

8 files changed

+301
-87
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "laradock"]
2+
path = laradock
3+
url = https://github.com/Laradock/laradock.git

Dockerfile

Lines changed: 90 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,97 @@
1-
# Stage 1: Compile Frontend Assets
2-
FROM node:20-alpine AS node_builder
3-
4-
WORKDIR /app/frontend
5-
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
9-
10-
# Install all dependencies (including devDependencies like laravel-mix)
11-
RUN npm ci
12-
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
18-
19-
# Compile assets for production
20-
RUN npm run production
21-
22-
# Stage 2: Setup PHP Application Environment using richarvey/nginx-php-fpm
23-
FROM richarvey/nginx-php-fpm:3.1.6 AS app
24-
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}
30-
ENV SKIP_COMPOSER 1
31-
ENV WEBROOT /var/www/html/public
32-
ENV PHP_ERRORS_STDERR 1 # Send PHP errors to stderr for Docker logging
33-
ENV RUN_SCRIPTS 1 # Enable execution of scripts in /scripts directory
34-
ENV REAL_IP_HEADER 1 # If behind a proxy, trust X-Forwarded-For
35-
ENV COMPOSER_ALLOW_SUPERUSER 1 # Allow composer to run as root if needed by scripts
36-
37-
# Set working directory
1+
# Stage 1: Base with PHP, Composer, and common extensions
2+
# We'll use an official PHP image as a base for PHP-FPM
3+
FROM php:8.2-fpm-alpine AS php_base
4+
5+
# Install system dependencies for PHP extensions and other tools
6+
RUN apk add --no-cache \
7+
bash \
8+
curl \
9+
git \
10+
supervisor \
11+
nginx \
12+
# For common PHP extensions
13+
libzip-dev \
14+
libpng-dev \
15+
libjpeg-turbo-dev \
16+
freetype-dev \
17+
icu-dev \
18+
libxml2-dev \
19+
# For pdo_mysql
20+
mysql-client
21+
22+
# Install PHP extensions
23+
# You can customize this list based on Laradock's PHP-FPM Dockerfile or your app's needs
24+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
25+
&& docker-php-ext-install -j$(nproc) \
26+
gd \
27+
intl \
28+
opcache \
29+
pdo_mysql \
30+
zip \
31+
xml \
32+
bcmath \
33+
pcntl \
34+
exif \
35+
sockets
36+
37+
# Get latest Composer
38+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
39+
40+
# Set working directory for the application
3841
WORKDIR /var/www/html
3942

40-
# Copy all application files
43+
# Copy application code
4144
COPY . .
4245

43-
# Copy compiled assets from the node_builder stage
44-
COPY --from=node_builder /app/frontend/public ./public
46+
# Install Composer dependencies
47+
RUN composer install --no-dev --no-interaction --no-progress --optimize-autoloader
48+
49+
# Optimize Laravel (optional here, can also be done at runtime start, but better in image)
50+
RUN php artisan config:cache
51+
RUN php artisan route:cache
52+
# RUN php artisan view:cache # view:cache can sometimes be problematic if paths change
53+
54+
# Fix permissions for storage and bootstrap cache
55+
RUN chown -R www-data:www-data storage bootstrap/cache public \
56+
&& chmod -R 775 storage bootstrap/cache public
57+
58+
# Stage 2: Final image with Nginx and Supervisor
59+
FROM alpine:latest
4560

46-
# Copy our Nginx site configuration to the standard location for richarvey images
47-
COPY nginx-site.conf /etc/nginx/sites-available/default
61+
# Copy PHP-FPM and application from the php_base stage
62+
COPY --from=php_base /usr/local/etc/php-fpm.d/ /usr/local/etc/php-fpm.d/
63+
COPY --from=php_base /usr/local/etc/php/ /usr/local/etc/php/
64+
COPY --from=php_base /usr/local/sbin/php-fpm /usr/local/sbin/php-fpm
65+
COPY --from=php_base /usr/local/bin/php /usr/local/bin/php
66+
COPY --from=php_base /usr/bin/composer /usr/bin/composer
67+
COPY --from=php_base /var/www/html /var/www/html
68+
COPY --from=php_base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
69+
70+
# Install Nginx and Supervisor from Alpine packages (if not already in php_base or if we want a clean stage)
71+
RUN apk add --no-cache nginx supervisor mysql-client bash
72+
73+
# Create Nginx log directory if it doesn't exist from package install
74+
RUN mkdir -p /var/log/nginx && \
75+
chown -R nginx:nginx /var/log/nginx && \
76+
mkdir -p /var/lib/nginx && \
77+
chown -R nginx:nginx /var/lib/nginx && \
78+
# Create run directory for php-fpm and nginx pid
79+
mkdir -p /run/php && \
80+
mkdir -p /run/nginx
81+
82+
# Copy Nginx configuration
83+
# We will create these files next: nginx.conf and supervisord.conf
84+
COPY nginx-prod.conf /etc/nginx/nginx.conf
85+
COPY laravel-site.conf /etc/nginx/http.d/default.conf
86+
87+
# Copy Supervisor configuration
88+
COPY supervisord.conf /etc/supervisord.conf
89+
90+
# Application root
91+
WORKDIR /var/www/html
4892

49-
# Copy our deploy script to the location where richarvey image expects to run scripts
50-
# Ensure deploy.sh has necessary commands (composer install, migrations, cache)
51-
RUN mkdir -p /scripts
52-
COPY deploy.sh /scripts/00-laravel-deploy.sh
53-
# Install dos2unix, convert line endings, and ensure the script is executable
54-
RUN apk add --no-cache dos2unix && \
55-
dos2unix /scripts/00-laravel-deploy.sh && \
56-
chmod +x /scripts/00-laravel-deploy.sh
93+
# Expose port 80 for Nginx
94+
EXPOSE 80
5795

58-
# The base image (richarvey/nginx-php-fpm) handles starting Nginx, PHP-FPM,
59-
# and running scripts from /scripts. Its default CMD is /start.sh.
60-
CMD ["/start.sh"]
96+
# Start Supervisor
97+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

docker-compose.render.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: '3.8'
2+
3+
services:
4+
php-fpm:
5+
build:
6+
context: . # We'll build from the project root
7+
dockerfile: php-fpm.render.dockerfile # A dedicated Dockerfile for this service
8+
args:
9+
# Example: Use PHP_VERSION from Laradock's .env or set a default
10+
# This can be overridden by Render environment variables if needed
11+
LARADOCK_PHP_VERSION: ${PHP_VERSION:-8.2} # Defaulting to 8.2 as in previous Dockerfile
12+
volumes:
13+
# Mount Render's persistent disk for Laravel storage
14+
# The name 'laravel-storage' should match the disk name in render.yaml
15+
- laravel-storage:/var/www/html/storage
16+
# Environment variables will be injected by Render from render.yaml
17+
# working_dir is typically /var/www/html (set in php-fpm.render.dockerfile)
18+
19+
nginx:
20+
build:
21+
context: ./laradock/nginx # Use Laradock's Nginx Dockerfile
22+
args:
23+
# Environment variables from Laradock's .env can be passed as build args if needed
24+
# For example, if Laradock's Nginx Dockerfile uses them.
25+
# Common ones are already handled by Laradock's Nginx entrypoint/config.
26+
PHP_UPSTREAM_CONTAINER: php-fpm # Ensure it points to our php-fpm service
27+
PHP_UPSTREAM_PORT: 9000
28+
NGINX_HOST_LOG_PATH: /var/log/nginx # Standard log path
29+
# Ensure NGINX_SITES_PATH points where Laradock's Dockerfile expects to find site configs
30+
# NGINX_SITES_PATH: /etc/nginx/sites-available # Default in Laradock .env
31+
volumes:
32+
# The application code (especially /public) needs to be accessible by Nginx.
33+
# Our php-fpm service builds the code into /var/www/html.
34+
# We need to share this with Nginx.
35+
# The 'app_code' volume is defined below and should be populated by the php-fpm service.
36+
# However, for Render, it's often better if the Nginx image also has the static assets.
37+
# Laradock's Nginx Dockerfile usually copies from APP_CODE_PATH_HOST.
38+
# Let's ensure our php-fpm service populates the app_code volume,
39+
# and nginx mounts it.
40+
# Alternatively, nginx Dockerfile could also COPY ../public /var/www/html/public
41+
- app_code:/var/www/html
42+
ports:
43+
- "80:80"
44+
depends_on:
45+
- php-fpm
46+
# Environment variables from render.yaml will be available.
47+
# Laradock's Nginx often uses NGINX_APP_CODE_PATH_CONTAINER=/var/www/html
48+
# and expects the site config to set root to $NGINX_APP_CODE_PATH_CONTAINER/public
49+
environment:
50+
NGINX_APP_CODE_PATH_CONTAINER: /var/www/html # To align with Laradock's Nginx config expectations
51+
# Other NGINX_... variables from laradock/.env can be set here if needed by the entrypoint
52+
53+
volumes:
54+
laravel-storage: # This name must match the disk name in render.yaml
55+
driver: local # For local testing; Render handles this differently
56+
app_code: # Volume to share application code if needed, populated by php-fpm build
57+
driver: local

laradock

Submodule laradock added at f2b5954

nginx.render.dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# nginx.render.dockerfile
2+
# Use Laradock's Nginx image as a base
3+
FROM laradock/nginx:latest
4+
5+
# Application code is expected to be in /var/www/html
6+
# Nginx needs access to the public directory.
7+
# We'll copy the application's public directory.
8+
# Note: The php-fpm container builds the full app. For Nginx, we primarily need static assets.
9+
# If your app has a build step for frontend assets that places them in public/,
10+
# ensure that step is run before this Dockerfile builds or that the assets are copied.
11+
# The php-fpm.render.dockerfile already copies the whole app, so assets should be there.
12+
13+
WORKDIR /var/www/html
14+
15+
# Copy only the public directory from the application source for Nginx to serve static files.
16+
# The rest of the app (PHP files) will be handled by PHP-FPM.
17+
# This assumes the build context for docker-compose is the project root.
18+
COPY public ./public
19+
20+
# Copy custom Nginx site configuration for the Laravel application
21+
# We will create 'laravel.render.conf' next.
22+
COPY laravel.render.conf /etc/nginx/sites-available/default.conf
23+
24+
# Expose port 80 (already exposed by base image, but good for clarity)
25+
EXPOSE 80
26+
27+
# CMD is inherited from laradock/nginx, which starts nginx.

php-fpm.render.dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# php-fpm.render.dockerfile
2+
ARG LARADOCK_PHP_VERSION=8.2
3+
FROM laradock/php-fpm:${LARADOCK_PHP_VERSION}
4+
5+
# Set working directory
6+
WORKDIR /var/www/html
7+
8+
# Install pdo_mysql if not present by default in this specific Laradock base
9+
# (Laradock's build process for php-fpm usually includes common extensions based on its .env)
10+
# For a production image, ensure all necessary extensions are explicitly built or verified.
11+
# Example: RUN docker-php-ext-install pdo_mysql zip bcmath pcntl exif sockets ...
12+
13+
# Copy application code from the build context (project root)
14+
COPY . .
15+
16+
# Install Composer dependencies
17+
# Composer should be available in the laradock/php-fpm base image.
18+
RUN composer install --no-dev --no-interaction --no-progress --optimize-autoloader
19+
20+
# Run Laravel optimizations
21+
RUN php artisan config:cache && \
22+
php artisan route:cache && \
23+
php artisan view:cache
24+
25+
# Ensure storage, bootstrap/cache, and public directories are writable by www-data
26+
# Adjust ownership/permissions as necessary for your application's needs.
27+
# The user for php-fpm is typically www-data.
28+
RUN chown -R www-data:www-data storage bootstrap/cache public && \
29+
chmod -R 775 storage bootstrap/cache public
30+
31+
# Expose port 9000 for PHP-FPM (already exposed by base image, but good for clarity)
32+
EXPOSE 9000
33+
34+
# The CMD is inherited from laradock/php-fpm, which starts php-fpm.

0 commit comments

Comments
 (0)