-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·125 lines (96 loc) · 3.59 KB
/
Copy pathDockerfile
File metadata and controls
executable file
·125 lines (96 loc) · 3.59 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
# Multi-stage build for Laravel + React application
FROM node:22-alpine AS frontend-builder
WORKDIR /app
# Copy package files
COPY package.json package-lock.json ./
RUN npm ci --only=production
# Copy frontend source
COPY resources/js ./resources/js
COPY resources/css ./resources/css
COPY resources/views ./resources/views
COPY vite.config.js ./
COPY tailwind.config.js ./
COPY tsconfig.json ./
COPY components.json ./
COPY postcss.config.js ./
# Build frontend assets
ARG BUILD_TARGET=production
RUN if [ "$BUILD_TARGET" = "ssr" ]; then \
npm run build:ssr; \
else \
npm run build; \
fi
# Main PHP application stage using FrankenPHP
FROM dunglas/frankenphp:1-php8.3-alpine AS base
# Install system dependencies
RUN apk add --no-cache \
git \
curl \
libpng-dev \
libxml2-dev \
zip \
unzip \
postgresql-dev \
nodejs \
npm \
supervisor
# Install PHP extensions
RUN docker-php-ext-install pdo pdo_pgsql gd xml opcache
# Configure OPcache for production
RUN echo "opcache.enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \
&& echo "opcache.memory_consumption=128" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \
&& echo "opcache.interned_strings_buffer=8" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \
&& echo "opcache.max_accelerated_files=4000" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \
&& echo "opcache.revalidate_freq=2" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \
&& echo "opcache.fast_shutdown=1" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /app
# Copy composer files
COPY composer.json composer.lock ./
# Install PHP dependencies
RUN composer install --no-dev --optimize-autoloader --no-interaction
# Copy application code
COPY . .
# Copy built frontend assets
COPY --from=frontend-builder /app/public/build ./public/build
# Set permissions
RUN chown -R www-data:www-data /app \
&& chmod -R 755 /app/storage \
&& chmod -R 755 /app/bootstrap/cache
# Development stage
FROM base AS development
# Install dev dependencies
RUN composer install --optimize-autoloader --no-interaction
# Copy Node.js for SSR
COPY --from=frontend-builder /app/node_modules ./node_modules
# Disable OPcache for development
RUN echo "opcache.enable=0" > /usr/local/etc/php/conf.d/opcache-dev.ini
# Enable Xdebug for development
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug
# Xdebug configuration
RUN echo "xdebug.mode=debug,coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Test stage
FROM development AS test
# Copy test files
COPY tests ./tests
COPY phpunit.xml ./
# Production stage
FROM base AS production
# Copy FrankenPHP configuration
COPY docker/frankenphp/Caddyfile /etc/caddy/Caddyfile
# Copy supervisor configuration for background processes
COPY docker/supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Expose HTTP and HTTPS ports
EXPOSE 80 443
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost/health || exit 1
# Start FrankenPHP
CMD ["frankenphp", "run", "--config", "/etc/caddy/Caddyfile"]