-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.queue
More file actions
125 lines (104 loc) · 3.73 KB
/
Dockerfile.queue
File metadata and controls
125 lines (104 loc) · 3.73 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 Dockerfile for Laravel Queue Worker (Production)
# Stage 1: Build stage
FROM php:8.2-cli-alpine AS builder
# Install system dependencies and PHP extensions
RUN apk add --no-cache \
build-base \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libzip-dev \
zip \
unzip \
curl \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) \
bcmath \
gd \
pdo_mysql \
zip \
pcntl \
posix \
opcache \
exif \
&& rm -rf /var/cache/apk/*
# Install Composer
COPY --from=composer:2.6 /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
# Copy composer files
COPY composer.json composer.lock ./
# Install PHP dependencies (production optimized)
RUN composer install --no-dev --no-scripts --optimize-autoloader
# Copy application code
COPY . .
# Set APP_ENV to production to disable dev-only service providers
ENV APP_ENV=production
# Run composer scripts and generate optimized autoloader for production
RUN composer run-script post-autoload-dump --no-dev
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
# Set proper permissions
RUN chown -R www-data:www-data /var/www \
&& chmod -R 755 /var/www/storage \
&& chmod -R 755 /var/www/bootstrap/cache
# Stage 2: Production stage
FROM php:8.2-cli-alpine AS production
# Install runtime dependencies and PHP extensions
RUN apk add --no-cache \
freetype \
libjpeg-turbo \
libpng \
libzip \
&& apk add --no-cache --virtual .build-deps \
build-base \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libzip-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) \
bcmath \
gd \
pdo_mysql \
zip \
pcntl \
posix \
opcache \
exif \
&& apk del .build-deps \
&& rm -rf /var/cache/apk/*
# Production OPcache configuration
RUN echo 'opcache.memory_consumption=128' >> /usr/local/etc/php/conf.d/opcache.ini \
&& echo 'opcache.interned_strings_buffer=8' >> /usr/local/etc/php/conf.d/opcache.ini \
&& echo 'opcache.max_accelerated_files=4000' >> /usr/local/etc/php/conf.d/opcache.ini \
&& echo 'opcache.revalidate_freq=2' >> /usr/local/etc/php/conf.d/opcache.ini \
&& echo 'opcache.fast_shutdown=1' >> /usr/local/etc/php/conf.d/opcache.ini \
&& echo 'opcache.enable_cli=1' >> /usr/local/etc/php/conf.d/opcache.ini
# Production PHP configuration for queue worker
RUN echo \'memory_limit=256M\' >> /usr/local/etc/php/conf.d/php.ini
# Set working directory
WORKDIR /var/www
# Copy application from builder stage
COPY --from=builder --chown=www-data:www-data /var/www /var/www
# Copy scripts and entrypoint
COPY scripts/ /var/www/scripts/
RUN chmod +x /var/www/scripts/*.sh
# Copy entrypoint script from scripts folder
COPY scripts/docker-entrypoint-queue.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint-queue.sh
# Create necessary directories
RUN mkdir -p /var/www/storage/logs \
&& mkdir -p /var/www/storage/framework/cache \
&& mkdir -p /var/www/storage/framework/sessions \
&& mkdir -p /var/www/storage/framework/views \
&& mkdir -p /var/www/bootstrap/cache \
&& chown -R www-data:www-data /var/www \
&& chmod -R 755 /var/www/storage \
&& chmod -R 755 /var/www/bootstrap/cache
# Health check for queue worker
HEALTHCHECK --interval=60s --timeout=10s --start-period=30s --retries=3 \
CMD pgrep -f "php artisan queue:work" || exit 1
# Set entrypoint
ENTRYPOINT ["/usr/local/bin/docker-entrypoint-queue.sh"]
# Start queue worker
CMD ["php", "artisan", "queue:work", "--verbose", "--sleep=3", "--tries=3"]