a bit of refactoring

This commit is contained in:
Christian Winther 2024-01-04 13:07:01 +00:00
parent 7b3e11012f
commit 7dcca09c65
4 changed files with 162 additions and 112 deletions

View file

@ -1,5 +1,4 @@
data data
contrib/docker/Dockerfile
docker-compose*.yml docker-compose*.yml
.dockerignore .dockerignore
.git .git

View file

@ -8,17 +8,25 @@
ARG COMPOSER_VERSION="2.6" ARG COMPOSER_VERSION="2.6"
ARG NGINX_VERSION=1.25.3 ARG NGINX_VERSION=1.25.3
ARG FOREGO_VERSION=0.17.2 ARG FOREGO_VERSION=0.17.2
ARG PECL_EXTENSIONS_EXTRA=""
ARG PECL_EXTENSIONS="imagick redis" # PHP base configuration
ARG PHP_BASE_TYPE="apache"
ARG PHP_DATABASE_EXTENSIONS="pdo_pgsql pdo_mysql pdo_sqlite"
ARG PHP_DEBIAN_RELEASE="bullseye"
ARG PHP_EXTENSIONS_EXTRA=""
ARG PHP_EXTENSIONS="intl bcmath zip pcntl exif curl gd"
ARG PHP_VERSION="8.1" ARG PHP_VERSION="8.1"
ARG APT_PACKAGES_EXTRA="" ARG PHP_BASE_TYPE="apache"
ARG RUNTIME_UID=33 ARG PHP_DEBIAN_RELEASE="bullseye"
ARG RUNTIME_GID=33 ARG RUNTIME_UID=33 # often called 'www-data'
ARG RUNTIME_GID=33 # often called 'www-data'
# APT extra packages
ARG APT_PACKAGES_EXTRA=
# Extensions installed via [pecl install]
ARG PHP_PECL_EXTENSIONS=""
ARG PHP_PECL_EXTENSIONS_EXTRA=
# Extensions installed via [docker-php-ext-install]
ARG PHP_EXTENSIONS="intl bcmath zip pcntl exif curl gd"
ARG PHP_EXTENSIONS_EXTRA=
ARG PHP_EXTENSIONS_DATABASE="pdo_pgsql pdo_mysql pdo_sqlite"
# GPG key for nginx apt repository # GPG key for nginx apt repository
ARG NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 ARG NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
@ -75,87 +83,13 @@ RUN set -ex \
WORKDIR /var/www/ WORKDIR /var/www/
# Install package dependencies ENV APT_PACKAGES_EXTRA=${APT_PACKAGES_EXTRA}
# Install and configure base layer
COPY contrib/docker/install/base.sh /install/base.sh
RUN --mount=type=cache,id=pixelfed-apt-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/lib/apt \ RUN --mount=type=cache,id=pixelfed-apt-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/lib/apt \
--mount=type=cache,id=pixelfed-apt-cache-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/cache/apt \ --mount=type=cache,id=pixelfed-apt-cache-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/cache/apt \
<<-SCRIPT /install/base.sh
#!/bin/bash
set -ex -o errexit -o nounset -o pipefail
# ensure we keep apt cache around in a Docker environment
rm -f /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
# Standard packages
standardPackages=(
apt-utils
ca-certificates
gettext-base
git
gnupg1
gosu
libcurl4-openssl-dev
libzip-dev
locales
locales-all
nano
procps
unzip
zip
)
# Image Optimization
imageOptimization=(
gifsicle
jpegoptim
optipng
pngquant
)
# Image Processing
imageProcessing=(
libjpeg62-turbo-dev
libmagickwand-dev
libpng-dev
)
# Required for GD
gdDependencies=(
libwebp-dev
libwebp6
libxpm-dev
libxpm4
)
# Video Processing
videoProcessing=(
ffmpeg
)
# Database
databaseDependencies=(
libpq-dev
libsqlite3-dev
)
apt-get update
apt-get upgrade -y
apt-get install -y --no-install-recommends \
${standardPackages[*]} \
${imageOptimization[*]} \
${imageProcessing[*]} \
${gdDependencies[*]} \
${videoProcessing[*]} \
${databaseDependencies[*]} \
${APT_PACKAGES_EXTRA}
SCRIPT
# update locales
RUN set -ex \
&& locale-gen \
&& update-locale
####################################################### #######################################################
# PHP: extensions # PHP: extensions
@ -163,37 +97,35 @@ RUN set -ex \
FROM base AS php-extensions FROM base AS php-extensions
ARG PECL_EXTENSIONS ARG PHP_EXTENSIONS_DATABASE
ARG PECL_EXTENSIONS_EXTRA
ARG PHP_DATABASE_EXTENSIONS
ARG PHP_DEBIAN_RELEASE ARG PHP_DEBIAN_RELEASE
ARG PHP_EXTENSIONS ARG PHP_EXTENSIONS
ARG PHP_EXTENSIONS_EXTRA ARG PHP_EXTENSIONS_EXTRA
ARG PHP_PECL_EXTENSIONS
ARG PHP_PECL_EXTENSIONS_EXTRA
ARG PHP_VERSION ARG PHP_VERSION
ARG TARGETPLATFORM ARG TARGETPLATFORM
ENV PHP_EXTENSIONS_DATABASE=${PHP_EXTENSIONS_DATABASE}
ENV PHP_DEBIAN_RELEASE=${PHP_DEBIAN_RELEASE}
ENV PHP_EXTENSIONS_EXTRA=${PHP_EXTENSIONS_EXTRA}
ENV PHP_EXTENSIONS=${PHP_EXTENSIONS}
ENV PHP_PECL_EXTENSIONS_EXTRA=${PHP_PECL_EXTENSIONS_EXTRA}
ENV PHP_PECL_EXTENSIONS=${PHP_PECL_EXTENSIONS}
ENV PHP_VERSION=${PHP_VERSION}
ENV TARGETPLATFORM=${TARGETPLATFORM}
COPY contrib/docker/install/php-extensions.sh /install/php-extensions.sh
RUN --mount=type=cache,id=pixelfed-php-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/usr/src/php/ \ RUN --mount=type=cache,id=pixelfed-php-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/usr/src/php/ \
set -ex \ --mount=type=cache,id=pixelfed-apt-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/lib/apt \
# Grab the PHP source code so we can compile against it --mount=type=cache,id=pixelfed-apt-cache-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/cache/apt \
&& docker-php-source extract \ /install/php-extensions.sh
# Install pecl extensions
&& pecl install ${PECL_EXTENSIONS} ${PECL_EXTENSIONS_EXTRA} \
# PHP GD extensions
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
--with-xpm \
# PHP extensions (dependencies)
&& docker-php-ext-install -j$(nproc) ${PHP_EXTENSIONS} ${PHP_EXTENSIONS_EXTRA} ${PHP_DATABASE_EXTENSIONS} \
# Enable all extensions
&& docker-php-ext-enable ${PECL_EXTENSIONS} ${PECL_EXTENSIONS_EXTRA} ${PHP_EXTENSIONS} ${PHP_EXTENSIONS_EXTRA} ${PHP_DATABASE_EXTENSIONS}
####################################################### #######################################################
# PHP: composer and source code # PHP: composer and source code
####################################################### #######################################################
FROM base AS composer-and-src FROM php-extensions AS composer-and-src
ARG PHP_VERSION ARG PHP_VERSION
ARG PHP_DEBIAN_RELEASE ARG PHP_DEBIAN_RELEASE
@ -241,6 +173,12 @@ USER root:root
FROM base AS shared-runtime FROM base AS shared-runtime
ARG RUNTIME_UID
ARG RUNTIME_GID
ENV RUNTIME_UID=${RUNTIME_UID}
ENV RUNTIME_GID=${RUNTIME_GID}
COPY --link --from=php-extensions /usr/local/lib/php/extensions /usr/local/lib/php/extensions COPY --link --from=php-extensions /usr/local/lib/php/extensions /usr/local/lib/php/extensions
COPY --link --from=php-extensions /usr/local/etc/php /usr/local/etc/php COPY --link --from=php-extensions /usr/local/etc/php /usr/local/etc/php
COPY --link --from=composer-and-src --chown=${RUNTIME_UID}:${RUNTIME_GID} /var/www /var/www COPY --link --from=composer-and-src --chown=${RUNTIME_UID}:${RUNTIME_GID} /var/www /var/www
@ -252,9 +190,9 @@ RUN set -ex \
&& cp --recursive --link --preserve=all storage storage.skel \ && cp --recursive --link --preserve=all storage storage.skel \
&& rm -rf html && ln -s public html && rm -rf html && ln -s public html
COPY --link contrib/docker/docker-entrypoint.sh /docker-entrypoint.sh COPY contrib/docker/docker-entrypoint.sh /docker-entrypoint.sh
COPY --link contrib/docker/shared/lib.sh /lib.sh COPY contrib/docker/shared/lib.sh /lib.sh
COPY --link contrib/docker/shared/docker-entrypoint.d /docker-entrypoint.d/ COPY contrib/docker/shared/docker-entrypoint.d /docker-entrypoint.d/
ENTRYPOINT ["/docker-entrypoint.sh"] ENTRYPOINT ["/docker-entrypoint.sh"]

