forked from the-djmaze/snappymail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Add Docker Hub image (the-djmaze#965)
* Enhancement: Add Docker Hub image * Push to ghcr.io * Add all `org.opencontainers.image.xxx` labels using `--label` instead of `LABEL` * Change `php-fpm` to listen on `:9000` to expose prometheus metrics via `php-fpm_exporter` * Include `yarn.lock` to speed up builds * Reorder * Use correct sha for pr * Add logging before overriding values in config * Add `DEBUG=true` env var for verbose `entrypoint.sh` logs * Print php exception when snappymail fails to generate data directory and config file on the very first time * Log snappymail version * Fix COPY statement * Add .dockerignore * Add `USER` and `ENTRYPOINT` * Update `.dockerignore` * Add docker image test * Push only if image test succeeds * Log when startup is successful * Use plain `docker build` in `build_and_test.sh` * Fix test output
- Loading branch information
1 parent
6552a93
commit 24dbff9
Showing
20 changed files
with
5,200 additions
and
228 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,51 +1,116 @@ | ||
# Inspired by the original Rainloop dockerfile from youtous on GitLab | ||
FROM php:8.1-fpm-bullseye | ||
|
||
ARG FILES_ZIP | ||
# syntax=docker/dockerfile:1 | ||
|
||
FROM alpine:3.15 AS builder | ||
RUN apk add --no-cache php7 php7-json php-phar php-zip | ||
RUN apk add --no-cache npm | ||
RUN npm install -g gulp yarn | ||
WORKDIR /source | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install | ||
COPY . . | ||
# Patch release.php with hotfix from: https://github.com/xgbstar1/snappymail-docker/blob/main/Dockerfile, so that release.php doesn't fail with error | ||
RUN sed -i 's_^if.*rename.*snappymail.v.0.0.0.*$_if (!!system("mv snappymail/v/0.0.0 snappymail/v/{$package->version}")) {_' cli/release.php || true | ||
RUN php release.php | ||
RUN set -eux; \ | ||
VERSION=$( ls build/dist/releases/webmail ); \ | ||
ls -al build/dist/releases/webmail/$VERSION/snappymail-$VERSION.tar.gz; \ | ||
mkdir -p /snappymail; \ | ||
tar -zxvf build/dist/releases/webmail/$VERSION/snappymail-$VERSION.tar.gz -C /snappymail; \ | ||
find /snappymail -type d -exec chmod 550 {} \; ; \ | ||
find /snappymail -type f -exec chmod 440 {} \; ; \ | ||
find /snappymail/data -type d -exec chmod 750 {} \; ; \ | ||
# Remove unneeded files | ||
rm -v /snappymail/README.md /snappymail/_include.php | ||
|
||
# Inspired by the original Rainloop dockerfile from youtous on GitLab | ||
FROM php:8.1-fpm-alpine AS final | ||
|
||
LABEL org.label-schema.description="SnappyMail webmail client image using nginx, php-fpm based on Debian Buster" | ||
|
||
ENV UID=991 GID=991 UPLOAD_MAX_SIZE=25M LOG_TO_STDERR=true MEMORY_LIMIT=128M SECURE_COOKIES=true | ||
ENV fpm.pool.clear_env=false | ||
LABEL org.label-schema.description="SnappyMail webmail client image using nginx, php-fpm on Alpine" | ||
|
||
# Install dependencies such as nginx | ||
RUN mkdir -p /usr/share/man/man1/ /usr/share/man/man3/ /usr/share/man/man7/ && \ | ||
apt-get update -q --fix-missing && \ | ||
apt-get -y upgrade && \ | ||
apt-get install --no-install-recommends -y \ | ||
apt-transport-https gnupg openssl wget curl ca-certificates nginx supervisor sudo \ | ||
unzip libzip-dev libxml2-dev libldb-dev libldap2-dev \ | ||
sqlite3 libsqlite3-dev libsqlite3-0 libpq-dev postgresql-client mariadb-client logrotate \ | ||
zip mlocate libpcre3-dev libicu-dev \ | ||
build-essential chrpath libssl-dev \ | ||
libxft-dev libfreetype6 libfreetype6-dev \ | ||
libpng-dev libjpeg62-turbo-dev \ | ||
libfontconfig1 libfontconfig1-dev \ | ||
&& \ | ||
rm -rf /var/lib/apt/lists/* | ||
RUN apk add --no-cache ca-certificates nginx supervisor bash | ||
|
||
# Install PHP extensions | ||
RUN php -m && \ | ||
docker-php-ext-configure ldap --with-libdir=lib/$(uname -m)-linux-gnu/ && \ | ||
docker-php-ext-configure intl && \ | ||
docker-php-ext-configure gd --with-freetype --with-jpeg && \ | ||
docker-php-ext-install ldap opcache pdo_mysql pdo_pgsql zip intl gd && \ | ||
php -m | ||
# gd | ||
RUN set -eux; \ | ||
apk add --no-cache freetype libjpeg-turbo libpng; \ | ||
apk add --no-cache --virtual .deps freetype-dev libjpeg-turbo-dev libpng-dev; \ | ||
docker-php-ext-configure gd --with-freetype --with-jpeg; \ | ||
docker-php-ext-install gd; \ | ||
apk del .deps | ||
# gnupg | ||
RUN set -eux; \ | ||
apk add --no-cache gnupg gpgme; \ | ||
apk add --no-cache --virtual .deps gpgme-dev; \ | ||
apk add --no-cache --virtual .build-dependencies $PHPIZE_DEPS; \ | ||
pecl install gnupg; \ | ||
docker-php-ext-enable gnupg; \ | ||
docker-php-source delete; \ | ||
apk del .build-dependencies; \ | ||
apk del .deps | ||
# intl | ||
RUN set -eux; \ | ||
apk add --no-cache icu-libs; \ | ||
apk add --no-cache --virtual .deps icu-dev; \ | ||
docker-php-ext-configure intl; \ | ||
docker-php-ext-install intl; \ | ||
apk del .deps | ||
# ldap | ||
RUN set -eux; \ | ||
apk add --no-cache libldap; \ | ||
apk add --no-cache --virtual .deps openldap-dev; \ | ||
docker-php-ext-configure ldap; \ | ||
docker-php-ext-install ldap; \ | ||
apk del .deps | ||
# mysql | ||
RUN docker-php-ext-install pdo_mysql | ||
# opcache | ||
RUN docker-php-ext-install opcache | ||
# postgres | ||
RUN set -eux; \ | ||
apk add --no-cache postgresql-libs; \ | ||
apk add --no-cache --virtual .deps postgresql-dev; \ | ||
docker-php-ext-install pdo_pgsql; \ | ||
apk del .deps | ||
# redis | ||
RUN set -eux; \ | ||
apk add --no-cache liblzf zstd-libs; \ | ||
apk add --no-cache --virtual .deps zstd-dev; \ | ||
apk add --no-cache --virtual .build-dependencies $PHPIZE_DEPS; \ | ||
pecl install igbinary; \ | ||
docker-php-ext-enable igbinary; \ | ||
pecl install --configureoptions 'enable-redis-igbinary="yes" enable-redis-lzf="yes" enable-redis-zstd="yes"' redis; \ | ||
docker-php-ext-enable redis; \ | ||
docker-php-source delete; \ | ||
apk del .build-dependencies; \ | ||
apk del .deps | ||
# zip | ||
RUN set -eux; \ | ||
apk add --no-cache libzip; \ | ||
apk add --no-cache --virtual .deps libzip-dev; \ | ||
docker-php-ext-install zip; \ | ||
apk del .deps | ||
|
||
# Install snappymail | ||
WORKDIR /tmp | ||
COPY ${FILES_ZIP} . | ||
RUN mkdir /snappymail && \ | ||
unzip -q ${FILES_ZIP} -d /snappymail && \ | ||
find /snappymail -type d -exec chmod 755 {} \; && \ | ||
find /snappymail -type f -exec chmod 644 {} \; && \ | ||
rm -rf ${FILES_ZIP} | ||
# The 'www-data' user/group in alpine is 82:82. The 'nginx' user/group in alpine is 101:101, and is part of www-data group | ||
COPY --chown=www-data:www-data --from=builder /snappymail /snappymail | ||
# Use a custom snappymail data folder | ||
RUN mv -v /snappymail/data /var/lib/snappymail; | ||
# Setup configs | ||
COPY --chown=root:root .docker/release/files / | ||
RUN set -eux; \ | ||
chown www-data:www-data /snappymail/include.php; \ | ||
chmod 440 /snappymail/include.php; \ | ||
chmod +x /entrypoint.sh; \ | ||
# Disable the built-in php-fpm configs, since we're using our own config | ||
mv -v /usr/local/etc/php-fpm.d/docker.conf /usr/local/etc/php-fpm.d/docker.conf.disabled; \ | ||
mv -v /usr/local/etc/php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf.disabled; \ | ||
mv -v /usr/local/etc/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf.disabled; | ||
|
||
# Install other content | ||
COPY files / | ||
RUN chmod +x /entrypoint.sh && chmod +x /logrotate-loop.sh | ||
VOLUME /snappymail/data | ||
USER root | ||
WORKDIR /snappymail | ||
VOLUME /var/lib/snappymail | ||
EXPOSE 8888 | ||
EXPOSE 9000 | ||
ENTRYPOINT [] | ||
CMD ["/entrypoint.sh"] |
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.