Skip to content

Commit f7abdb6

Browse files
committed
Install DMA & handle configuration variables (fixes thecodingmachine#204)
1 parent 7353627 commit f7abdb6

10 files changed

+114
-0
lines changed

Dockerfile.apache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ARG INSTALL_CRON=1
22
ARG INSTALL_COMPOSER=1
3+
ARG INSTALL_DMA=1
34
ARG PHP_VERSION
45
ARG GLOBAL_VERSION
56
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-apache

Dockerfile.cli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ARG INSTALL_CRON=1
22
ARG INSTALL_COMPOSER=1
3+
ARG INSTALL_DMA=1
34
ARG PHP_VERSION
45
ARG GLOBAL_VERSION
56
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-cli

Dockerfile.fpm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ARG INSTALL_CRON=1
22
ARG INSTALL_COMPOSER=1
3+
ARG INSTALL_DMA=1
34
ARG PHP_VERSION
45
ARG GLOBAL_VERSION
56
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-fpm

Dockerfile.slim.apache

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
293293
RUN chmod +x /tini
294294

295295
COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
296+
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
296297
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php
297298

298299
COPY utils/enable_apache_mods.php /usr/local/bin/enable_apache_mods.php
@@ -386,3 +387,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
386387
sudo apt-get update && \
387388
sudo apt-get install -y --no-install-recommends yarn; \
388389
fi;
390+
391+
# |--------------------------------------------------------------------------
392+
# | DragonFly Mail Agent
393+
# |--------------------------------------------------------------------------
394+
# |
395+
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
396+
# | to send email from PHP, either using direct delivery or through an SMTP
397+
# | smarthost.
398+
# |
399+
400+
ONBUILD ARG INSTALL_DMA
401+
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
402+
sudo apt-get update && \
403+
sudo -E apt-get install -y --no-install-recommends dma; \
404+
fi;

Dockerfile.slim.cli

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
219219
RUN chmod +x /tini
220220

221221
COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
222+
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
222223
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php
223224

224225
COPY utils/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
@@ -291,3 +292,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
291292
sudo apt-get update && \
292293
sudo apt-get install -y --no-install-recommends yarn; \
293294
fi;
295+
296+
# |--------------------------------------------------------------------------
297+
# | DragonFly Mail Agent
298+
# |--------------------------------------------------------------------------
299+
# |
300+
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
301+
# | to send email from PHP, either using direct delivery or through an SMTP
302+
# | smarthost.
303+
# |
304+
305+
ONBUILD ARG INSTALL_DMA
306+
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
307+
sudo apt-get update && \
308+
sudo -E apt-get install -y --no-install-recommends dma; \
309+
fi;

Dockerfile.slim.fpm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
232232
RUN chmod +x /tini
233233

234234
COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
235+
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
235236
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php
236237

237238
COPY utils/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
@@ -314,3 +315,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
314315
sudo apt-get update && \
315316
sudo apt-get install -y --no-install-recommends yarn; \
316317
fi;
318+
319+
# |--------------------------------------------------------------------------
320+
# | DragonFly Mail Agent
321+
# |--------------------------------------------------------------------------
322+
# |
323+
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
324+
# | to send email from PHP, either using direct delivery or through an SMTP
325+
# | smarthost.
326+
# |
327+
328+
ONBUILD ARG INSTALL_DMA
329+
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
330+
sudo apt-get update && \
331+
sudo -E apt-get install -y --no-install-recommends dma; \
332+
fi;

utils/Dockerfile.blueprint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
ARG INSTALL_CRON=1
44
ARG INSTALL_COMPOSER=1
5+
ARG INSTALL_DMA=1
56
ARG PHP_VERSION
67
ARG GLOBAL_VERSION
78
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-{{ $variant }}

utils/Dockerfile.slim.blueprint

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
311311
RUN chmod +x /tini
312312

313313
COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
314+
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
314315
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php
315316
{{if eq $variant "apache" }}
316317
COPY utils/enable_apache_mods.php /usr/local/bin/enable_apache_mods.php
@@ -418,3 +419,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
418419
sudo apt-get update && \
419420
sudo apt-get install -y --no-install-recommends yarn; \
420421
fi;
422+
423+
# |--------------------------------------------------------------------------
424+
# | DragonFly Mail Agent
425+
# |--------------------------------------------------------------------------
426+
# |
427+
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
428+
# | to send email from PHP, either using direct delivery or through an SMTP
429+
# | smarthost.
430+
# |
431+
432+
ONBUILD ARG INSTALL_DMA
433+
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
434+
sudo apt-get update && \
435+
sudo -E apt-get install -y --no-install-recommends dma; \
436+
fi;

utils/docker-entrypoint-as-root.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ fi
116116
unset DOCKER_FOR_MAC_REMOTE_HOST
117117
unset REMOTE_HOST_FOUND
118118

119+
if [ -e /usr/sbin/dma ]; then
120+
# set sendmail path for PHP
121+
if [ "$DMA_FROM" = "" ]; then
122+
123+
fi
124+
export PHP_INI_SENDMAIL_PATH="/usr/sbin/sendmail -t -i -f'$DMA_FROM'"
125+
126+
# generate DMA config based on DMA_CONF_... environment variables
127+
php /usr/local/bin/generate_dma.php > /etc/dma/dma.conf
128+
129+
# generate DMA authentication file based on DMA_AUTH_... environment variables
130+
if [ -n "$DMA_AUTH_USERNAME" ] && [ -n "$DMA_AUTH_PASSWORD" ]; then
131+
if [ -z "$DMA_CONF_SMARTHOST" ]; then
132+
echo "DMA_AUTH_USERNAME and DMA_AUTH_PASSWORD are set, but DMA_CONF_SMARTHOST is empty - not attempting authentication" >&2
133+
else
134+
echo "$DMA_AUTH_USERNAME|$DMA_CONF_SMARTHOST:$DMA_AUTH_PASSWORD" > /etc/dma/auth.conf
135+
fi
136+
fi
137+
fi
138+
119139
php /usr/local/bin/generate_conf.php > /etc/php/${PHP_VERSION}/mods-available/generated_conf.ini
120140
php /usr/local/bin/setup_extensions.php | sudo bash
121141

utils/generate_dma.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* A very simple script in charge of generating the DMA configuration based on environment variables.
4+
* The script is run on each start of the container.
5+
*/
6+
7+
require __DIR__.'/utils.php';
8+
9+
$found = false;
10+
11+
foreach ($_SERVER as $key => $value) {
12+
if (strpos($key, 'DMA_') === 0) {
13+
$found = true;
14+
}
15+
if (strpos($key, 'DMA_CONF_') === 0) {
16+
$suffix = substr($key, 9);
17+
18+
echo $suffix." ".$value."\n";
19+
}
20+
}
21+
22+
if (($found === true) && !file_exists('/usr/sbin/dma')) {
23+
// Let's check DMA is installed (it could be not installed is we are using the slim version...)
24+
error_log('DMA is not available in this image. If you are using the thecodingmachine/php "slim" variant, do not forget to add "ARG INSTALL_DMA=1" in your Dockerfile. Check the documentation for more details.');
25+
exit(1);
26+
}

0 commit comments

Comments
 (0)