81
contrib/docker/install/base.sh Executable file
View file

@ -0,0 +1,81 @@
#!/bin/bash
set -ex -o errexit -o nounset -o pipefail
# Ensure we keep apt cache around in a Docker environment
rm -f /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache
# Don't install recommended packages by default
echo 'APT::Install-Recommends "false";' >>/etc/apt/apt.conf
# Don't install suggested packages by default
echo 'APT::Install-Suggests "false";' >>/etc/apt/apt.conf
# Standard packages
declare -ra standardPackages=(
apt-utils
ca-certificates
gettext-base
git
gnupg1
gosu
libcurl4-openssl-dev
libzip-dev
locales
locales-all
nano
procps
unzip
zip
software-properties-common
)
# Image Optimization
declare -ra imageOptimization=(
gifsicle
jpegoptim
optipng
pngquant
)
# Image Processing
declare -ra imageProcessing=(
libjpeg62-turbo-dev
libmagickwand-dev
libpng-dev
)
# Required for GD
declare -ra gdDependencies=(
libwebp-dev
libwebp6
libxpm-dev
libxpm4
)
# Video Processing
declare -ra videoProcessing=(
ffmpeg
)
# Database
declare -ra databaseDependencies=(
libpq-dev
libsqlite3-dev
)
apt-get update
apt-get upgrade -y
apt-get install -y \
${standardPackages[*]} \
${imageOptimization[*]} \
${imageProcessing[*]} \
${gdDependencies[*]} \
${videoProcessing[*]} \
${databaseDependencies[*]} \
${APT_PACKAGES_EXTRA}
locale-gen
update-locale

