Skip to content

Commit be45045

Browse files
committed
ci: Update Dockerfile for PHP 8.4 and optimize multi-stage builds
1 parent ffde49c commit be45045

File tree

1 file changed

+59
-88
lines changed

1 file changed

+59
-88
lines changed

Dockerfile

Lines changed: 59 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,105 @@
1-
### Extensions
2-
FROM php:8.2-apache as extensions
1+
### Stage 1: build PHP extensions on PHP 8.4
2+
FROM php:8.4-apache AS extensions
33

44
LABEL stage=intermediate
55

6-
RUN apt-get update && \
6+
RUN set -eux; \
7+
apt-get update; \
78
apt-get install -y --no-install-recommends \
8-
libcurl4-gnutls-dev \
99
libicu-dev \
10-
libmcrypt-dev \
11-
libvpx-dev \
12-
libxpm-dev \
1310
zlib1g-dev \
14-
libxml2-dev \
15-
libexpat1-dev \
16-
libfreetype6-dev \
11+
libzip-dev \
12+
libpng-dev \
1713
libjpeg62-turbo-dev \
1814
libwebp-dev \
19-
libbz2-dev \
20-
libgmp3-dev \
21-
libldap2-dev \
22-
unixodbc-dev \
23-
libpng-dev \
15+
libfreetype6-dev \
16+
libgmp-dev \
2417
libpq-dev \
25-
libaspell-dev \
26-
libsnmp-dev \
27-
libpcre3-dev \
28-
libtidy-dev \
29-
libzip-dev \
30-
libonig-dev
18+
libxml2-dev \
19+
libonig-dev; \
20+
rm -rf /var/lib/apt/lists/*
3121

32-
RUN ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/local/include/
22+
RUN set -eux; \
23+
docker-php-ext-install -j"$(nproc)" bcmath gmp intl opcache pdo_mysql zip
3324

34-
RUN docker-php-ext-install bcmath && \
35-
docker-php-ext-install gmp && \
36-
docker-php-ext-install intl && \
37-
docker-php-ext-install opcache && \
38-
docker-php-ext-install pdo_mysql && \
39-
docker-php-ext-install zip
25+
RUN set -eux; \
26+
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \
27+
docker-php-ext-install -j"$(nproc)" gd
4028

4129
RUN set -eux; \
42-
docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg --with-webp; \
43-
docker-php-ext-install -j "$(nproc)" gd
44-
45-
RUN echo '\
46-
opcache.enable=1\n\
47-
opcache.memory_consumption=256\n\
48-
opcache.interned_strings_buffer=16\n\
49-
opcache.max_accelerated_files=16000\n\
50-
opcache.validate_timestamps=0\n\
51-
opcache.load_comments=Off\n\
52-
opcache.save_comments=1\n\
53-
opcache.fast_shutdown=0\n\
54-
' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
55-
56-
### Composer
57-
FROM php:8.2-apache as api
58-
59-
COPY --from=extensions /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini
60-
COPY --from=extensions /usr/local/etc/php/conf.d/docker-php-ext-intl.ini /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
61-
COPY --from=extensions /usr/local/lib/php/extensions/no-debug-non-zts-20220829/intl.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/intl.so
62-
COPY --from=extensions /usr/local/lib/php/extensions/no-debug-non-zts-20220829/bcmath.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/bcmath.so
30+
{ \
31+
echo 'opcache.enable=1'; \
32+
echo 'opcache.memory_consumption=256'; \
33+
echo 'opcache.interned_strings_buffer=16'; \
34+
echo 'opcache.max_accelerated_files=16000'; \
35+
echo 'opcache.validate_timestamps=0'; \
36+
echo 'opcache.load_comments=Off'; \
37+
echo 'opcache.save_comments=1'; \
38+
echo 'opcache.fast_shutdown=0'; \
39+
} > /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
40+
41+
### Stage 2: composer install on PHP 8.4
42+
FROM php:8.4-apache AS api
6343

6444
LABEL stage=intermediate
65-
6645
WORKDIR /api
6746

68-
# install git
69-
RUN set -eux; \
70-
chown www-data:www-data /api; \
71-
apt-get update && \
72-
apt-get install -y zip unzip git
47+
COPY --from=extensions /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
48+
COPY --from=extensions /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
7349

74-
COPY --chown=www-data:www-data composer.json composer.lock /api/
50+
RUN set -eux; \
51+
apt-get update; \
52+
apt-get install -y --no-install-recommends zip unzip git; \
53+
rm -rf /var/lib/apt/lists/*
7554

76-
COPY --chmod=777 --from=composer /usr/bin/composer /usr/bin/composer
55+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
7756

57+
COPY --chown=www-data:www-data composer.json composer.lock /api/
7858
USER www-data
7959

8060
RUN set -eux; \
81-
/usr/bin/composer install --no-dev \
82-
--ignore-platform-reqs \
83-
--no-ansi \
84-
--no-autoloader \
85-
--no-interaction \
86-
--no-scripts
61+
composer install --no-dev --ignore-platform-reqs --no-ansi --no-autoloader --no-interaction --no-scripts
8762

8863
COPY --chown=www-data:www-data / /api
8964

90-
RUN rm -rf storage/app/api/scunpacked-data
91-
# RUN git clone https://github.com/StarCitizenWiki/scunpacked-data --branch=master --depth=1 storage/app/api/scunpacked-data
92-
93-
RUN rm -rf storage/app/api/ScToolBoxLocales
94-
# RUN git clone https://github.com/StarCitizenToolBox/LocalizationData --branch=main --depth=1 storage/app/api/ScToolBoxLocales
65+
RUN rm -rf storage/app/api/scunpacked-data storage/app/api/ScToolBoxLocales
9566

96-
RUN /usr/bin/composer dump-autoload --optimize --classmap-authoritative
67+
RUN composer dump-autoload --optimize --classmap-authoritative
9768

98-
### Final Image
99-
FROM php:8.2-apache
69+
### Stage 3: final runtime image on PHP 8.4
70+
FROM php:8.4-apache
10071

10172
USER root
73+
WORKDIR /var/www/html
10274

103-
RUN apt-get update && \
75+
RUN set -eux; \
76+
apt-get update; \
10477
apt-get install -y --no-install-recommends \
10578
ffmpeg \
106-
libfreetype6-dev \
107-
libjpeg62-turbo-dev \
108-
libwebp-dev \
109-
libpng-dev
110-
111-
WORKDIR /var/www/html
79+
libfreetype6 \
80+
libjpeg62-turbo \
81+
libwebp7 \
82+
libpng16-16 \
83+
libzip4; \
84+
rm -rf /var/lib/apt/lists/*
11285

11386
COPY --chown=www-data:www-data --from=api /api /var/www/html
87+
COPY --from=extensions /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
88+
COPY --from=extensions /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
89+
11490
COPY ./docker/vhost.conf /etc/apache2/sites-available/000-default.conf
11591
COPY --chown=www-data:www-data --chmod=770 ./docker/start.sh /usr/local/bin/start
116-
117-
COPY --from=extensions /usr/local/etc/php/conf.d/*.ini /usr/local/etc/php/conf.d/
118-
COPY --from=extensions /usr/local/lib/php/extensions/no-debug-non-zts-20220829/*.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/
119-
120-
RUN sed -i -e "s/extension=zip.so/;extension=zip.so/" /usr/local/etc/php/conf.d/docker-php-ext-zip.ini && \
121-
echo 'memory_limit = 1G' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini && \
122-
echo 'max_execution_time = 60' >> /usr/local/etc/php/conf.d/docker-php-executiontime.ini
123-
12492
COPY --chown=www-data:www-data --chmod=770 ./docker/schedule.sh /usr/local/bin/schedule
12593

126-
RUN chmod -R u+w,g+w /var/www/html/storage; \
94+
RUN set -eux; \
95+
echo 'memory_limit = 1G' > /usr/local/etc/php/conf.d/docker-php-memlimit.ini; \
96+
echo 'max_execution_time = 60' > /usr/local/etc/php/conf.d/docker-php-executiontime.ini; \
12797
a2enmod rewrite
12898

12999
USER www-data
130100

131-
RUN php artisan storage:link; \
101+
RUN set -eux; \
102+
php artisan storage:link; \
132103
php artisan optimize
133104

134105
CMD ["/usr/local/bin/start"]

0 commit comments

Comments
 (0)