Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new transversal directory structure #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions mautic3/apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
FROM php:7.1-apache

LABEL vendor="Mautic"
LABEL maintainer="Luiz Eduardo Oliveira Fonseca <luiz@powertic.com>"

# Install PHP extensions
RUN apt-get update && apt-get install --no-install-recommends -y \
cron \
git \
wget \
sudo \
libc-client-dev \
libicu-dev \
libkrb5-dev \
libmcrypt-dev \
libssl-dev \
libz-dev \
unzip \
zip \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/* \
&& rm /etc/cron.daily/*

RUN docker-php-ext-configure imap --with-imap --with-imap-ssl --with-kerberos \
&& docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install imap intl mbstring mcrypt mysqli pdo_mysql zip opcache bcmath\
&& docker-php-ext-enable imap intl mbstring mcrypt mysqli pdo_mysql zip opcache bcmath

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

# Define Mautic volume to persist data
VOLUME /var/www/html

# Define Mautic version and expected SHA1 signature
ENV MAUTIC_VERSION 2.16.2
ENV MAUTIC_SHA1 df6735df8d7d31cc6bc505c38ee8147b40b8311b

# By default enable cron jobs
ENV MAUTIC_RUN_CRON_JOBS true

# Setting an root user for test
ENV MAUTIC_DB_USER root
ENV MAUTIC_DB_NAME mautic

# Setting PHP properties
ENV PHP_INI_DATE_TIMEZONE='UTC' \
PHP_MEMORY_LIMIT=512M \
PHP_MAX_UPLOAD=128M \
PHP_MAX_EXECUTION_TIME=300

# Download package and extract to web volume
RUN curl -o mautic.zip -SL https://github.com/mautic/mautic/releases/download/${MAUTIC_VERSION}/${MAUTIC_VERSION}.zip \
&& echo "$MAUTIC_SHA1 *mautic.zip" | sha1sum -c - \
&& mkdir /usr/src/mautic \
&& unzip mautic.zip -d /usr/src/mautic \
&& rm mautic.zip \
&& chown -R www-data:www-data /usr/src/mautic

# Copy init scripts and custom .htaccess
COPY docker-entrypoint.sh /entrypoint.sh
COPY makeconfig.php /makeconfig.php
COPY makedb.php /makedb.php
COPY mautic.crontab /etc/cron.d/mautic
RUN chmod 644 /etc/cron.d/mautic

# Enable Apache Rewrite Module
RUN a2enmod rewrite

# Apply necessary permissions
RUN ["chmod", "+x", "/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]

CMD ["apache2-foreground"]
164 changes: 164 additions & 0 deletions mautic3/common/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/bin/bash
set -e

if [ ! -f /usr/local/etc/php/php.ini ]; then
cat <<EOF > /usr/local/etc/php/php.ini
date.timezone = "${PHP_INI_DATE_TIMEZONE}"
always_populate_raw_post_data = -1
memory_limit = ${PHP_MEMORY_LIMIT}
file_uploads = On
upload_max_filesize = ${PHP_MAX_UPLOAD}
post_max_size = ${PHP_MAX_UPLOAD}
max_execution_time = ${PHP_MAX_EXECUTION_TIME}
EOF
fi


if [ -n "$MYSQL_PORT_3306_TCP" ]; then
if [ -z "$MAUTIC_DB_HOST" ]; then
export MAUTIC_DB_HOST='mysql'
if [ "$MAUTIC_DB_USER" = 'root' ] && [ -z "$MAUTIC_DB_PASSWORD" ]; then
export MAUTIC_DB_PASSWORD="$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
fi
else
echo >&2 "warning: both MAUTIC_DB_HOST and MYSQL_PORT_3306_TCP found"
echo >&2 " Connecting to MAUTIC_DB_HOST ($MAUTIC_DB_HOST)"
echo >&2 " instead of the linked mysql container"
fi
fi


if [ -z "$MAUTIC_DB_HOST" ]; then
echo >&2 "error: missing MAUTIC_DB_HOST and MYSQL_PORT_3306_TCP environment variables"
echo >&2 " Did you forget to --link some_mysql_container:mysql or set an external db"
echo >&2 " with -e MAUTIC_DB_HOST=hostname:port?"
exit 1
fi


if [ -z "$MAUTIC_DB_PASSWORD" ]; then
echo >&2 "error: missing required MAUTIC_DB_PASSWORD environment variable"
echo >&2 " Did you forget to -e MAUTIC_DB_PASSWORD=... ?"
echo >&2
echo >&2 " (Also of interest might be MAUTIC_DB_USER and MAUTIC_DB_NAME.)"
exit 1
fi

#ENABLES HUBSPOT CRON
if [ -n "$MAUTIC_CRON_HUBSPOT" ]; then
echo >&2 "CRON: Activating Hubspot"
echo "10,40 * * * * www-data php /var/www/html/app/console mautic:integration:fetchleads --integration=Hubspot > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
echo "15,45 * * * * www-data php /var/www/html/app/console mautic:integration:pushactivity --integration=Hubspot > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
fi

#ENABLES SALESFORCE CRON
if [ -n "$MAUTIC_CRON_SALESFORCE" ]; then
echo >&2 "CRON: Activating Salesforce"
echo "10,40 * * * * www-data php /var/www/html/app/console mautic:integration:fetchleads --integration=Salesforce > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
echo "12,42 * * * * www-data php /var/www/html/app/console mautic:integration:pushactivity --integration=Salesforce > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
echo "14,44 * * * * www-data php /var/www/html/app/console mautic:integration:pushleadactivity --integration=Salesforce > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
echo "16,46 * * * * www-data php /var/www/html/app/console mautic:integration:synccontacts --integration=Salesforce > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
fi

#ENABLES SUGARCRM CRON
if [ -n "$MAUTIC_CRON_SUGARCRM" ]; then
echo >&2 "CRON: Activating SugarCRM"
echo "10,40 * * * * www-data php /var/www/html/app/console mautic:integration:fetchleads --fetch-all --integration=Sugarcrm > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
fi

#ENABLES PIPEDRIVE CRON
if [ -n "$MAUTIC_CRON_PIPEDRIVE" ]; then
echo >&2 "CRON: Activating Pipedrive"
echo "10,40 * * * * www-data php /var/www/html/app/console mautic:integration:pipedrive:fetch > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
echo "15,45 * * * * www-data php /var/www/html/app/console mautic:integration:pipedrive:push > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
fi

#ENABLES ZOHO CRON
if [ -n "$MAUTIC_CRON_ZOHO" ]; then
echo >&2 "CRON: Activating ZohoCRM"
echo "10,40 * * * * www-data php /var/www/html/app/console mautic:integration:fetchleads --integration=Zoho > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
fi

#ENABLES DYNAMICS CRON
if [ -n "$MAUTIC_CRON_DYNAMICS" ]; then
echo >&2 "CRON: Activating DynamicsCRM"
echo "10,40 * * * * www-data php /var/www/html/app/console mautic:integration:fetchleads -i Dynamics > /var/log/cron.pipe 2>&1" >> /etc/cron.d/mautic
fi

if ! [ -e index.php -a -e app/AppKernel.php ]; then
echo >&2 "Mautic not found in $(pwd) - copying now..."

if [ "$(ls -A)" ]; then
echo >&2 "WARNING: $(pwd) is not empty - press Ctrl+C now if this is an error!"
( set -x; ls -A; sleep 10 )
fi

tar cf - --one-file-system -C /usr/src/mautic . | tar xf -

echo >&2 "Complete! Mautic has been successfully copied to $(pwd)"
fi

# Ensure the MySQL Database is created
php /makedb.php "$MAUTIC_DB_HOST" "$MAUTIC_DB_USER" "$MAUTIC_DB_PASSWORD" "$MAUTIC_DB_NAME"

echo >&2 "========================================================================"
echo >&2
echo >&2 "This server is now configured to run Mautic!"
echo >&2 "The following information will be prefilled into the installer (keep password field empty):"
echo >&2 "Host Name: $MAUTIC_DB_HOST"
echo >&2 "Database Name: $MAUTIC_DB_NAME"
echo >&2 "Database Username: $MAUTIC_DB_USER"
echo >&2 "Database Password: $MAUTIC_DB_PASSWORD"

# Write the database connection to the config so the installer prefills it
if ! [ -e app/config/local.php ]; then
php /makeconfig.php

# Make sure our web user owns the config file if it exists
chown www-data:www-data app/config/local.php
mkdir -p /var/www/html/app/logs
chown www-data:www-data /var/www/html/app/logs
fi

if [[ "$MAUTIC_RUN_CRON_JOBS" == "true" ]]; then
if [ ! -e /var/log/cron.pipe ]; then
mkfifo /var/log/cron.pipe
chown www-data:www-data /var/log/cron.pipe
fi
(tail -f /var/log/cron.pipe | while read line; do echo "[CRON] $line"; done) &
CRONLOGPID=$!
cron -f &
CRONPID=$!
else
echo >&2 "Not running cron as requested."
fi

echo >&2
echo >&2 "========================================================================"


# Github Pull Tester
if [ -n "$MAUTIC_TESTER" ]; then
echo >&2 "Copying Mautic Github Pull Tester"
wget https://raw.githubusercontent.com/mautic/mautic-tester/master/tester.php
fi


"$@" &
MAINPID=$!

shut_down() {
if [[ "$MAUTIC_RUN_CRON_JOBS" == "true" ]]; then
kill -TERM $CRONPID || echo 'Cron not killed. Already gone.'
kill -TERM $CRONLOGPID || echo 'Cron log not killed. Already gone.'
fi
kill -TERM $MAINPID || echo 'Main process not killed. Already gone.'
}
trap 'shut_down;' TERM INT

# wait until all processes end (wait returns 0 retcode)
while :; do
if wait; then
break
fi
done
50 changes: 50 additions & 0 deletions mautic3/common/makeconfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
$stderr = fopen('php://stderr', 'w');

fwrite($stderr, "\nWriting initial Mautic config\n");

$parameters = array(
'db_driver' => 'pdo_mysql',
'install_source' => 'Docker'
);

if(array_key_exists('MAUTIC_DB_HOST', $_ENV)) {
// Figure out if we have a port in the database host string
if (strpos($_ENV['MAUTIC_DB_HOST'], ':') !== false) {
list($host, $port) = explode(':', $_ENV['MAUTIC_DB_HOST'], 2);
$parameters['db_port'] = $port;
}
else {
$host = $_ENV['MAUTIC_DB_HOST'];
}
$parameters['db_host'] = $host;
}
if(array_key_exists('MAUTIC_DB_NAME', $_ENV)) {
$parameters['db_name'] = $_ENV['MAUTIC_DB_NAME'];
}
if(array_key_exists('MAUTIC_DB_TABLE_PREFIX', $_ENV)) {
$parameters['db_table_prefix'] = $_ENV['MAUTIC_DB_TABLE_PREFIX'];
}
if(array_key_exists('MAUTIC_DB_USER', $_ENV)) {
$parameters['db_user'] = $_ENV['MAUTIC_DB_USER'];
}
if(array_key_exists('MAUTIC_DB_PASSWORD', $_ENV)) {
$parameters['db_password'] = $_ENV['MAUTIC_DB_PASSWORD'];
}
if(array_key_exists('MAUTIC_TRUSTED_PROXIES', $_ENV)) {
$proxies = explode(',', $_ENV['MAUTIC_TRUSTED_PROXIES']);
$parameters['trusted_proxies'] = $proxies;
}

if(array_key_exists('PHP_INI_DATE_TIMEZONE', $_ENV)) {
$parameters['default_timezone'] = $_ENV['PHP_INI_DATE_TIMEZONE'];
}

$path = '/var/www/html/app/config/local.php';
$rendered = "<?php\n\$parameters = ".var_export($parameters, true).";\n";

$status = file_put_contents($path, $rendered);

if ($status === false) {
fwrite($stderr, "\nCould not write configuration file to $path, you can create this file with the following contents:\n\n$rendered\n");
}
46 changes: 46 additions & 0 deletions mautic3/common/makedb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
// Args: 0 => makedb.php, 1 => "$MAUTIC_DB_HOST", 2 => "$MAUTIC_DB_USER", 3 => "$MAUTIC_DB_PASSWORD", 4 => "$MAUTIC_DB_NAME"
$stderr = fopen('php://stderr', 'w');
fwrite($stderr, "\nEnsuring Mautic database is present\n");

if (strpos($argv[1], ':') !== false)
{
list($host, $port) = explode(':', $argv[1], 2);
}
else
{
$host = $argv[1];
$port = 3306;
}

$maxTries = 10;

do
{
$mysql = new mysqli($host, $argv[2], $argv[3], '', (int) $port);

if ($mysql->connect_error)
{
fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
--$maxTries;

if ($maxTries <= 0)
{
exit(1);
}

sleep(5);
}
}
while ($mysql->connect_error);

if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($argv[4]) . '`'))
{
fwrite($stderr, "\nMySQL 'CREATE DATABASE' Error: " . $mysql->error . "\n");
$mysql->close();
exit(1);
}

fwrite($stderr, "\nMySQL Database Created\n");

$mysql->close();
20 changes: 20 additions & 0 deletions mautic3/common/mautic.crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

8,23,38,52 * * * * www-data php /var/www/html/app/console mautic:segments:update > /var/log/cron.pipe 2>&1
*/5 * * * * www-data php /var/www/html/app/console mautic:import > /var/log/cron.pipe 2>&1
5,20,35,50 * * * * www-data php /var/www/html/app/console mautic:campaigns:rebuild > /var/log/cron.pipe 2>&1
2,17,32,47 * * * * www-data php /var/www/html/app/console mautic:campaigns:trigger > /var/log/cron.pipe 2>&1
0,15,30,45 * * * * www-data php /var/www/html/app/console mautic:messages:send > /var/log/cron.pipe 2>&1
0,15,30,45 * * * * www-data php /var/www/html/app/console mautic:emails:send > /var/log/cron.pipe 2>&1
0,15,30,45 * * * * www-data php /var/www/html/app/console mautic:email:fetch > /var/log/cron.pipe 2>&1
0,15,30,45 * * * * www-data php /var/www/html/app/console mautic:social:monitoring > /var/log/cron.pipe 2>&1
0,15,30,45 * * * * www-data php /var/www/html/app/console mautic:webhooks:process > /var/log/cron.pipe 2>&1
0,15,30,45 * * * * www-data php /var/www/html/app/console mautic:broadcasts:send > /var/log/cron.pipe 2>&1
* 1 * * * www-data php /var/www/html/app/console mautic:maintenance:cleanup --days-old=365 > /var/log/cron.pipe 2>&1
0 4 15 * * www-data php /var/www/html/app/console mautic:iplookup:download > /var/log/cron.pipe 2>&1
*/5 * * * * www-data php /var/www/html/app/console mautic:reports:scheduler > /var/log/cron.pipe 2>&1
0 5 10 * * www-data php /var/www/html/app/console mautic:unusedip:delete > /var/log/cron.pipe 2>&1

# download geoip db on start if it does not exist
@reboot www-data [[ "$(ls -A /var/www/html/app/cache/ip_data 2>/dev/null)" ]] || php /var/www/html/app/console mautic:iplookup:download > /var/log/cron.pipe 2>&1
Loading