-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
141 lines (119 loc) · 4 KB
/
Dockerfile
File metadata and controls
141 lines (119 loc) · 4 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
FROM php:8.4.4-fpm AS extensions
COPY grpc-backup /tmp/grpc-backup
# Main application stage
FROM php:8.4.4-fpm AS builder
# Install system dependencies including protobuf
RUN apt-get update && apt-get install -y \
supervisor \
libpq-dev \
libzip-dev \
unzip \
git \
libcurl4-openssl-dev \
libssl-dev \
pkg-config \
protobuf-compiler \
protobuf-compiler-grpc \
libprotobuf-dev \
build-essential \
autoconf \
libtool \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Install PHP extensions (separate layer for better caching)
RUN docker-php-ext-install \
pdo_mysql \
zip \
sockets \
pcntl \
bcmath \
opcache
COPY --from=extensions /tmp/grpc-backup/extensions/no-debug-non-zts-20240924/*.so /usr/local/lib/php/extensions/no-debug-non-zts-20240924/
COPY --from=extensions /tmp/grpc-backup/conf.d/*.ini /usr/local/etc/php/conf.d/
FROM php:8.4.4-fpm AS production
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
supervisor \
libpq-dev \
libzip-dev \
unzip \
git \
curl \
libcurl4-openssl-dev \
libssl-dev \
pkg-config \
protobuf-compiler \
protobuf-compiler-grpc \
libprotobuf-dev \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy PHP extensions from builder
COPY --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
COPY --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
# Copy grpc_php_plugin from builder
# COPY --from=builder /usr/local/bin/grpc_php_plugin /usr/local/bin/grpc_php_plugin
# Clean up PECL cache to reduce image size
RUN rm -rf /tmp/pear
# Install Composer (separate layer)
COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
# Copy PHP configuration early (rarely changes)
COPY php.ini /usr/local/etc/php/conf.d/custom.ini
# Copy proto files first (for gRPC generation - changes less frequently than app code)
# COPY proto/ ./proto/
# # Generate gRPC clASses from proto files (do this before copying app code)
# RUN if [ -d "proto" ]; then \
# mkdir -p app/Grpc app/Grpc/GPBMetadata && \
# for proto in proto/*.proto; do \
# if [ -f "$proto" ]; then \
# echo "Generating protobuf for $proto" && \
# protoc --proto_path=proto \
# --php_out=. \
# --grpc_out=. \
# --plugin=protoc-gen-grpc=/usr/local/bin/grpc_php_plugin \
# "$proto" || echo "Warning: Failed to generate protobuf for $proto"; \
# fi \
# done \
# echo "Protobuf generation complete"; \
# if [ -d "App" ]; then \
# cp -R App/* app/ && rm -rf App; \
# fi \
# fi
# Copy composer files (for dependency caching)
COPY composer.json composer.lock ./
# Install dependencies with production optimizations
RUN composer install \
--no-dev \
--no-scripts \
--no-interaction \
--optimize-autoloader \
--classmap-authoritative \
&& composer clear-cache
# Copy application files (most frequently changing layer - put last)
COPY . .
# Copy supervisor configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Create necessary directories and set permissions
RUN mkdir -p storage/logs storage/framework/{cache,sessions,views} bootstrap/cache \
&& chown -R www-data:www-data /var/www \
&& chmod -R 755 /var/www/storage \
&& chmod -R 755 /var/www/bootstrap/cache
# Expose ports
EXPOSE 50051 8080
# Create startup script
RUN echo '#!/bin/bash\n\
set -e\n\
echo "Starting Laravel gRPC application..."\n\
php artisan config:cache\n\
php artisan route:cache\n\
php artisan view:cache\n\
php artisan migrate --force\n\
php artisan storage:link\n\
echo "Starting supervisor..."\n\
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf\n\
' > /usr/local/bin/start.sh \
&& chmod +x /usr/local/bin/start.sh
CMD ["/usr/local/bin/start.sh"]