-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
120 lines (100 loc) · 2.95 KB
/
Dockerfile
File metadata and controls
120 lines (100 loc) · 2.95 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
FROM php:8.4.4-fpm AS builder
# Install system dependencies including protobuf
RUN apt-get update && apt-get install -y \
libpq-dev \
libzip-dev \
unzip \
git \
curl \
wget \
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 backed up gRPC extension files
COPY grpc-backup/extensions/ /usr/local/lib/php/extensions/
COPY grpc-backup/conf.d/ /usr/local/etc/php/conf.d/
# Install remaining PECL extensions
# docke
FROM php:8.4.4-fpm AS production
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
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/
# 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 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 . .
# 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
# Create a non-root user for security
RUN groupadd -g 1000 laravel \
&& useradd -u 1000 -g laravel -m laravel
# Expose ports
EXPOSE 50051 8080
# Health check for gRPC service
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD nc -z localhost 50051 || exit 1
# 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\
php-fpm\n\
' > /usr/local/bin/start.sh \
&& chmod +x /usr/local/bin/start.sh
CMD ["/usr/local/bin/start.sh"]