-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
132 lines (110 loc) · 3.97 KB
/
Dockerfile
File metadata and controls
132 lines (110 loc) · 3.97 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
# Working Laravel Dockerfile
FROM php:8.3-fpm-alpine AS base
# Install system dependencies
RUN apk add --no-cache \
nginx \
supervisor \
bash \
curl \
git \
unzip \
libzip-dev \
libpng-dev \
libjpeg-turbo-dev \
freetype-dev \
oniguruma-dev \
postgresql-dev \
postgresql-client \
libxml2-dev \
icu-dev
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) \
gd \
pdo_pgsql \
pgsql \
zip \
mbstring \
exif \
pcntl \
bcmath \
intl \
opcache
# Install Redis
RUN apk add --no-cache --virtual .build-deps autoconf g++ make \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& apk del .build-deps
# Install Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
WORKDIR /var/www
# Development stage
FROM base AS development
# Copy configuration files first
COPY docker/php/dev/php.ini /usr/local/etc/php/conf.d/php.ini
COPY docker/php/dev/www.conf /usr/local/etc/php-fpm.d/www.conf
COPY docker/nginx/dev/nginx.conf /etc/nginx/nginx.conf
COPY docker/nginx/dev/default.conf /etc/nginx/http.d/default.conf
COPY docker/supervisor/dev/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Copy composer files and install dependencies without scripts
COPY composer.json composer.lock* ./
RUN composer install --no-scripts --no-interaction --optimize-autoloader
# Copy the rest of the application
COPY . .
# Create necessary directories BEFORE running composer scripts
RUN mkdir -p \
storage/app/public \
storage/framework/cache \
storage/framework/sessions \
storage/framework/views \
storage/logs \
bootstrap/cache \
&& chown -R www-data:www-data storage bootstrap/cache \
&& chmod -R 775 storage bootstrap/cache
# Now run composer scripts after directories exist
RUN composer dump-autoload --optimize
# Copy and setup entrypoint
COPY docker/entrypoint/dev-entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
# Production stage
FROM base AS production
# Copy production configuration
COPY docker/php/prod/php.ini /usr/local/etc/php/conf.d/php.ini
COPY docker/php/prod/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
COPY docker/php/prod/www.conf /usr/local/etc/php-fpm.d/www.conf
COPY docker/nginx/prod/nginx.conf /etc/nginx/nginx.conf
COPY docker/nginx/prod/default.conf /etc/nginx/conf.d/default.conf
COPY docker/supervisor/prod/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Install production dependencies without scripts
COPY composer.json composer.lock* ./
RUN composer install --no-dev --no-scripts --no-interaction --optimize-autoloader
# Copy and build application
COPY package.json package-lock.json* ./
COPY . .
# Create necessary directories BEFORE running any Laravel commands
RUN mkdir -p \
storage/app/public \
storage/framework/cache \
storage/framework/sessions \
storage/framework/views \
storage/logs \
bootstrap/cache \
&& chown -R www-data:www-data storage bootstrap/cache \
&& chmod -R 755 storage bootstrap/cache
# Run composer scripts and build assets
RUN composer dump-autoload --optimize \
&& (npm install && npm run build) || echo "Frontend build skipped"
# Optimize Laravel for production (after directories exist)
RUN php artisan config:cache || echo "Config cache skipped" \
&& php artisan route:cache || echo "Route cache skipped" \
&& php artisan view:cache || echo "View cache skipped"
# Setup entrypoint
COPY docker/entrypoint/prod-entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
USER www-data
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]