View file

@ -0,0 +1,32 @@
#!/bin/bash
set -ex -o errexit -o nounset -o pipefail
# Grab the PHP source code so we can compile against it
docker-php-source extract
# PHP GD extensions
docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
--with-xpm
# Optional script folks can copy into their image to do any [docker-php-ext-configure] work before the [docker-php-ext-install]
# this can also overwirte the [gd] configure above by simply running it again
if [[ -f /install/php-extension-configure.sh ]]; then
if [ !-x "$f" ]; then
echo >&2 "ERROR: found /install/php-extension-configure.sh but its not executable - please [chmod +x] the file!"
exit 1
fi
/install/php-extension-configure.sh
fi
# Install pecl extensions
pecl install ${PHP_PECL_EXTENSIONS} ${PHP_PECL_EXTENSIONS_EXTRA}
# PHP extensions (dependencies)
docker-php-ext-install -j$(nproc) ${PHP_EXTENSIONS} ${PHP_EXTENSIONS_EXTRA} ${PHP_EXTENSIONS_DATABASE}
# Enable all extensions
docker-php-ext-enable ${PHP_PECL_EXTENSIONS} ${PHP_PECL_EXTENSIONS_EXTRA} ${PHP_EXTENSIONS} ${PHP_EXTENSIONS_EXTRA} ${PHP_EXTENSIONS_DATABASE}