Rework template used to build the Dockerfiles (#16)

This commit is contained in:
Alexis Saettler 2020-05-16 15:29:07 +02:00 committed by GitHub
parent 3dccf804db
commit 257d3334bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 186 additions and 203 deletions

View File

@ -0,0 +1,5 @@
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN set -ex; \
\
sed -ri -e "s!/var/www/html!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/sites-available/*.conf; \
sed -ri -e "s!/var/www/!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

View File

@ -0,0 +1,36 @@
# Set crontab for schedules
RUN set -ex; \
\
mkdir -p /var/spool/cron/crontabs; \
rm -f /var/spool/cron/crontabs/root; \
echo '*/5 * * * * php /var/www/html/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2' > /var/spool/cron/crontabs/www-data
# Opcache
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
PHP_OPCACHE_MAX_ACCELERATED_FILES="20000" \
PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"
RUN set -ex; \
\
{ \
echo '[opcache]'; \
echo 'opcache.enable=1'; \
echo 'opcache.revalidate_freq=0'; \
echo 'opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS}'; \
echo 'opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}'; \
echo 'opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}'; \
echo 'opcache.max_wasted_percentage=${PHP_OPCACHE_MAX_WASTED_PERCENTAGE}'; \
echo 'opcache.interned_strings_buffer=16'; \
echo 'opcache.fast_shutdown=1'; \
} > $PHP_INI_DIR/conf.d/opcache-recommended.ini; \
\
echo 'apc.enable_cli=1' >> $PHP_INI_DIR/conf.d/docker-php-ext-apcu.ini; \
\
echo 'memory_limit=512M' > $PHP_INI_DIR/conf.d/memory-limit.ini
%%APACHE_DOCUMENT%%
WORKDIR /var/www/html
# Define Monica version
ENV MONICA_VERSION %%VERSION%%

View File

@ -0,0 +1,7 @@
COPY entrypoint.sh \
queue.sh \
cron.sh \
/usr/local/bin/
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["%%CMD%%"]

View File

@ -0,0 +1,4 @@
FROM php:%%PHP_VERSION%%-%%VARIANT%%
# opencontainers annotations https://github.com/opencontainers/image-spec/blob/master/annotations.md
%%LABEL%%

View File

@ -0,0 +1,20 @@
for ext in tar.bz2 tar.bz2.asc; do \
curl -fsSL -o monica-${MONICA_VERSION}.$ext "https://github.com/monicahq/monica/releases/download/${MONICA_VERSION}/monica-${MONICA_VERSION}.$ext"; \
done; \
\
GPGKEY='BDAB0D0D36A00466A2964E85DE15667131EA6018'; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver ipv4.pool.sks-keyservers.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver keys.gnupg.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver pgp.mit.edu --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver keyserver.pgp.com --recv-keys "$GPGKEY"; \
gpg --batch --verify monica-${MONICA_VERSION}.tar.bz2.asc monica-${MONICA_VERSION}.tar.bz2; \
\
tar -xf monica-${MONICA_VERSION}.tar.bz2 -C /var/www/html --strip-components=1; \
\
gpgconf --kill all; \
rm -r "$GNUPGHOME" monica-${MONICA_VERSION}.tar.bz2 monica-${MONICA_VERSION}.tar.bz2.asc; \
\
cp /var/www/html/.env.example /var/www/html/.env; \
chown -R www-data:www-data /var/www/html;

View File

@ -0,0 +1,8 @@
LABEL org.opencontainers.image.authors="Alexis Saettler <alexis@saettler.org>" \
org.opencontainers.image.title="MonicaHQ, the Personal Relationship Manager" \
org.opencontainers.image.description="This is MonicaHQ, your personal memory! MonicaHQ is like a CRM but for the friends, family, and acquaintances around you." \
org.opencontainers.image.url="https://monicahq.com" \
org.opencontainers.image.revision="%%COMMIT%%" \
org.opencontainers.image.source="https://github.com/monicahq/docker" \
org.opencontainers.image.vendor="Monica" \
org.opencontainers.image.version="%%VERSION%%"

View File

@ -1,7 +1,4 @@
FROM php:%%PHP_VERSION%%-%%VARIANT%%
# opencontainers annotations https://github.com/opencontainers/image-spec/blob/master/annotations.md
%%LABEL%%
%%HEAD%%
# entrypoint.sh dependencies
RUN set -ex; \
@ -71,40 +68,7 @@ RUN set -ex; \
apk add --no-network --virtual .monica-phpext-rundeps $runDeps; \
apk del --no-network .build-deps
# Set crontab for schedules
RUN set -ex; \
\
rm /var/spool/cron/crontabs/root; \
echo '*/5 * * * * php /var/www/html/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2' > /var/spool/cron/crontabs/www-data
# Opcache
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
PHP_OPCACHE_MAX_ACCELERATED_FILES="20000" \
PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"
RUN set -ex; \
\
{ \
echo '[opcache]'; \
echo 'opcache.enable=1'; \
echo 'opcache.revalidate_freq=0'; \
echo 'opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS}'; \
echo 'opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}'; \
echo 'opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}'; \
echo 'opcache.max_wasted_percentage=${PHP_OPCACHE_MAX_WASTED_PERCENTAGE}'; \
echo 'opcache.interned_strings_buffer=16'; \
echo 'opcache.fast_shutdown=1'; \
} > $PHP_INI_DIR/conf.d/opcache-recommended.ini; \
\
echo 'apc.enable_cli=1' >> $PHP_INI_DIR/conf.d/docker-php-ext-apcu.ini; \
\
echo 'memory_limit=512M' > $PHP_INI_DIR/conf.d/memory-limit.ini
WORKDIR /var/www/html
# Define Monica version
ENV MONICA_VERSION %%VERSION%%
%%EXTRA_INSTALL%%
RUN set -ex; \
apk add --no-cache --virtual .fetch-deps \
@ -112,33 +76,8 @@ RUN set -ex; \
gnupg \
; \
\
for ext in tar.bz2 tar.bz2.asc; do \
curl -fsSL -o monica-${MONICA_VERSION}.$ext "https://github.com/monicahq/monica/releases/download/${MONICA_VERSION}/monica-${MONICA_VERSION}.$ext"; \
done; \
\
GPGKEY='BDAB0D0D36A00466A2964E85DE15667131EA6018'; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver ipv4.pool.sks-keyservers.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver keys.gnupg.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver pgp.mit.edu --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver keyserver.pgp.com --recv-keys "$GPGKEY"; \
gpg --batch --verify monica-${MONICA_VERSION}.tar.bz2.asc monica-${MONICA_VERSION}.tar.bz2; \
\
tar -xf monica-${MONICA_VERSION}.tar.bz2 -C /var/www/html --strip-components=1; \
\
gpgconf --kill all; \
rm -r "$GNUPGHOME" monica-${MONICA_VERSION}.tar.bz2 monica-${MONICA_VERSION}.tar.bz2.asc; \
\
cp /var/www/html/.env.example /var/www/html/.env; \
chown -R www-data:www-data /var/www/html; \
%%INSTALL%% \
\
apk del .fetch-deps
COPY entrypoint.sh \
queue.sh \
cron.sh \
/usr/local/bin/
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["%%CMD%%"]
%%FOOT%%

View File

@ -1,7 +1,4 @@
FROM php:%%PHP_VERSION%%-%%VARIANT%%
# opencontainers annotations https://github.com/opencontainers/image-spec/blob/master/annotations.md
%%LABEL%%
%%HEAD%%
# entrypoint.sh dependencies
RUN set -ex; \
@ -82,42 +79,8 @@ RUN set -ex; \
a2enmod rewrite; \
fi
# Set crontab for schedules
RUN set -ex; \
\
mkdir -p /var/spool/cron/crontabs; \
echo '*/5 * * * * php /var/www/html/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2' > /var/spool/cron/crontabs/www-data
# Opcache
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
PHP_OPCACHE_MAX_ACCELERATED_FILES="20000" \
PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"
RUN set -ex; \
\
{ \
echo '[opcache]'; \
echo 'opcache.enable=1'; \
echo 'opcache.revalidate_freq=0'; \
echo 'opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS}'; \
echo 'opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}'; \
echo 'opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}'; \
echo 'opcache.max_wasted_percentage=${PHP_OPCACHE_MAX_WASTED_PERCENTAGE}'; \
echo 'opcache.interned_strings_buffer=16'; \
echo 'opcache.fast_shutdown=1'; \
} > $PHP_INI_DIR/conf.d/opcache-recommended.ini; \
\
echo 'apc.enable_cli=1' >> $PHP_INI_DIR/conf.d/docker-php-ext-apcu.ini; \
\
echo 'memory_limit=512M' > $PHP_INI_DIR/conf.d/memory-limit.ini
WORKDIR /var/www/html
# Define Monica version
ENV MONICA_VERSION %%VERSION%%
%%APACHE_DOCUMENT%%
%%EXTRA_INSTALL%%
RUN set -ex; \
fetchDeps=" \
@ -126,34 +89,9 @@ RUN set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends $fetchDeps; \
\
for ext in tar.bz2 tar.bz2.asc; do \
curl -fsSL -o monica-${MONICA_VERSION}.$ext "https://github.com/monicahq/monica/releases/download/${MONICA_VERSION}/monica-${MONICA_VERSION}.$ext"; \
done; \
\
GPGKEY='BDAB0D0D36A00466A2964E85DE15667131EA6018'; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver ipv4.pool.sks-keyservers.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver keys.gnupg.net --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver pgp.mit.edu --recv-keys "$GPGKEY" \
|| gpg --batch --keyserver keyserver.pgp.com --recv-keys "$GPGKEY"; \
gpg --batch --verify monica-${MONICA_VERSION}.tar.bz2.asc monica-${MONICA_VERSION}.tar.bz2; \
\
tar -xf monica-${MONICA_VERSION}.tar.bz2 -C /var/www/html --strip-components=1; \
\
gpgconf --kill all; \
rm -r "$GNUPGHOME" monica-${MONICA_VERSION}.tar.bz2 monica-${MONICA_VERSION}.tar.bz2.asc; \
\
cp /var/www/html/.env.example /var/www/html/.env; \
chown -R www-data:www-data /var/www/html; \
%%INSTALL%% \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \
rm -rf /var/lib/apt/lists/*
COPY entrypoint.sh \
queue.sh \
cron.sh \
/usr/local/bin/
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["%%CMD%%"]
%%FOOT%%

View File

@ -89,10 +89,12 @@ RUN set -ex; \
a2enmod rewrite; \
fi
# Set crontab for schedules
RUN set -ex; \
\
mkdir -p /var/spool/cron/crontabs; \
rm -f /var/spool/cron/crontabs/root; \
echo '*/5 * * * * php /var/www/html/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2' > /var/spool/cron/crontabs/www-data
# Opcache
@ -118,16 +120,17 @@ RUN set -ex; \
\
echo 'memory_limit=512M' > $PHP_INI_DIR/conf.d/memory-limit.ini
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN set -ex; \
\
sed -ri -e "s!/var/www/html!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/sites-available/*.conf; \
sed -ri -e "s!/var/www/!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
WORKDIR /var/www/html
# Define Monica version
ENV MONICA_VERSION v2.17.0
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN set -eu; sed -ri -e "s!/var/www/html!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/sites-available/*.conf; \
sed -ri -e "s!/var/www/!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN set -ex; \
fetchDeps=" \
gnupg \

View File

@ -81,7 +81,8 @@ RUN set -ex; \
# Set crontab for schedules
RUN set -ex; \
\
rm /var/spool/cron/crontabs/root; \
mkdir -p /var/spool/cron/crontabs; \
rm -f /var/spool/cron/crontabs/root; \
echo '*/5 * * * * php /var/www/html/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2' > /var/spool/cron/crontabs/www-data
# Opcache
@ -108,6 +109,7 @@ RUN set -ex; \
echo 'memory_limit=512M' > $PHP_INI_DIR/conf.d/memory-limit.ini
WORKDIR /var/www/html
# Define Monica version

View File

@ -89,10 +89,12 @@ RUN set -ex; \
a2enmod rewrite; \
fi
# Set crontab for schedules
RUN set -ex; \
\
mkdir -p /var/spool/cron/crontabs; \
rm -f /var/spool/cron/crontabs/root; \
echo '*/5 * * * * php /var/www/html/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2' > /var/spool/cron/crontabs/www-data
# Opcache
@ -119,13 +121,12 @@ RUN set -ex; \
echo 'memory_limit=512M' > $PHP_INI_DIR/conf.d/memory-limit.ini
WORKDIR /var/www/html
# Define Monica version
ENV MONICA_VERSION v2.17.0
RUN set -ex; \
fetchDeps=" \
gnupg \

150
update.sh
View File

@ -4,98 +4,118 @@ set -e
IFS='
'
_template() {
sed -e 's/\\/\\\\/g' $1 | sed -E ':a;N;$!ba;s/\r{0,1}\n/%0A/g'
}
declare -A php_version=(
[default]='7.3'
[default]='7.3'
)
declare -A cmd=(
[apache]='apache2-foreground'
[fpm]='php-fpm'
[fpm-alpine]='php-fpm'
[apache]='apache2-foreground'
[fpm]='php-fpm'
[fpm-alpine]='php-fpm'
)
declare -A base=(
[apache]='debian'
[fpm]='debian'
[fpm-alpine]='alpine'
[apache]='debian'
[fpm]='debian'
[fpm-alpine]='alpine'
)
declare -A document=(
[apache]="ENV APACHE_DOCUMENT_ROOT /var/www/html/public\\n\
RUN set -eu; sed -ri -e \"s!/var/www/html!\\\${APACHE_DOCUMENT_ROOT}!g\" /etc/apache2/sites-available/*.conf; \\\\\\n\
sed -ri -e \"s!/var/www/!\\\${APACHE_DOCUMENT_ROOT}!g\" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf"
[fpm]=''
[fpm-alpine]=''
[apache]=$(_template .templates/Dockerfile-apache.template)
[fpm]=''
[fpm-alpine]=''
)
label="LABEL org.opencontainers.image.authors=\"Alexis Saettler <alexis@saettler.org>\" \\\\\\n\
org.opencontainers.image.title=\"MonicaHQ, the Personal Relationship Manager\" \\\\\\n\
org.opencontainers.image.description=\"This is MonicaHQ, your personal memory! MonicaHQ is like a CRM but for the friends, family, and acquaintances around you.\" \\\\\\n\
org.opencontainers.image.url=\"https://monicahq.com\" \\\\\\n\
org.opencontainers.image.revision=\"%%COMMIT%%\" \\\\\\n\
org.opencontainers.image.source=\"https://github.com/monicahq/docker\" \\\\\\n\
org.opencontainers.image.vendor=\"Monica\" \\\\\\n\
org.opencontainers.image.version=\"%%VERSION%%\""
label=$(_template .templates/Dockerfile-label.template)
echo Initialisation
apcu_version="$(
git ls-remote --tags https://github.com/krakjoe/apcu.git \
| cut -d/ -f3 \
| grep -vE -- '-rc|-b' \
| sed -E 's/^v//' \
| sort -V \
| tail -1
git ls-remote --tags https://github.com/krakjoe/apcu.git \
| cut -d/ -f3 \
| grep -vE -- '-rc|-b' \
| sed -E 's/^v//' \
| sort -V \
| tail -1
)"
echo " APCu version: $apcu_version"
memcached_version="$(
git ls-remote --tags https://github.com/php-memcached-dev/php-memcached.git \
| cut -d/ -f3 \
| grep -vE -- '-rc|-b' \
| sed -E 's/^[rv]//' \
| sort -V \
| tail -1
git ls-remote --tags https://github.com/php-memcached-dev/php-memcached.git \
| cut -d/ -f3 \
| grep -vE -- '-rc|-b' \
| sed -E 's/^[rv]//' \
| sort -V \
| tail -1
)"
echo " Memcached version: $memcached_version"
redis_version="$(
git ls-remote --tags https://github.com/phpredis/phpredis.git \
| cut -d/ -f3 \
| grep -viE '[a-z]' \
| tr -d '^{}' \
| sort -V \
| tail -1
git ls-remote --tags https://github.com/phpredis/phpredis.git \
| cut -d/ -f3 \
| grep -viE '[a-z]' \
| tr -d '^{}' \
| sort -V \
| tail -1
)"
echo " Redis version: $redis_version"
declare -A pecl_versions=(
[APCu]="$apcu_version"
[memcached]="$memcached_version"
[redis]="$redis_version"
[APCu]="$apcu_version"
[memcached]="$memcached_version"
[redis]="$redis_version"
)
version="$(curl -fsSL 'https://api.github.com/repos/monicahq/monica/releases/latest' | jq -r '.tag_name')"
commit="$(curl -fsSL 'https://api.github.com/repos/monicahq/monica/tags' | jq -r 'map(select(.name | contains ("'$version'"))) | .[].commit.sha')"
_githubapi() {
if [ -n "${GITHUB_TOKEN:-}" ]; then
curl -fsSL -H "Authorization: token $GITHUB_TOKEN" $1;
else
curl -fsSL $1;
fi
}
set -x
version="$(_githubapi 'https://api.github.com/repos/monicahq/monica/releases/latest' | jq -r '.tag_name')"
echo " Monica version: $version"
commit="$(_githubapi 'https://api.github.com/repos/monicahq/monica/tags' | jq -r 'map(select(.name | contains ("'$version'"))) | .[].commit.sha')"
echo " Commit: $commit"
head=$(_template .templates/Dockerfile-head.template)
foot=$(_template .templates/Dockerfile-foot.template)
extra=$(_template .templates/Dockerfile-extra.template)
install=$(_template .templates/Dockerfile-install.template)
for variant in apache fpm fpm-alpine; do
rm -rf $variant
mkdir -p $variant
phpVersion=${php_version[$version]-${php_version[default]}}
echo Generating $variant variant...
rm -rf $variant
mkdir -p $variant
phpVersion=${php_version[$version]-${php_version[default]}}
template="Dockerfile-${base[$variant]}.template"
sed -e '
s/%%VARIANT%%/'"$variant"'/;
s/%%PHP_VERSION%%/'"$phpVersion"'/;
s#%%LABEL%%#'"$label"'#;
s/%%VERSION%%/'"$version"'/;
s/%%COMMIT%%/'"$commit"'/;
s/%%CMD%%/'"${cmd[$variant]}"'/;
s#%%APACHE_DOCUMENT%%#'"${document[$variant]}"'#;
s/%%APCU_VERSION%%/'"${pecl_versions[APCu]}"'/;
s/%%MEMCACHED_VERSION%%/'"${pecl_versions[memcached]}"'/;
s/%%REDIS_VERSION%%/'"${pecl_versions[redis]}"'/;
' \
$template > "$variant/Dockerfile"
for file in entrypoint cron queue; do
cp docker-$file.sh $variant/$file.sh
done
template="Dockerfile-${base[$variant]}.template"
sed -e '
s@%%HEAD%%@'"$head"'@;
s@%%FOOT%%@'"$foot"'@;
s@%%EXTRA_INSTALL%%@'"$extra"'@;
s@%%INSTALL%%@'"$install"'@;
s/%%VARIANT%%/'"$variant"'/;
s/%%PHP_VERSION%%/'"$phpVersion"'/;
s#%%LABEL%%#'"$label"'#;
s/%%VERSION%%/'"$version"'/;
s/%%COMMIT%%/'"$commit"'/;
s/%%CMD%%/'"${cmd[$variant]}"'/;
s#%%APACHE_DOCUMENT%%#'"${document[$variant]}"'#;
s/%%APCU_VERSION%%/'"${pecl_versions[APCu]}"'/;
s/%%MEMCACHED_VERSION%%/'"${pecl_versions[memcached]}"'/;
s/%%REDIS_VERSION%%/'"${pecl_versions[redis]}"'/;
' \
-e "s/%0A/\n/g;" \
$template > "$variant/Dockerfile"
for file in entrypoint cron queue; do
cp docker-$file.sh $variant/$file.sh
done
done