-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reduce the weight of the Docker image
- Loading branch information
Juan Manuel "Kang" Perez
committed
Mar 18, 2024
1 parent
a66a2a4
commit 8e91faa
Showing
1 changed file
with
81 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,100 @@ | ||
FROM php:8.2-fpm-alpine | ||
|
||
# https://github.com/docker-library/php/blob/master/8.2/alpine3.18/fpm/Dockerfile#L33 | ||
ARG fpm_user=82:82 | ||
ENV FPM_USER=${fpm_user} | ||
|
||
LABEL org.opencontainers.image.authors="[email protected]" | ||
LABEL org.opencontainers.image.url="https://github.com/tchapi/davis/pkgs/container/davis" | ||
LABEL org.opencontainers.image.description="A simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 4" | ||
|
||
############################################################### | ||
# Run update, and gets basic packages and packages for runtime | ||
FROM php:8.2-fpm-alpine AS base-image | ||
|
||
RUN apk --no-progress --update add --no-cache \ | ||
curl unzip fcgi \ | ||
# These are for php-intl | ||
icu-libs \ | ||
# This one is for IMAP (to provide libc-client.so) | ||
c-client \ | ||
# This one for LDAP | ||
libldap \ | ||
# These are for GD (map image in mail) | ||
freetype \ | ||
libjpeg-turbo \ | ||
libpng \ | ||
# This is for PostgreSQL | ||
libpq | ||
curl unzip \ | ||
# These are for php-intl | ||
icu-libs \ | ||
# This one is for IMAP (to provide libc-client.so) | ||
c-client \ | ||
# This one for LDAP | ||
libldap \ | ||
# These are for GD (map image in mail) | ||
freetype \ | ||
libjpeg-turbo \ | ||
libpng \ | ||
# This is for PostgreSQL | ||
libpq \ | ||
# For the webserver and process manager | ||
caddy supervisor | ||
|
||
|
||
########################################################################### | ||
# Build all extension on a diferent build environment so keep things clean | ||
FROM base-image AS extension-builder | ||
|
||
RUN apk --update --no-cache add\ | ||
# Intl support | ||
--virtual build-deps-intl \ | ||
icu-dev \ | ||
# PDO: PostgreSQL | ||
--virtual build-deps-pg \ | ||
libpq-dev \ | ||
# # PDO: PostgreSQL | ||
--virtual build-deps-pg libpq-dev \ | ||
# GD (map image in mail) | ||
--virtual build-deps-gd \ | ||
freetype-dev \ | ||
libjpeg-turbo-dev \ | ||
libpng-dev \ | ||
# LDAP auth support | ||
--virtual build-deps-ldap \ | ||
openldap-dev \ | ||
# IMAP auth support | ||
--virtual build-deps-imap \ | ||
imap-dev \ | ||
openssl-dev \ | ||
krb5-dev | ||
|
||
# Leaving a Docker layer per extension so in case it fails I have it cached to develop faster. | ||
|
||
# Intl support | ||
RUN apk --update --virtual build-deps-intl add --no-cache icu-dev \ | ||
&& docker-php-ext-install intl \ | ||
&& apk del build-deps-intl \ | ||
&& rm -rf /tmp/* | ||
|
||
RUN docker-php-ext-install intl | ||
# PDO: MySQL | ||
RUN docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \ | ||
&& docker-php-ext-install pdo_mysql | ||
|
||
RUN docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd && \ | ||
docker-php-ext-install pdo_mysql | ||
# PDO: PostgreSQL | ||
RUN apk --update --virtual build-deps-pg add --no-cache libpq-dev \ | ||
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ | ||
&& docker-php-ext-install pgsql pdo_pgsql \ | ||
&& apk del build-deps-pg \ | ||
&& rm -rf /tmp/* | ||
|
||
RUN docker-php-ext-configure pgsql --with-pgsql=/usr/local/pgsql && \ | ||
docker-php-ext-install pgsql pdo_pgsql | ||
# GD (map image in mail) | ||
RUN apk --update --virtual build-deps-gd add --no-cache freetype-dev libjpeg-turbo-dev libpng-dev \ | ||
&& docker-php-ext-configure gd --with-freetype \ | ||
&& docker-php-ext-install gd \ | ||
&& docker-php-ext-enable gd \ | ||
&& apk del build-deps-gd \ | ||
&& rm -rf /tmp/* | ||
|
||
RUN docker-php-ext-configure gd --with-freetype && \ | ||
docker-php-ext-install gd && \ | ||
docker-php-ext-enable gd | ||
# LDAP auth support | ||
RUN apk --update --virtual build-deps-ldap add --no-cache openldap-dev \ | ||
&& docker-php-ext-configure ldap \ | ||
&& docker-php-ext-install ldap \ | ||
&& apk del build-deps-ldap \ | ||
&& rm -rf /tmp/* | ||
|
||
RUN docker-php-ext-configure ldap && \ | ||
docker-php-ext-install ldap | ||
# IMAP auth support | ||
RUN apk --update --virtual build-deps-imap add --no-cache imap-dev openssl-dev krb5-dev \ | ||
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \ | ||
&& docker-php-ext-install imap \ | ||
&& apk del build-deps-imap \ | ||
&& rm -rf /tmp/* | ||
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \ | ||
docker-php-ext-install imap | ||
|
||
# Davis installation | ||
ADD . /var/www/davis | ||
WORKDIR /var/www/davis | ||
|
||
################################################### | ||
# Installing composer and downloading dependencies | ||
FROM extension-builder AS composer | ||
|
||
# Install Composer 2, then dependencies | ||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | ||
ADD --chown=www-data:www-data . /var/www/davis/ | ||
WORKDIR /var/www/davis | ||
RUN APP_ENV=prod COMPOSER_ALLOW_SUPERUSER=1 composer install --no-ansi --no-dev --no-interaction --no-progress --optimize-autoloader | ||
|
||
# PHP-FPM healthcheck | ||
RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf | ||
RUN curl https://raw.githubusercontent.com/renatomefi/php-fpm-healthcheck/v0.5.0/php-fpm-healthcheck \ | ||
-o /usr/local/bin/php-fpm-healthcheck -s \ | ||
&& chmod +x /usr/local/bin/php-fpm-healthcheck | ||
|
||
# Cleanup (only useful when using --squash) | ||
RUN docker-php-source delete | ||
RUN rm -rf /usr/local/bin/composer | ||
################################################### | ||
# Final image | ||
FROM base-image | ||
|
||
# Sets the app folder owner as the FPM user | ||
RUN chown -R ${FPM_USER} . | ||
# https://github.com/docker-library/php/blob/master/8.2/alpine3.18/fpm/Dockerfile#L33 | ||
ARG fpm_user=82:82 | ||
ENV FPM_USER=${fpm_user} | ||
|
||
USER $FPM_USER | ||
LABEL org.opencontainers.image.authors="[email protected]" | ||
LABEL org.opencontainers.image.url="https://github.com/tchapi/davis/pkgs/container/davis-standalone" | ||
LABEL org.opencontainers.image.description="A simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 4 (Standalone version with reverse-proxy)" | ||
|
||
HEALTHCHECK --interval=30s --timeout=1s CMD php-fpm-healthcheck || exit 1 | ||
COPY --from=extension-builder /usr/local/etc/php/conf.d /usr/local/etc/php/conf.d/ | ||
COPY --from=extension-builder /usr/local/lib/php/extensions /usr/local/lib/php/extensions/ | ||
COPY --from=composer /var/www/davis/vendor /var/www/davis/vendor/ | ||
|
||
ADD --chown=$FPM_USER bin migrations public src /var/www/davis/ | ||
USER $FPM_USER |