1- FROM debian:bullseye-slim
1+ ARG BASE_IMAGE=debian:bookworm-slim
2+ ARG PHP_VERSION=8.2
3+
4+ FROM ${BASE_IMAGE} AS base
5+ ARG PHP_VERSION
26
37# Install needed dependencies for PHP build
48# RUN apt-get update && apt-get install -y pkg-config curl libcurl4-openssl-dev libicu-dev \
59# libpng-dev libjpeg-dev libfreetype6-dev gnupg zip libzip-dev libjpeg62-turbo-dev libonig-dev libxslt-dev libwebp-dev vim \
610# && apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/*
711
8- RUN apt-get update && apt-get -y install apt-transport-https lsb-release ca-certificates curl zip mariadb-client postgresql-client \
12+ RUN apt-get update && apt-get -y install \
13+ apt-transport-https \
14+ lsb-release \
15+ ca-certificates \
16+ curl \
17+ zip \
18+ mariadb-client \
19+ postgresql-client \
920 && curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg \
1021 && sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' \
1122 && apt-get update && apt-get upgrade -y \
12- && apt-get install -y apache2 php8.1 php8.1-fpm php8.1-opcache php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-bcmath php8.1-intl php8.1-zip php8.1-xsl php8.1-sqlite3 php8.1-mysql php8.1-pgsql gpg sudo \
13- && apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/*;
23+ && apt-get install -y \
24+ apache2 \
25+ php${PHP_VERSION} \
26+ php${PHP_VERSION}-fpm \
27+ php${PHP_VERSION}-opcache \
28+ php${PHP_VERSION}-curl \
29+ php${PHP_VERSION}-gd \
30+ php${PHP_VERSION}-mbstring \
31+ php${PHP_VERSION}-xml \
32+ php${PHP_VERSION}-bcmath \
33+ php${PHP_VERSION}-intl \
34+ php${PHP_VERSION}-zip \
35+ php${PHP_VERSION}-xsl \
36+ php${PHP_VERSION}-sqlite3 \
37+ php${PHP_VERSION}-mysql \
38+ php${PHP_VERSION}-pgsql \
39+ gpg \
40+ sudo \
41+ && apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/* \
42+ # Create workdir and set permissions if directory does not exists
43+ && mkdir -p /var/www/html \
44+ && chown -R www-data:www-data /var/www/html \
45+ # delete the "index.html" that installing Apache drops in here
46+ && rm -rvf /var/www/html/*
1447
15- ENV APACHE_CONFDIR /etc/apache2
16- ENV APACHE_ENVVARS $APACHE_CONFDIR/envvars
48+ # Install node and yarn
49+ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
50+ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
51+ curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
52+ apt-get update && apt-get install -y \
53+ nodejs \
54+ yarn \
55+ && apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/*
1756
18- # Create workdir and set permissions if directory does not exists
19- RUN mkdir -p /var/www/html && chown -R www-data:www-data /var/www/html
57+ # Install composer
58+ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
59+
60+ ENV APACHE_CONFDIR=/etc/apache2
61+ ENV APACHE_ENVVARS=$APACHE_CONFDIR/envvars
2062
2163# Configure apache 2 (taken from https://github.com/docker-library/php/blob/master/8.2/bullseye/apache/Dockerfile)
2264# generically convert lines like
@@ -27,107 +69,111 @@ RUN mkdir -p /var/www/html && chown -R www-data:www-data /var/www/html
2769# so that they can be overridden at runtime ("-e APACHE_RUN_USER=...")
2870RUN sed -ri 's/^export ([^=]+)=(.*)$/: ${\1 :=\2 }\n export \1 /' "$APACHE_ENVVARS" ; \
2971 set -eux; . "$APACHE_ENVVARS" ; \
30- # delete the "index.html" that installing Apache drops in here
31- rm -rvf /var/www/html/*; \
3272 \
3373 # logs should go to stdout / stderr
3474 ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" ; \
3575 ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" ; \
3676 ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" ; \
3777 chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR" ;
3878
39- # Enable php-fpm
40- RUN a2enmod proxy_fcgi setenvif && a2enconf php8.1-fpm
79+ # ---
4180
81+ FROM scratch AS apache-config
82+ ARG PHP_VERSION
4283# Configure php-fpm to log to stdout of the container (stdout of PID 1)
4384# We have to use /proc/1/fd/1 because /dev/stdout or /proc/self/fd/1 does not point to the container stdout (because we use apache as entrypoint)
4485# We also disable the clear_env option to allow the use of environment variables in php-fpm
45- RUN { \
46- echo ' [global]' ; \
47- echo ' error_log = /proc/1/fd/1' ; \
48- echo; \
49- echo ' [www]' ; \
50- echo ' access.log = /proc/1/fd/1' ; \
51- echo ' catch_workers_output = yes' ; \
52- echo ' decorate_workers_output = no' ; \
53- echo ' clear_env = no' ; \
54- } | tee "/etc/php/8.1/fpm/pool.d/zz-docker.conf"
86+ COPY <<EOF /etc/php/${PHP_VERSION}/fpm/pool.d/zz-docker.conf
87+ [global]
88+ error_log = /proc/1/fd/1
89+
90+ [www]
91+ access.log = /proc/1/fd/1
92+ catch_workers_output = yes
93+ decorate_workers_output = no
94+ clear_env = no
95+ EOF
5596
5697# PHP files should be handled by PHP, and should be preferred over any other file type
57- RUN { \
58- echo '<FilesMatch \. php$>' ; \
59- echo '\t SetHandler application/x-httpd-php' ; \
60- echo '</FilesMatch>' ; \
61- echo; \
62- echo 'DirectoryIndex disabled' ; \
63- echo 'DirectoryIndex index.php index.html' ; \
64- echo; \
65- echo '<Directory /var/www/>' ; \
66- echo '\t Options -Indexes' ; \
67- echo '\t AllowOverride All' ; \
68- echo '</Directory>' ; \
69- } | tee "$APACHE_CONFDIR/conf-available/docker-php.conf" \
70- && a2enconf docker-php
98+ COPY <<EOF /etc/apache2/conf-available/docker-php.conf
99+ <FilesMatch \\ .php$>
100+ SetHandler application/x-httpd-php
101+ </FilesMatch>
102+
103+ DirectoryIndex disabled
104+ DirectoryIndex index.php index.html
105+
106+ <Directory /var/www/>
107+ Options -Indexes
108+ AllowOverride All
109+ </Directory>
110+ EOF
71111
72112# Enable opcache and configure it recommended for symfony (see https://symfony.com/doc/current/performance.html)
73- RUN \
74- { \
75- echo 'opcache.memory_consumption=256' ; \
76- echo 'opcache.max_accelerated_files=20000' ; \
77- echo 'opcache.validate_timestamp=0' ; \
78- # Configure Realpath cache for performance
79- echo 'realpath_cache_size=4096K' ; \
80- echo 'realpath_cache_ttl=600' ; \
81- } > /etc/php/8.1/fpm/conf.d/symfony-recommended.ini
113+ COPY <<EOF /etc/php/${PHP_VERSION}/fpm/conf.d/symfony-recommended.ini
114+ opcache.memory_consumption=256
115+ opcache.max_accelerated_files=20000
116+ opcache.validate_timestamp=0
117+ # Configure Realpath cache for performance
118+ realpath_cache_size=4096K
119+ realpath_cache_ttl=600
120+ EOF
82121
83122# Increase upload limit and enable preloading
84- RUN \
85- { \
86- echo 'upload_max_filesize=256M' ; \
87- echo 'post_max_size=300M' ; \
88- echo 'opcache.preload_user=www-data' ; \
89- echo 'opcache.preload=/var/www/html/config/preload.php' ; \
90- } > /etc/php/8.1/fpm/conf.d/partdb.ini
123+ COPY <<EOF /etc/php/${PHP_VERSION}/fpm/conf.d/partdb.ini
124+ upload_max_filesize=256M
125+ post_max_size=300M
126+ opcache.preload_user=www-data
127+ opcache.preload=/var/www/html/config/preload.php
128+ EOF
91129
92- # Install node and yarn
93- RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
94- RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
95- RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - && apt-get update && apt-get install -y nodejs yarn && apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/*
130+ COPY ./.docker/symfony.conf /etc/apache2/sites-available/symfony.conf
96131
97- # Install composer
98- COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
132+ # ---
99133
134+ FROM base
135+ ARG PHP_VERSION
100136
101137# Set working dir
102138WORKDIR /var/www/html
139+ COPY --from=apache-config / /
103140COPY --chown=www-data:www-data . .
104141
105142# Setup apache2
106- RUN a2dissite 000-default.conf
107- COPY ./.docker/symfony.conf /etc/apache2/sites-available/symfony.conf
108- RUN a2ensite symfony.conf
109- RUN a2enmod rewrite
143+ RUN a2dissite 000-default.conf && \
144+ a2ensite symfony.conf && \
145+ # Enable php-fpm
146+ a2enmod proxy_fcgi setenvif && \
147+ a2enconf php${PHP_VERSION}-fpm && \
148+ a2enconf docker-php && \
149+ a2enmod rewrite
110150
111151# Install composer and yarn dependencies for Part-DB
112152USER www-data
113- RUN composer install -a --no-dev && composer clear-cache
114- RUN yarn install --network-timeout 600000 && yarn build && yarn cache clean && rm -rf node_modules/
153+ RUN composer install -a --no-dev && \
154+ composer clear-cache
155+ RUN yarn install --network-timeout 600000 && \
156+ yarn build && \
157+ yarn cache clean && \
158+ rm -rf node_modules/
115159
116160# Use docker env to output logs to stdout
117161ENV APP_ENV=docker
118162ENV DATABASE_URL="sqlite:///%kernel.project_dir%/uploads/app.db"
119163
120164USER root
121165
122- # Copy entrypoint to /usr/local/bin and make it executable
123- RUN cp ./.docker/partdb-entrypoint.sh /usr/local/bin/partdb-entrypoint.sh && chmod +x /usr/local/bin/partdb-entrypoint.sh
124- # Copy apache2-foreground to /usr/local/bin and make it executable
125- RUN cp ./.docker/apache2-foreground /usr/local/bin/apache2-foreground && chmod +x /usr/local/bin/apache2-foreground
166+ # Replace the php version placeholder in the entry point, with our php version
167+ RUN sed -i "s/PHP_VERSION/${PHP_VERSION}/g" ./.docker/partdb-entrypoint.sh
168+
169+ # Copy entrypoint and apache2-foreground to /usr/local/bin and make it executable
170+ RUN install ./.docker/partdb-entrypoint.sh /usr/local/bin && \
171+ install ./.docker/apache2-foreground /usr/local/bin
126172ENTRYPOINT ["partdb-entrypoint.sh" ]
127173CMD ["apache2-foreground" ]
128174
129175# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
130176STOPSIGNAL SIGWINCH
131177
132178EXPOSE 80
133- VOLUME ["/var/www/html/uploads" , "/var/www/html/public/media" ]
179+ VOLUME ["/var/www/html/uploads" , "/var/www/html/public/media" ]
0 commit comments