-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.production
More file actions
128 lines (99 loc) · 3.9 KB
/
Dockerfile.production
File metadata and controls
128 lines (99 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# ============================================
# Production Dockerfile for Webtool 4.2
# Multi-stage build for optimized image size
# ============================================
# ============================================
# Stage 1: Build Frontend Assets
# ============================================
FROM node:20-alpine AS frontend-builder
WORKDIR /build
# Copy package files
COPY package*.json ./
# Install dependencies (includes both production and dev dependencies)
# Using npm install since package-lock.json doesn't exist
RUN npm install
# Copy source files needed for build
COPY resources ./resources
COPY public ./public
COPY vite.config.js ./
# COPY postcss.config.js ./
# COPY tailwind.config.js ./
# Build production assets
RUN npm run build
# ============================================
# Stage 2: Build PHP Production Image
# ============================================
FROM framenetbrasil/php-fpm:8.4 AS production
# Build arguments
ARG WWWGROUP=1000
ARG WWWUSER=1000
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# Create application user and directories
# Note: Your base image uses /www as WORKDIR
RUN addgroup -g ${WWWGROUP} www 2>/dev/null || true \
&& adduser -s /usr/bin/fish -D -G www -u ${WWWUSER} sail 2>/dev/null || true \
&& mkdir -p /var/log/laravel /www/storage /www/bootstrap/cache \
&& touch /var/log/laravel/laravel.log \
&& chown -R sail:www /var/log/laravel
# Set working directory (matching your base image)
WORKDIR /www
# Copy composer files
COPY composer.json composer.lock ./
# Install PHP dependencies (production only)
RUN composer install \
--no-dev \
--no-interaction \
--no-progress \
--no-scripts \
--prefer-dist \
--optimize-autoloader \
&& composer clear-cache
# Copy application code
COPY --chown=sail:www . .
# Copy built frontend assets from Stage 1
COPY --from=frontend-builder --chown=sail:www /build/public/build ./public/build
# Disable Xdebug in production (it's enabled in your base image)
RUN rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Copy production PHP configuration
COPY docker/php/php.production.ini /usr/local/etc/php/conf.d/99-production.ini
# Copy OPcache preload script
COPY docker/php/opcache-preload.php /www/opcache-preload.php
# Copy entrypoint script
COPY docker/scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# Note: Skipping post-autoload-dump during build because proc_open is disabled
# Package discovery will run automatically at runtime on first request
# Create Laravel required directories (will be recreated by entrypoint if volume overrides)
RUN mkdir -p /www/storage/framework/cache/data \
&& mkdir -p /www/storage/framework/sessions \
&& mkdir -p /www/storage/framework/views \
&& mkdir -p /www/storage/framework/testing \
&& mkdir -p /www/storage/logs \
&& mkdir -p /www/storage/app/public \
&& mkdir -p /www/bootstrap/cache
# Set proper permissions
RUN chown -R sail:www /www/storage /www/bootstrap/cache \
&& chmod -R 775 /www/storage \
&& chmod -R 775 /www/bootstrap/cache
# Create .env placeholder (will be mounted/injected at runtime)
RUN touch .env && chown sail:www .env
# Laravel production optimizations (optional - can be done at runtime)
# Uncomment if you want to bake optimizations into the image
# Note: This requires a valid .env file with APP_KEY
# RUN php artisan config:cache \
# && php artisan route:cache \
# && php artisan view:cache \
# && php artisan event:cache
# Switch to non-root user
USER sail
# Expose PHP-FPM port
EXPOSE 9000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD php -v > /dev/null 2>&1 || exit 1
# Set entrypoint to ensure directories exist
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# Start PHP-FPM
# Your base image now uses php:8.4-fpm-alpine which has php-fpm
CMD ["php-fpm", "-F"]