Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Install DMA & handle configuration variables (fixes #204)
  • Loading branch information
moqmar committed Feb 7, 2022
commit cb71e1afd76bbf980825cba90f19e98e6c01ab52
1 change: 1 addition & 0 deletions Dockerfile.apache
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# DO NOT EDIT THIS FILE : Make yours changes in /utils/Dockerfile.*.blueprint)
ARG INSTALL_CRON=1
ARG INSTALL_COMPOSER=1
ARG INSTALL_DMA=1
ARG PHP_VERSION
ARG GLOBAL_VERSION
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-apache
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.cli
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# DO NOT EDIT THIS FILE : Make yours changes in /utils/Dockerfile.*.blueprint)
ARG INSTALL_CRON=1
ARG INSTALL_COMPOSER=1
ARG INSTALL_DMA=1
ARG PHP_VERSION
ARG GLOBAL_VERSION
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-cli
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.fpm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# DO NOT EDIT THIS FILE : Make yours changes in /utils/Dockerfile.*.blueprint)
ARG INSTALL_CRON=1
ARG INSTALL_COMPOSER=1
ARG INSTALL_DMA=1
ARG PHP_VERSION
ARG GLOBAL_VERSION
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-fpm
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile.slim.apache
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php

COPY utils/enable_apache_mods.php /usr/local/bin/enable_apache_mods.php
Expand Down Expand Up @@ -385,3 +386,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*; \
fi;

# |--------------------------------------------------------------------------
# | DragonFly Mail Agent
# |--------------------------------------------------------------------------
# |
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
# | to send email from PHP, either using direct delivery or through an SMTP
# | smarthost.
# |

ONBUILD ARG INSTALL_DMA
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
sudo apt-get update && \
sudo -E apt-get install -y --no-install-recommends dma; \
fi;
16 changes: 16 additions & 0 deletions Dockerfile.slim.cli
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php

COPY utils/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
Expand Down Expand Up @@ -290,3 +291,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*; \
fi;

# |--------------------------------------------------------------------------
# | DragonFly Mail Agent
# |--------------------------------------------------------------------------
# |
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
# | to send email from PHP, either using direct delivery or through an SMTP
# | smarthost.
# |

ONBUILD ARG INSTALL_DMA
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
sudo apt-get update && \
sudo -E apt-get install -y --no-install-recommends dma; \
fi;
16 changes: 16 additions & 0 deletions Dockerfile.slim.fpm
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php

COPY utils/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
Expand Down Expand Up @@ -313,3 +314,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*; \
fi;

# |--------------------------------------------------------------------------
# | DragonFly Mail Agent
# |--------------------------------------------------------------------------
# |
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
# | to send email from PHP, either using direct delivery or through an SMTP
# | smarthost.
# |

ONBUILD ARG INSTALL_DMA
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
sudo apt-get update && \
sudo -E apt-get install -y --no-install-recommends dma; \
fi;
1 change: 1 addition & 0 deletions utils/Dockerfile.blueprint
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ARG INSTALL_CRON=1
ARG INSTALL_COMPOSER=1
ARG INSTALL_DMA=1
ARG PHP_VERSION
ARG GLOBAL_VERSION
FROM thecodingmachine/php:${PHP_VERSION}-${GLOBAL_VERSION}-slim-{{ $variant }}
Expand Down
16 changes: 16 additions & 0 deletions utils/Dockerfile.slim.blueprint
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
COPY utils/generate_dma.php /usr/local/bin/generate_dma.php
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php
{{if eq $variant "apache" }}
COPY utils/enable_apache_mods.php /usr/local/bin/enable_apache_mods.php
Expand Down Expand Up @@ -416,3 +417,18 @@ ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*; \
fi;

# |--------------------------------------------------------------------------
# | DragonFly Mail Agent
# |--------------------------------------------------------------------------
# |
# | Installs DragonFly Mail Agent, a sendmail-compatible MTA that can be used
# | to send email from PHP, either using direct delivery or through an SMTP
# | smarthost.
# |

ONBUILD ARG INSTALL_DMA
ONBUILD RUN if [ -n "$INSTALL_DMA" ]; then \
sudo apt-get update && \
sudo -E apt-get install -y --no-install-recommends dma; \
fi;
20 changes: 20 additions & 0 deletions utils/docker-entrypoint-as-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ fi
unset DOCKER_FOR_MAC_REMOTE_HOST
unset REMOTE_HOST_FOUND

if [ -e /usr/sbin/dma ]; then
# set sendmail path for PHP
if [ "$DMA_FROM" = "" ]; then
DMA_FROM=noreply@example.org
fi
export PHP_INI_SENDMAIL_PATH="/usr/sbin/sendmail -t -i -f'$DMA_FROM'"

# generate DMA config based on DMA_CONF_... environment variables
php /usr/local/bin/generate_dma.php > /etc/dma/dma.conf

# generate DMA authentication file based on DMA_AUTH_... environment variables
if [ -n "$DMA_AUTH_USERNAME" ] && [ -n "$DMA_AUTH_PASSWORD" ]; then
if [ -z "$DMA_CONF_SMARTHOST" ]; then
echo "DMA_AUTH_USERNAME and DMA_AUTH_PASSWORD are set, but DMA_CONF_SMARTHOST is empty - not attempting authentication" >&2
else
echo "$DMA_AUTH_USERNAME|$DMA_CONF_SMARTHOST:$DMA_AUTH_PASSWORD" > /etc/dma/auth.conf
fi
fi
fi

sudo chown docker:docker /opt/php_env_var_cache.php
/usr/bin/real_php /usr/local/bin/check_php_env_var_changes.php &> /dev/null

Expand Down
26 changes: 26 additions & 0 deletions utils/generate_dma.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* A very simple script in charge of generating the DMA configuration based on environment variables.
* The script is run on each start of the container.
*/

require __DIR__.'/utils.php';

$found = false;

foreach ($_SERVER as $key => $value) {
if (strpos($key, 'DMA_') === 0) {
$found = true;
}
if (strpos($key, 'DMA_CONF_') === 0) {
$suffix = substr($key, 9);

echo $suffix." ".$value."\n";
}
}

if (($found === true) && !file_exists('/usr/sbin/dma')) {
// Let's check DMA is installed (it could be not installed is we are using the slim version...)
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.');
exit(1);
}