mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-20 10:21:32 +00:00
Dockfile added caching to package managers
This commit is contained in:
parent
5c95813854
commit
6c420fe400
1 changed files with 36 additions and 29 deletions
65
Dockerfile
65
Dockerfile
|
|
@ -1,3 +1,4 @@
|
||||||
|
# syntax=docker/dockerfile:1
|
||||||
ARG BASE_IMAGE=debian:bookworm-slim
|
ARG BASE_IMAGE=debian:bookworm-slim
|
||||||
ARG PHP_VERSION=8.4
|
ARG PHP_VERSION=8.4
|
||||||
ARG NODE_VERSION=22
|
ARG NODE_VERSION=22
|
||||||
|
|
@ -11,17 +12,23 @@ WORKDIR /app
|
||||||
# Install composer and minimal PHP for running Symfony commands
|
# Install composer and minimal PHP for running Symfony commands
|
||||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
# Use BuildKit cache mounts for apt in builder stage
|
||||||
php-cli \
|
RUN --mount=type=cache,id=apt-cache-node,target=/var/cache/apt \
|
||||||
php-xml \
|
--mount=type=cache,id=apt-lists-node,target=/var/lib/apt/lists \
|
||||||
php-mbstring \
|
apt-get update && apt-get install -y --no-install-recommends \
|
||||||
unzip \
|
php-cli \
|
||||||
git \
|
php-xml \
|
||||||
|
php-mbstring \
|
||||||
|
unzip \
|
||||||
|
git \
|
||||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy composer files and install dependencies (needed for Symfony UX assets)
|
# Copy composer files and install dependencies (needed for Symfony UX assets)
|
||||||
COPY composer.json composer.lock symfony.lock ./
|
COPY composer.json composer.lock symfony.lock ./
|
||||||
RUN composer install --no-scripts --no-autoloader --no-dev --prefer-dist --ignore-platform-reqs
|
|
||||||
|
# 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 all application files needed for cache warmup and webpack build
|
||||||
COPY .env* ./
|
COPY .env* ./
|
||||||
|
|
@ -44,7 +51,10 @@ RUN php bin/console cache:warmup -n --env=prod 2>&1
|
||||||
|
|
||||||
# Copy package files and install node dependencies
|
# Copy package files and install node dependencies
|
||||||
COPY package.json yarn.lock ./
|
COPY package.json yarn.lock ./
|
||||||
RUN yarn install --network-timeout 600000
|
# 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
|
# Build the assets
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
@ -56,12 +66,10 @@ RUN yarn cache clean && rm -rf node_modules/
|
||||||
FROM ${BASE_IMAGE} AS base
|
FROM ${BASE_IMAGE} AS base
|
||||||
ARG PHP_VERSION
|
ARG PHP_VERSION
|
||||||
|
|
||||||
# Install needed dependencies for PHP build
|
# Use BuildKit cache mounts for apt in base stage
|
||||||
#RUN apt-get update && apt-get install -y pkg-config curl libcurl4-openssl-dev libicu-dev \
|
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt \
|
||||||
# libpng-dev libjpeg-dev libfreetype6-dev gnupg zip libzip-dev libjpeg62-turbo-dev libonig-dev libxslt-dev libwebp-dev vim \
|
--mount=type=cache,id=apt-lists,target=/var/lib/apt/lists \
|
||||||
# && apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/*
|
apt-get update && apt-get -y install \
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y install \
|
|
||||||
apt-transport-https \
|
apt-transport-https \
|
||||||
lsb-release \
|
lsb-release \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
|
@ -91,10 +99,8 @@ RUN apt-get update && apt-get -y install \
|
||||||
gpg \
|
gpg \
|
||||||
sudo \
|
sudo \
|
||||||
&& apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/* \
|
&& apt-get -y autoremove && apt-get clean autoclean && rm -rf /var/lib/apt/lists/* \
|
||||||
# Create workdir and set permissions if directory does not exists
|
|
||||||
&& mkdir -p /var/www/html \
|
&& mkdir -p /var/www/html \
|
||||||
&& chown -R www-data:www-data /var/www/html \
|
&& chown -R www-data:www-data /var/www/html \
|
||||||
# delete the "index.html" that installing Apache drops in here
|
|
||||||
&& rm -rvf /var/www/html/*
|
&& rm -rvf /var/www/html/*
|
||||||
|
|
||||||
# Install composer
|
# Install composer
|
||||||
|
|
@ -110,14 +116,12 @@ ENV APACHE_ENVVARS=$APACHE_CONFDIR/envvars
|
||||||
# : ${APACHE_RUN_USER:=www-data}
|
# : ${APACHE_RUN_USER:=www-data}
|
||||||
# export APACHE_RUN_USER
|
# export APACHE_RUN_USER
|
||||||
# so that they can be overridden at runtime ("-e 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"; \
|
RUN sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS" && \
|
||||||
set -eux; . "$APACHE_ENVVARS"; \
|
set -eux; . "$APACHE_ENVVARS" && \
|
||||||
\
|
ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" && \
|
||||||
# logs should go to stdout / stderr
|
ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" && \
|
||||||
ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log"; \
|
ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" && \
|
||||||
ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log"; \
|
chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"
|
||||||
ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \
|
|
||||||
chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR";
|
|
||||||
|
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
|
|
@ -186,7 +190,6 @@ COPY --chown=www-data:www-data . .
|
||||||
# Setup apache2
|
# Setup apache2
|
||||||
RUN a2dissite 000-default.conf && \
|
RUN a2dissite 000-default.conf && \
|
||||||
a2ensite symfony.conf && \
|
a2ensite symfony.conf && \
|
||||||
# Enable php-fpm
|
|
||||||
a2enmod proxy_fcgi setenvif && \
|
a2enmod proxy_fcgi setenvif && \
|
||||||
a2enconf php${PHP_VERSION}-fpm && \
|
a2enconf php${PHP_VERSION}-fpm && \
|
||||||
a2enconf docker-php && \
|
a2enconf docker-php && \
|
||||||
|
|
@ -194,7 +197,9 @@ RUN a2dissite 000-default.conf && \
|
||||||
|
|
||||||
# Install composer and yarn dependencies for Part-DB
|
# Install composer and yarn dependencies for Part-DB
|
||||||
USER www-data
|
USER www-data
|
||||||
RUN composer install -a --no-dev && \
|
# Use BuildKit cache for Composer when running as www-data by setting COMPOSER_CACHE_DIR
|
||||||
|
RUN --mount=type=cache,id=composer-cache,target=/tmp/.composer-cache \
|
||||||
|
COMPOSER_CACHE_DIR=/tmp/.composer-cache composer install -a --no-dev && \
|
||||||
composer clear-cache
|
composer clear-cache
|
||||||
|
|
||||||
# Copy built frontend assets from node-builder stage
|
# Copy built frontend assets from node-builder stage
|
||||||
|
|
@ -210,10 +215,12 @@ USER root
|
||||||
RUN sed -i "s/PHP_VERSION/${PHP_VERSION}/g" ./.docker/partdb-entrypoint.sh
|
RUN sed -i "s/PHP_VERSION/${PHP_VERSION}/g" ./.docker/partdb-entrypoint.sh
|
||||||
|
|
||||||
# Copy entrypoint and apache2-foreground to /usr/local/bin and make it executable
|
# Copy entrypoint and apache2-foreground to /usr/local/bin and make it executable
|
||||||
RUN install ./.docker/partdb-entrypoint.sh /usr/local/bin && \
|
# Convert CRLF -> LF and install entrypoint scripts with executable mode
|
||||||
install ./.docker/apache2-foreground /usr/local/bin
|
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"]
|
ENTRYPOINT ["partdb-entrypoint.sh"]
|
||||||
CMD ["apache2-foreground"]
|
CMD ["/usr/local/bin/apache2-foreground"]
|
||||||
|
|
||||||
# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
|
# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
|
||||||
STOPSIGNAL SIGWINCH
|
STOPSIGNAL SIGWINCH
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue