Add mail support by adding msmtp for sending
This commit is contained in:
parent
cc995b2479
commit
cacfd8c7fd
5 changed files with 97 additions and 51 deletions
25
Dockerfile
25
Dockerfile
|
@ -67,27 +67,33 @@ RUN chmod -x /wait-for.sh && \
|
||||||
curl \
|
curl \
|
||||||
python3 \
|
python3 \
|
||||||
py-pygments \
|
py-pygments \
|
||||||
|
imagemagick \
|
||||||
|
ghostscript \
|
||||||
|
msmtp \
|
||||||
composer \
|
composer \
|
||||||
php7 \
|
php7 \
|
||||||
php7-intl \
|
|
||||||
php7-fpm \
|
php7-fpm \
|
||||||
php7-cli \
|
php7-cli \
|
||||||
|
php7-intl \
|
||||||
php7-curl \
|
php7-curl \
|
||||||
php7-fileinfo \
|
|
||||||
php7-mbstring \
|
|
||||||
php7-gd \
|
|
||||||
php7-json \
|
php7-json \
|
||||||
php7-dom \
|
php7-dom \
|
||||||
php7-pcntl \
|
php7-pcntl \
|
||||||
php7-posix \
|
php7-posix \
|
||||||
php7-pgsql \
|
|
||||||
php7-exif \
|
|
||||||
php7-mcrypt \
|
php7-mcrypt \
|
||||||
php7-session \
|
php7-session \
|
||||||
|
php7-gd \
|
||||||
|
php7-exif \
|
||||||
|
php7-phar \
|
||||||
php7-pdo \
|
php7-pdo \
|
||||||
|
php7-pgsql \
|
||||||
php7-pdo_pgsql \
|
php7-pdo_pgsql \
|
||||||
php7-ctype \
|
php7-pdo_mysql \
|
||||||
php7-mysqli \
|
php7-mysqli \
|
||||||
|
php7-fileinfo \
|
||||||
|
php7-mbstring \
|
||||||
|
php7-ctype \
|
||||||
|
php7-ldap \
|
||||||
php7-pecl-memcached \
|
php7-pecl-memcached \
|
||||||
memcached \
|
memcached \
|
||||||
ca-certificates && \
|
ca-certificates && \
|
||||||
|
@ -100,6 +106,7 @@ RUN chmod -x /wait-for.sh && \
|
||||||
sed -i "s|;*upload_max_filesize =.*|upload_max_filesize = ${MAX_UPLOAD}|i" /etc/php7/php.ini && \
|
sed -i "s|;*upload_max_filesize =.*|upload_max_filesize = ${MAX_UPLOAD}|i" /etc/php7/php.ini && \
|
||||||
sed -i "s|;*max_file_uploads =.*|max_file_uploads = ${PHP_MAX_FILE_UPLOAD}|i" /etc/php7/php.ini && \
|
sed -i "s|;*max_file_uploads =.*|max_file_uploads = ${PHP_MAX_FILE_UPLOAD}|i" /etc/php7/php.ini && \
|
||||||
sed -i "s|;*post_max_size =.*|post_max_size = ${PHP_MAX_POST}|i" /etc/php7/php.ini && \
|
sed -i "s|;*post_max_size =.*|post_max_size = ${PHP_MAX_POST}|i" /etc/php7/php.ini && \
|
||||||
|
sed -i 's+.*sendmail_path =.*+sendmail_path = "/usr/bin/msmtp -C /var/www/msmtprc --logfile /var/www/msmtp.log -a filebinmail -t"+' /etc/php7/php.ini && \
|
||||||
# clean up and permissions
|
# clean up and permissions
|
||||||
rm -rf /var/cache/apk/* && \
|
rm -rf /var/cache/apk/* && \
|
||||||
ln -s /usr/bin/python3 /usr/bin/python && \
|
ln -s /usr/bin/python3 /usr/bin/python && \
|
||||||
|
@ -113,8 +120,10 @@ EXPOSE 80
|
||||||
# add templates for replace env variables in the application
|
# add templates for replace env variables in the application
|
||||||
ADD src/config/database.php.tpl /var/www/application/config/database.php.tpl
|
ADD src/config/database.php.tpl /var/www/application/config/database.php.tpl
|
||||||
ADD src/config/config-local.php.tpl /var/www/application/config/config-local.php.tpl
|
ADD src/config/config-local.php.tpl /var/www/application/config/config-local.php.tpl
|
||||||
ADD src/configure.php /configure.php
|
ADD src/config/email.php.tpl /var/www/application/config/email.php.tpl
|
||||||
ADD src/crontab /etc/periodic/15min/crontab
|
ADD src/crontab /etc/periodic/15min/crontab
|
||||||
|
ADD src/configure.php /configure.php
|
||||||
|
ADD src/configure-mail.sh /var/www/configure-mail.sh
|
||||||
|
|
||||||
# add overlay
|
# add overlay
|
||||||
ADD src/s6/ /etc/s6/
|
ADD src/s6/ /etc/s6/
|
||||||
|
|
|
@ -41,13 +41,3 @@ $config['tarball_cache_time'] = intval(%%%TARBALL_CACHE_TIME%%%);
|
||||||
|
|
||||||
// The maximum number of active invitation keys per account.
|
// The maximum number of active invitation keys per account.
|
||||||
$config['max_invitation_keys'] = intval(%%%MAX_INVITATION_KEYS%%%);
|
$config['max_invitation_keys'] = intval(%%%MAX_INVITATION_KEYS%%%);
|
||||||
|
|
||||||
// SMTP mail settings if enabled
|
|
||||||
if (getenv('SMTP_ENABLED') === 'true') {
|
|
||||||
$config['protocol'] = %%%SMTP_PROTOCOL%%%;
|
|
||||||
$config['smtp_host'] = %%%SMTP_HOST%%%;
|
|
||||||
$config['smtp_port'] = intval(%%%SMTP_PORT%%%);
|
|
||||||
$config['smtp_crypto'] = %%%SMTP_CRYPTO%%%;
|
|
||||||
$config['smtp_user'] = %%%SMTP_USER%%%;
|
|
||||||
$config['smtp_pass'] = %%%SMTP_PASS%%%;
|
|
||||||
}
|
|
13
src/config/email.php.tpl
Normal file
13
src/config/email.php.tpl
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// SMTP mail settings if enabled
|
||||||
|
if (getenv('SMTP_ENABLED') === 'true') {
|
||||||
|
$config = [
|
||||||
|
'protocol' => %%%SMTP_PROTOCOL%%%,
|
||||||
|
'smtp_host' => %%%SMTP_HOST%%%,
|
||||||
|
'smtp_port' => intval(%%%SMTP_PORT%%%),
|
||||||
|
'smtp_crypto' => %%%SMTP_CRYPTO%%%,
|
||||||
|
'smtp_user' => %%%SMTP_USER%%%,
|
||||||
|
'smtp_pass' => %%%SMTP_PASS%%%,
|
||||||
|
];
|
||||||
|
}
|
20
src/configure-mail.sh
Executable file
20
src/configure-mail.sh
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
function set_mail_config() {
|
||||||
|
|
||||||
|
cat <<EOF > /var/www/msmtprc
|
||||||
|
account filebinmail
|
||||||
|
tls on
|
||||||
|
tls_certcheck off
|
||||||
|
auth on
|
||||||
|
host ${SMTP_HOST}
|
||||||
|
port ${SMTP_PORT}
|
||||||
|
user ${SMTP_USER}
|
||||||
|
from ${EMAIL_FROM}
|
||||||
|
password ${SMTP_PASS}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod 600 /var/www/msmtprc
|
||||||
|
}
|
||||||
|
|
||||||
|
set_mail_config;
|
|
@ -2,33 +2,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (getenv('RECONFIGURE') === "true") {
|
if (getenv('RECONFIGURE') === "true") {
|
||||||
echo "Reconfiguring container..." . PHP_EOL;
|
echo "Reconfiguring database and local settings..." . PHP_EOL;
|
||||||
|
|
||||||
$confPath = '/var/www/application/config/config-local.php.tpl';
|
|
||||||
$confTargetPath = '/var/www/application/config/config-local.php';
|
|
||||||
$confVars = [
|
|
||||||
'BASE_URL',
|
|
||||||
'ENCRYPTION_KEY',
|
|
||||||
'CACHE_BACKEND',
|
|
||||||
'INDEX_PAGE',
|
|
||||||
'EMAIL_FROM',
|
|
||||||
'UPLOAD_MAX_SIZE',
|
|
||||||
'UPLOAD_MAX_TEXT_SIZE',
|
|
||||||
'UPLOAD_MAX_AGE',
|
|
||||||
'ACTIONS_MAX_AGE',
|
|
||||||
'SMALL_UPLOAD_SIZE',
|
|
||||||
'TARBALL_MAX_SIZE',
|
|
||||||
'TARBALL_CACHE_TIME',
|
|
||||||
'MAX_INVITATION_KEYS',
|
|
||||||
'SMTP_PROTOCOL',
|
|
||||||
'SMTP_HOST',
|
|
||||||
'SMTP_PORT',
|
|
||||||
'SMTP_CRYPTO',
|
|
||||||
'SMTP_USER',
|
|
||||||
'SMTP_PASS'
|
|
||||||
];
|
|
||||||
contentsReplace($confVars, $confPath, $confTargetPath);
|
|
||||||
|
|
||||||
|
// configure database
|
||||||
$dbPath = '/var/www/application/config/database.php.tpl';
|
$dbPath = '/var/www/application/config/database.php.tpl';
|
||||||
$dbTargetPath = '/var/www/application/config/database.php';
|
$dbTargetPath = '/var/www/application/config/database.php';
|
||||||
$dbVars = [
|
$dbVars = [
|
||||||
|
@ -51,21 +27,61 @@ if (getenv('RECONFIGURE') === "true") {
|
||||||
'DB_SAVE_QUERIES'
|
'DB_SAVE_QUERIES'
|
||||||
];
|
];
|
||||||
contentsReplace($dbVars, $dbPath, $dbTargetPath);
|
contentsReplace($dbVars, $dbPath, $dbTargetPath);
|
||||||
|
|
||||||
|
// configure local settings
|
||||||
|
$confPath = '/var/www/application/config/config-local.php.tpl';
|
||||||
|
$confTargetPath = '/var/www/application/config/config-local.php';
|
||||||
|
$confVars = [
|
||||||
|
'BASE_URL',
|
||||||
|
'ENCRYPTION_KEY',
|
||||||
|
'CACHE_BACKEND',
|
||||||
|
'INDEX_PAGE',
|
||||||
|
'EMAIL_FROM',
|
||||||
|
'UPLOAD_MAX_SIZE',
|
||||||
|
'UPLOAD_MAX_TEXT_SIZE',
|
||||||
|
'UPLOAD_MAX_AGE',
|
||||||
|
'ACTIONS_MAX_AGE',
|
||||||
|
'SMALL_UPLOAD_SIZE',
|
||||||
|
'TARBALL_MAX_SIZE',
|
||||||
|
'TARBALL_CACHE_TIME',
|
||||||
|
'MAX_INVITATION_KEYS'
|
||||||
|
];
|
||||||
|
contentsReplace($confVars, $confPath, $confTargetPath);
|
||||||
|
|
||||||
|
// configure mail if enabled
|
||||||
|
$mailPath = '/var/www/application/config/email.php.tpl';
|
||||||
|
$mailTargetPath = '/var/www/application/config/email.php';
|
||||||
|
$mailVars = [
|
||||||
|
'SMTP_PROTOCOL',
|
||||||
|
'SMTP_HOST',
|
||||||
|
'SMTP_PORT',
|
||||||
|
'SMTP_CRYPTO',
|
||||||
|
'SMTP_USER',
|
||||||
|
'SMTP_PASS'
|
||||||
|
];
|
||||||
|
contentsReplace($mailVars, $mailPath, $mailTargetPath);
|
||||||
|
|
||||||
|
if (getenv('SMTP_ENABLED') === 'true') {
|
||||||
|
echo "Applying mail configuration..." . PHP_EOL;
|
||||||
|
exec('sh /var/www/configure-mail.sh');
|
||||||
} else {
|
} else {
|
||||||
echo "Will not reconfigure container..." . PHP_EOL;
|
echo "Will not apply mail configuration..." . PHP_EOL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Will not reconfigure database and local settings..." . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getenv('MIGRATE') === "true") {
|
if (getenv('MIGRATE') === "true") {
|
||||||
echo "Migrating..." . PHP_EOL;
|
echo "Migrating database and dependencies..." . PHP_EOL;
|
||||||
|
|
||||||
exec("php /var/www/index.php tools update_database");
|
exec("php /var/www/index.php tools update_database");
|
||||||
exec("composer --working-dir=/var/www install --no-dev --no-plugins --no-scripts");
|
exec("composer --working-dir=/var/www install --no-dev --no-plugins --no-scripts");
|
||||||
exec("chown -R nobody:nginx /var/www");
|
exec("chown -R nobody:nginx /var/www");
|
||||||
} else {
|
} else {
|
||||||
echo "Will not migrate..." . PHP_EOL;
|
echo "Will not migrate database and dependencies..." . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
function contentsReplace($envNames = array(), $filePath, $targetFilePath)
|
function contentsReplace($envNames, $filePath, $targetFilePath)
|
||||||
{
|
{
|
||||||
$fileContent = file_get_contents($filePath);
|
$fileContent = file_get_contents($filePath);
|
||||||
|
|
||||||
|
@ -73,11 +89,9 @@ function contentsReplace($envNames = array(), $filePath, $targetFilePath)
|
||||||
$fileContent = preg_replace("/%%%" . strtoupper($env) . "%%%/", env($env), $fileContent);
|
$fileContent = preg_replace("/%%%" . strtoupper($env) . "%%%/", env($env), $fileContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
file_put_contents($targetFilePath, $fileContent);
|
file_put_contents($targetFilePath, $fileContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function env($name, $default = null)
|
function env($name, $default = null)
|
||||||
{
|
{
|
||||||
$v = getenv($name) ?: $default;
|
$v = getenv($name) ?: $default;
|
||||||
|
|
Loading…
Reference in a new issue