-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
151 lines (128 loc) · 5.74 KB
/
Copy pathDockerfile
File metadata and controls
151 lines (128 loc) · 5.74 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Multi-stage Docker build for WordPress development
# Optimized for layer caching and fast rebuilds
# =============================================================================
# Stage 1: WP-CLI Builder
# Downloads and verifies WP-CLI in a separate stage for caching
# =============================================================================
FROM alpine:3.19 AS wp-cli-builder
# Install curl for downloading WP-CLI
RUN apk add --no-cache curl
# Download WP-CLI (cached unless WP-CLI version changes)
ARG WP_CLI_VERSION=2.10.0
RUN curl -o /wp-cli.phar -fSL "https://github.com/wp-cli/wp-cli/releases/download/v${WP_CLI_VERSION}/wp-cli-${WP_CLI_VERSION}.phar" \
&& chmod +x /wp-cli.phar
# =============================================================================
# Stage 2: PHP Extensions Builder
# Pre-compiles PHP extensions that rarely change
# =============================================================================
FROM wordpress:php8.3-apache AS php-extensions
# Install build dependencies (cached layer)
RUN apt-get update && apt-get install -y --no-install-recommends \
libzip-dev \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libwebp-dev \
&& rm -rf /var/lib/apt/lists/*
# Configure and install additional PHP extensions (cached layer)
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-install -j$(nproc) \
zip \
exif \
opcache
# =============================================================================
# Stage 3: Production Image
# Final optimized image with all components
# =============================================================================
FROM wordpress:php8.3-apache AS production
# Labels for image metadata
LABEL maintainer="Flavian WordPress Development"
LABEL description="Optimized WordPress development image with WP-CLI"
LABEL version="1.0.0"
# Copy compiled PHP extensions from builder stage
COPY --from=php-extensions /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
COPY --from=php-extensions /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
# Copy WP-CLI from builder stage
COPY --from=wp-cli-builder /wp-cli.phar /usr/local/bin/wp
RUN chmod +x /usr/local/bin/wp
# Install runtime dependencies only (smaller than build dependencies).
# Note: libzip5 (not libzip4) — the libzip soname bumped to .so.5 in Debian 13
# (trixie), the base of wordpress:php8.3-apache. The other runtime libs kept
# their names across bookworm→trixie.
RUN apt-get update && apt-get install -y --no-install-recommends \
less \
mariadb-client \
libzip5 \
libpng16-16 \
libjpeg62-turbo \
libfreetype6 \
libwebp7 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Configure PHP for development (cached layer - rarely changes)
RUN { \
echo 'upload_max_filesize = 64M'; \
echo 'post_max_size = 64M'; \
echo 'max_execution_time = 300'; \
echo 'memory_limit = 256M'; \
echo 'opcache.enable = 1'; \
echo 'opcache.memory_consumption = 128'; \
echo 'opcache.interned_strings_buffer = 8'; \
echo 'opcache.max_accelerated_files = 10000'; \
echo 'opcache.revalidate_freq = 0'; \
echo 'opcache.validate_timestamps = 1'; \
} > /usr/local/etc/php/conf.d/wordpress-optimized.ini
# Enable Apache modules (cached layer)
RUN a2enmod rewrite expires headers deflate filter
# Gzip text assets. Lighthouse CI budgets (lighthouserc.json) are expressed in
# *gzipped* KB (JS ≤ 200, CSS ≤ 50) and measured against the over-the-wire
# transferSize — so the origin must compress, exactly like production behind a
# CDN. mod_deflate's Debian default conf omits `text/javascript` (the MIME WP
# serves .js as), so declare the types explicitly. Compression is transparent
# to rendering, so visual-regression baselines are unaffected.
RUN { \
echo '<IfModule mod_deflate.c>'; \
echo ' <IfModule mod_filter.c>'; \
echo ' AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css'; \
echo ' AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/ecmascript'; \
echo ' AddOutputFilterByType DEFLATE application/json application/xml application/rss+xml'; \
echo ' AddOutputFilterByType DEFLATE image/svg+xml'; \
echo ' </IfModule>'; \
echo '</IfModule>'; \
} > /etc/apache2/conf-available/flavian-deflate.conf \
&& a2enconf flavian-deflate
# Create WP-CLI config directory
RUN mkdir -p /var/www/.wp-cli/cache \
&& chown -R www-data:www-data /var/www/.wp-cli
# Set working directory
WORKDIR /var/www/html
# Health check for container orchestration
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost/ || exit 1
# Expose port
EXPOSE 80
# Default command (inherited from wordpress base image)
CMD ["apache2-foreground"]
# =============================================================================
# Stage 4: Development Image (optional, for additional dev tools)
# =============================================================================
FROM production AS development
# Install development tools (only in dev image)
RUN apt-get update && apt-get install -y --no-install-recommends \
vim \
git \
unzip \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Install Composer for development
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
# Development-specific PHP configuration
RUN { \
echo 'display_errors = On'; \
echo 'display_startup_errors = On'; \
echo 'error_reporting = E_ALL'; \
echo 'log_errors = On'; \
echo 'xdebug.mode = debug,develop'; \
echo 'xdebug.start_with_request = yes'; \
echo 'xdebug.client_host = host.docker.internal'; \
} > /usr/local/etc/php/conf.d/wordpress-development.ini