Skip to content

Commit 7830645

Browse files
committed
Install ssmtp and msmtp and add confs.
1 parent 9616b56 commit 7830645

File tree

6 files changed

+71
-3
lines changed

6 files changed

+71
-3
lines changed

php/Dockerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ADD --chmod=0644 https://dl.cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem /o
3333

3434
RUN <<EOF
3535
apk update && apk upgrade
36-
apk --no-cache add bash curl git make nano neofetch sudo tar tini
36+
apk --no-cache add bash curl git make msmtp nano neofetch ssmtp sudo tar tini
3737
neofetch
3838
addgroup -S ${DEFAULT_USER} -g ${DEFAULT_USER_UID}
3939
adduser -D -S -G ${DEFAULT_USER} -u ${DEFAULT_USER_UID} -s /bin/bash ${DEFAULT_USER}
@@ -47,7 +47,12 @@ EOF
4747
COPY --chown=${DEFAULT_USER}:${DEFAULT_USER} files/home/druid/ /home/druid
4848
COPY files/usr/local/bin/ /usr/local/bin/
4949
COPY --link --from=amazeeio/envplate:v1.0.3 /usr/local/bin/ep /usr/local/bin/ep
50-
COPY files/entrypoints/00-umask.sh files/entrypoints/15-xdebug.sh files/entrypoints/19-php_ini.sh /entrypoints/
50+
COPY files/entrypoints/00-umask.sh \
51+
files/entrypoints/15-xdebug.sh \
52+
files/entrypoints/19-php_ini.sh \
53+
files/entrypoints/40-ssmtp.sh /entrypoints/
54+
COPY files/etc/msmtprc /etc/msmtprc
55+
COPY files/etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf
5156

5257
SHELL ["/bin/bash", "-c"]
5358
USER ${DEFAULT_USER}
@@ -175,6 +180,8 @@ COPY files/etc/php/php-fpm.d/www.conf.ep /etc/php83/php-fpm.d/www.conf.ep
175180

176181
FROM build-php-fpm-${PHP_SHORT_VERSION} as final-php-fpm
177182

183+
ENV PHP_SENDMAIL_PATH="/usr/bin/msmtp -t --read-envelope-from"
184+
178185
RUN sudo -s <<EOF
179186
addgroup -g 82 -S www-data || echo "www-data group already exists"
180187
adduser -u 82 -D -S -G www-data www-data
@@ -189,6 +196,8 @@ CMD ["sudo", "-E", "LD_PRELOAD=/usr/lib/preloadable_libiconv.so", "php-fpm", "-F
189196

190197
FROM final-php-fpm as drupal-php-81
191198

199+
ENV PHP_SENDMAIL_PATH="/usr/bin/dos2unix -u | /usr/bin/msmtp -t --read-envelope-from"
200+
192201
RUN sudo -s <<EOF
193202
apk --no-cache add mysql-client openssh rsync mariadb-connector-c \
194203
php81-{bcmath,ctype,dom,exif,gd,intl,pdo,pdo_mysql,simplexml,soap,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter}
@@ -221,14 +230,14 @@ ENV DRUPAL_DB_NAME=drupal \
221230
DRUPAL_DB_PASS=drupal \
222231
DRUPAL_DB_HOST=db \
223232
DRUPAL_DB_PORT=3306 \
224-
PHP_SENDMAIL_PATH="/usr/sbin/sendmail -S host.docker.internal:1025 -t" \
225233
SSH_AUTH_SOCK=/tmp/ssh-agent
226234

227235
RUN sudo -s <<EOF
228236
install -o ${DEFAULT_USER} -g ${DEFAULT_USER} -d /home/${DEFAULT_USER}/.drush /home/${DEFAULT_USER}/drush-backups/drupal
229237
EOF
230238

231239
COPY files/entrypoints/10-ssh-agent.sh /entrypoints/
240+
COPY drupal/set-permissions.sh /entrypoints/99-set-permissions.sh
232241

233242
#
234243
# Drupal Web

php/drupal/set-permissions.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
function set_permissions {
4+
FILES_PATH=/app/${WEBROOT:-public}/sites/default/files/
5+
6+
echo "- Delete css and js folder from public files"
7+
sudo rm -rf "${FILES_PATH}css" "${FILES_PATH}js"
8+
9+
echo "- Set ownership of ${FILES_PATH} to www-data"
10+
sudo chown -R www-data:www-data "${FILES_PATH}"
11+
}
12+
13+
set_permissions &

php/files/entrypoints/40-ssmtp.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
if [ ${SSMTP_MAILHUB+x} ]; then
4+
5+
echo "- Prepare SSMTP conf..."
6+
7+
sudo --preserve-env ep -v /etc/ssmtp/ssmtp.conf
8+
9+
fi
10+
11+
echo "- Prepare MSMTP conf in /etc/msmtprc..."
12+
13+
sudo --preserve-env ep -v /etc/msmtprc

php/files/etc/msmtprc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defaults
2+
tls off
3+
4+
account default
5+
auth ${MSMTP_AUTH:-off}
6+
7+
host ${MSMTP_HOST:-host.docker.internal}
8+
port ${MSMTP_PORT:-1025}
9+
10+
user ${MSMTP_USER:-}
11+
password ${MSMTP_PASS:-}
12+
13+
add_missing_date_header on

php/files/etc/nginx/conf.d/default.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ server {
22
listen [::]:8080 default_server;
33
listen 8080 default_server;
44
server_name _;
5+
client_max_body_size 512M;
56

67
root /app/${WEBROOT:-public};
78
index index.php;
@@ -29,6 +30,12 @@ server {
2930
deny all;
3031
}
3132

33+
location ~ /(?:a|A)utodiscover/(?:a|A)utodiscover.xml {
34+
deny all;
35+
access_log off;
36+
return 404;
37+
}
38+
3239
# Do not allow access to .txt and .md unless inside sites/*/files/
3340
location ~* ^(?!.+sites\/.+\/files\/).+\.(txt|md)$ {
3441
deny all;
@@ -84,6 +91,11 @@ server {
8491
internal;
8592
}
8693

94+
# Passes image style and asset generation to PHP.
95+
location ~ ^/sites/.*/files/(css|js|styles)/ {
96+
try_files $uri @rewrite;
97+
}
98+
8799
# Disallow access to vendor directory.
88100
location ^~ /core/vendor/ {
89101
deny all;

php/files/etc/ssmtp/ssmtp.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FromLineOverride=YES
2+
root=postmaster
3+
mailhub=${SSMTP_MAILHUB}
4+
hostname=${HOSTNAME}
5+
AuthUser=${SSMTP_AUTHUSER:-}
6+
AuthPass=${SSMTP_AUTHPASS:-}
7+
FromLineOverride=YES
8+
UseSTARTTLS=YES

0 commit comments

Comments
 (0)