# syntax=docker/dockerfile:1 ARG BASE_IMAGE=debian:bookworm-slim ARG PHP_VERSION=8.4 ARG NODE_VERSION=22 # Node.js build stage for building frontend assets # Use native platform for build stage as it's platform-independent FROM --platform=$BUILDPLATFORM node:${NODE_VERSION}-bookworm-slim AS node-builder ARG TARGETARCH WORKDIR /app # Install composer and minimal PHP for running Symfony commands COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # Use BuildKit cache mounts for apt in builder stage RUN --mount=type=cache,id=apt-cache-node-$TARGETARCH,target=/var/cache/apt \ --mount=type=cache,id=apt-lists-node-$TARGETARCH,target=/var/lib/apt/lists \ apt-get update && apt-get install -y --no-install-recommends \ php-cli \ php-xml \ php-mbstring \ unzip \ git \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Copy composer files and install dependencies (needed for Symfony UX assets) COPY composer.json composer.lock symfony.lock ./ # Use BuildKit cache for Composer downloads RUN --mount=type=cache,id=composer-cache,target=/root/.cache/composer \ composer install --no-scripts --no-autoloader --no-dev --prefer-dist --ignore-platform-reqs # Copy all application files needed for cache warmup and webpack build COPY .env* ./ COPY bin ./bin COPY config ./config COPY src ./src COPY translations ./translations COPY public ./public COPY assets ./assets COPY webpack.config.js ./ # Generate autoloader RUN composer dump-autoload # Create required directories for cache warmup RUN mkdir -p var/cache var/log uploads public/media # Dump translations, which we need for cache warmup RUN php bin/console cache:warmup -n --env=prod 2>&1 # Copy package files and install node dependencies COPY package.json yarn.lock ./ # Use BuildKit cache for yarn/npm RUN --mount=type=cache,id=yarn-cache,target=/root/.cache/yarn \ --mount=type=cache,id=npm-cache,target=/root/.npm \ yarn install --network-timeout 600000 # Build the assets RUN yarn build # Clean up RUN yarn cache clean && rm -rf node_modules/ # Base stage for PHP FROM ${BASE_IMAGE} AS base ARG PHP_VERSION ARG TARGETARCH # Use BuildKit cache mounts for apt in base stage RUN --mount=type=cache,id=apt-cache-$TARGETARCH,target=/var/cache/apt \ --mount=type=cache,id=apt-lists-$TARGETARCH,target=/var/lib/apt/lists \ apt-get update && apt-get -y install \ apt-transport-https \ lsb-release \ ca-certificates \ curl \ zip \ mariadb-client \ postgresql-client \ && curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg \ && 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' \ && apt-get update && apt-get upgrade -y \ && apt-get install -y \ apache2 \ php${PHP_VERSION} \ php${PHP_VERSION}-fpm \ php${PHP_VERSION}-opcache \ php${PHP_VERSION}-curl \ php${PHP_VERSION}-gd \ php${PHP_VERSION}-mbstring \ php${PHP_VERSION}-xml \ php${PHP_VERSION}-bcmath \ php${PHP_VERSION}-intl \ php${PHP_VERSION}-zip \ php${PHP_VERSION}-xsl \ php${PHP_VERSION}-sqlite3 \ php${PHP_VERSION}-mysql \ php${PHP_VERSION}-pgsql \ gpg \ sudo \ && apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/* \ && mkdir -p /var/www/html \ && chown -R www-data:www-data /var/www/html \ && rm -rvf /var/www/html/* # Install composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer ENV APACHE_CONFDIR=/etc/apache2 ENV APACHE_ENVVARS=$APACHE_CONFDIR/envvars # Configure apache 2 (taken from https://github.com/docker-library/php/blob/master/8.2/bullseye/apache/Dockerfile) # generically convert lines like # export APACHE_RUN_USER=www-data # into # : ${APACHE_RUN_USER:=www-data} # export APACHE_RUN_USER # so that they can be overridden at runtime ("-e APACHE_RUN_USER=...") RUN sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS" && \ set -eux; . "$APACHE_ENVVARS" && \ ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" && \ ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" && \ ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" && \ chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR" # --- FROM scratch AS apache-config ARG PHP_VERSION # Configure php-fpm to log to stdout of the container (stdout of PID 1) # 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) # We also disable the clear_env option to allow the use of environment variables in php-fpm COPY < SetHandler application/x-httpd-php DirectoryIndex disabled DirectoryIndex index.php index.html Options -Indexes AllowOverride All EOF # Enable opcache and configure it recommended for symfony (see https://symfony.com/doc/current/performance.html) COPY < LF and install entrypoint scripts with executable mode RUN sed -i 's/\r$//' ./.docker/partdb-entrypoint.sh ./.docker/apache2-foreground && \ install -m 0755 ./.docker/partdb-entrypoint.sh /usr/local/bin/ && \ install -m 0755 ./.docker/apache2-foreground /usr/local/bin/ ENTRYPOINT ["partdb-entrypoint.sh"] CMD ["/usr/local/bin/apache2-foreground"] # https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop STOPSIGNAL SIGWINCH EXPOSE 80 VOLUME ["/var/www/html/uploads", "/var/www/html/public/media"]