Skip to content

switch to docker image instead of installing Mautic locally #290

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

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
17f7f85
switch to docker image instead of installing Mautic locally
mollux Feb 10, 2023
f19ec72
correct db name
mollux Feb 10, 2023
9d89fa7
other creds
mollux Feb 10, 2023
a8238c5
no empty password allowed
mollux Feb 10, 2023
7ec4294
correct copy
mollux Feb 10, 2023
dfb16c9
give mautic a name
mollux Feb 10, 2023
4f76fc3
does this work?
mollux Feb 10, 2023
80538a1
no tty
mollux Feb 10, 2023
951de60
first step
mollux Feb 10, 2023
950d6fd
we need the source obviously
mollux Feb 10, 2023
d47a158
no dev env
mollux Feb 10, 2023
a5753ee
more params
mollux Feb 10, 2023
1a8a07f
more config
mollux Feb 10, 2023
b4949db
reshuffle
mollux Feb 10, 2023
5d6cc2a
correct filename
mollux Feb 10, 2023
90ef07c
dollars
mollux Feb 10, 2023
585ad80
faster tests? + logs
mollux Feb 10, 2023
bb1b684
install after changing algo
mollux Feb 10, 2023
cf2b7a1
logs
mollux Feb 10, 2023
29cec55
permissions
mollux Feb 10, 2023
e26654c
faster?
mollux Feb 10, 2023
13fa1bf
debug user password
mollux Feb 11, 2023
4cffa6f
clear cache before
mollux Feb 11, 2023
27f8e89
why are they failing?
mollux Feb 11, 2023
e51c738
let's see if non-parallel works
mollux Feb 11, 2023
bb1dd6a
uncomment
mollux Feb 11, 2023
63b44ac
switch to supported version
mollux Feb 11, 2023
f7ea514
let's try multiple images
mollux Feb 11, 2023
a2302fd
quoting
mollux Feb 11, 2023
b8d9198
correct images and path
mollux Feb 11, 2023
014a22f
correct paths
mollux Feb 11, 2023
31dea6c
we need mysql binary
mollux Feb 11, 2023
780ad62
new log dir
mollux Feb 11, 2023
cca1f49
workaround for failing tests
mollux Feb 11, 2023
64a43bc
get logs from correct dir
mollux Feb 11, 2023
f91d97e
better naming
mollux Feb 11, 2023
d17ded9
bump version
mollux Feb 11, 2023
3b6a893
cleanup
mollux Feb 11, 2023
95a1d02
test API on both 7.4 and 8.0
mollux Feb 12, 2023
4945f72
let's test something
mollux Feb 12, 2023
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
4 changes: 2 additions & 2 deletions .github/ci-files/local.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
'version' => 'OAuth1a',

// Required for OAuth1a and OAuth2
'baseUrl' => 'http://localhost/index_dev.php',
'baseUrl' => 'http://localhost/',

// Required for All tests
'apiUrl' => 'http://localhost/index_dev.php/api/',
'apiUrl' => 'http://localhost/api/',
// Required for EmailsTest
'testEmail' => 'notexisting@email.com',

Expand Down
17 changes: 0 additions & 17 deletions .github/ci-files/local.php

This file was deleted.

59 changes: 59 additions & 0 deletions .github/ci-files/prepare_mautic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -e

apt-get update && apt-get install default-mysql-client -y

cd /var/www

cat << 'EOF' > docroot/app/config/parameters_local.php
<?php
/**
* Parameter overrides for GitHub Actions.
*/
$parameters = [
'api_enabled' => true,
'api_enable_basic_auth' => true,
];
EOF

cat << 'EOF2' > docroot/app/config/security_local.php
<?php

$this->import('security.php');

// Support HTTP basic auth for test logins
$container->loadFromExtension('security',
[
'firewalls' => [
'main' => [
// Support HTTP basic auth for test logins
'http_basic' => true,
],
],
'encoders' => [
'Symfony\Component\Security\Core\User\User' => [
'algorithm' => 'md5',
'encode_as_base64' => false,
'iterations' => 0,
],
'Mautic\UserBundle\Entity\User' => [
'algorithm' => 'md5',
'encode_as_base64' => false,
'iterations' => 0,
],
],
]
);
EOF2

php bin/console cache:clear --no-warmup

php bin/console mautic:install http://localhost/ --force --mailer_from_name="GitHub Actions" --mailer_from_email="github-actions@mautic.org" --mailer_transport="smtp" --mailer_host="mailhog" --mailer_port="1025" --admin_username=admin --admin_password=mautic --admin_email="bla@bla.be"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mollux can you please remove the email values from this command as it will now fail due to mautic/mautic#12216

And set them in the config file directly.


mysql -uroot -proot -hmysql mautictest -e "INSERT INTO plugin_integration_settings (plugin_id, name, is_published, supported_features, api_keys, feature_settings) VALUES (NULL, 'Twilio', 1, 'a:0:{}', 'a:2:{s:8:\"username\";s:169:\"bzFmNlIydWRSZXlIN2lQVkdpanJ4aTQ2NUh6RVdDbHlLRVhsWGZ4b0kyZVNxLzYrQ1J6V1RvMnlhVEp0c245TEp6eStQekx5ZVhLWjB1YVdoR3RnR2dHQ3k1emVVdGt5NzZKUmtjUnJ3c1E9|L8tbZRIYhwatT7Mq+HAdYA==\";s:8:\"password\";s:169:\"T2d2cFpXQWE5YVZnNFFianJSYURRYUtGRHBNZGZjM1VETXg2Wm5Va3NheW43MjVWUlJhTVlCL2pYMDBpbElONStiVVBNbEM3M3BaeGJMNkFKNUFEN1pTNldSRjc4bUM4SDh1SE9OY1k5MTg9|TeuSvfx4XSUOvp0O7T49Cg==\";}', 'a:4:{s:20:\"sending_phone_number\";N;s:22:\"disable_trackable_urls\";i:0;s:16:\"frequency_number\";N;s:14:\"frequency_time\";N;}');"
php bin/console mautic:plugins:reload

cp -rp docroot/app/assets/images/* docroot/media/images/

chown -R www-data:www-data /var/www
125 changes: 52 additions & 73 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,116 +18,93 @@ on:
jobs:
phpunit:
runs-on: ubuntu-20.04
name: PHPUnit tests
name: PHPUnit ${{ matrix.php_version }} ${{ matrix.mautic_version }}
strategy:
matrix:
mautic_version: ["5.x-dev", "4.x-dev"]
php_version: ["7.4", "8.0", "8.1"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per #286 PHP 7 is no longer supported.

Suggested change
php_version: ["7.4", "8.0", "8.1"]
php_version: ["8.0", "8.1"]


services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: mautictest
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
- 3306:3306
options: >-
--shm-size=2gb
--name=mysql
--tmpfs=/var/lib/mysql
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3

mailhog:
image: mailhog/mailhog:latest
ports:
- 1025:1025

redis:
image: redis:6
ports:
- 6379:6379

mautic:
image: ghcr.io/mollux/docker-mautic:${{ matrix.mautic_version }}
env:
MAUTIC_DB_HOST: mysql
MAUTIC_DB_USER: root
MAUTIC_DB_PASSWORD: root
MAUTIC_DB_NAME: mautictest
MAUTIC_RUN_CRON_JOBS: "false"
ports:
- 80:80
options:
--health-cmd="curl --fail http://localhost || exit 1"
--health-interval=10s
--health-timeout=5s
--health-retries=10
--name=mautic
steps:
- uses: actions/checkout@v3

- name: Prepare Mautic installation
run: |
sudo docker cp .github/ci-files/prepare_mautic.sh mautic:/tmp/prepare_mautic.sh
sudo docker exec mautic chmod 755 /tmp/prepare_mautic.sh
sudo docker exec mautic /tmp/prepare_mautic.sh

- name: Copy our API library config into the tests/ folder
run: cp -a ./.github/ci-files/local.config.php tests/local.config.php

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
ini-values: session.save_handler=redis, session.save_path="tcp://127.0.0.1:6379"
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
php-version: ${{ matrix.php_version }}
coverage: pcov

- name: Set SYMFONY_ENV to test
run: echo "SYMFONY_ENV=test" >> $GITHUB_ENV

- name: Install Apache
# We need the sed command at the bottom to set the PHP session save path to a directory that's writable for PHP
# NOTE: update the PHP version below as well if you're updating PHP!
run: |
sudo add-apt-repository ppa:ondrej/php -y
sudo add-apt-repository ppa:ondrej/apache2 -y
sudo apt-get install apache2 libapache2-mod-php8.0
sudo a2enmod rewrite
sudo sed -i 's,^session.save_handler =.*$,session.save_handler = redis,' /etc/php/8.0/apache2/php.ini
sudo sed -i 's,^;session.save_path =.*$,session.save_path = "tcp://127.0.0.1:6379",' /etc/php/8.0/apache2/php.ini
sudo service apache2 restart
cat /etc/php/8.0/apache2/php.ini | grep session

- name: Install dependencies
run: |
composer validate --strict
composer install --prefer-dist --no-progress

- name: Clone Mautic main branch or specific PR from GitHub
run: |
gh repo clone mautic/mautic -- --single-branch --depth 1
if [[ "${{ github.event.inputs.pr }}" != "" ]]; then
pushd mautic
gh pr checkout ${{ github.event.inputs.pr }}
popd
fi
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Move files to web root
run: |
shopt -s dotglob
sudo chmod -R 777 /var/www/html
sudo chown -R www-data:www-data /var/www/html
rm -rf /var/www/html/*
mv $GITHUB_WORKSPACE/mautic/* /var/www/html/

- name: Install Mautic
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
composer install --prefer-dist --no-progress
cp $GITHUB_WORKSPACE/.github/ci-files/local.php ./app/config/local.php
php bin/console mautic:install http://localhost/ \
--force --mailer_from_name="GitHub Actions" --mailer_from_email="github-actions@mautic.org" \
--mailer_transport="smtp" --mailer_host="localhost" --mailer_port="1025" --env=dev
php bin/console cache:warmup --no-interaction --env=dev
working-directory: /var/www/html/

# Enable Twilio plugin with random credentials (needed for MessagesTest to function, doesn't actually contact Twilio API).
- name: Enable Twilio plugin
run: |
mysql -uroot -P${{ job.services.mysql.ports[3306] }} -h127.0.0.1 -e "USE mautictest; INSERT INTO plugin_integration_settings (plugin_id, name, is_published, supported_features, api_keys, feature_settings) VALUES (NULL, 'Twilio', 1, 'a:0:{}', 'a:2:{s:8:\"username\";s:169:\"bzFmNlIydWRSZXlIN2lQVkdpanJ4aTQ2NUh6RVdDbHlLRVhsWGZ4b0kyZVNxLzYrQ1J6V1RvMnlhVEp0c245TEp6eStQekx5ZVhLWjB1YVdoR3RnR2dHQ3k1emVVdGt5NzZKUmtjUnJ3c1E9|L8tbZRIYhwatT7Mq+HAdYA==\";s:8:\"password\";s:169:\"T2d2cFpXQWE5YVZnNFFianJSYURRYUtGRHBNZGZjM1VETXg2Wm5Va3NheW43MjVWUlJhTVlCL2pYMDBpbElONStiVVBNbEM3M3BaeGJMNkFKNUFEN1pTNldSRjc4bUM4SDh1SE9OY1k5MTg9|TeuSvfx4XSUOvp0O7T49Cg==\";}', 'a:4:{s:20:\"sending_phone_number\";N;s:22:\"disable_trackable_urls\";i:0;s:16:\"frequency_number\";N;s:14:\"frequency_time\";N;}');"
php bin/console mautic:plugins:reload --env=dev
working-directory: /var/www/html

- name: Set correct ownership so Apache can access the files
run: sudo chown -R www-data:www-data /var/www/html

- name: Run tests
run: vendor/bin/paratest -p 3 --coverage-clover coverage.xml
run: vendor/bin/phpunit --coverage-clover coverage.xml

- name: Upload code coverage
run: bash <(curl -s https://codecov.io/bash)


- name: gather logs
if: always()
run: |
sudo docker cp mautic:/var/www/docroot/var/logs/ /tmp/logs

- name: Upload logs as artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: always()
with:
name: mautic-logs
path: /var/www/html/var/logs/
name: mautic-logs-${{ matrix.mautic_version }}
path: /tmp/logs/

- name: Slack Notification if tests fail
uses: rtCamp/action-slack-notify@v2
Expand All @@ -139,15 +116,17 @@ jobs:
cs:
runs-on: ubuntu-20.04
name: CS tests
strategy:
matrix:
php_version: ["7.4", "8.0"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem.

Suggested change
php_version: ["7.4", "8.0"]
php_version: ["8.0"]


steps:
- uses: actions/checkout@v3

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
php-version: ${{ matrix.php_version }}

- name: Install dependencies
run: |
Expand Down
15 changes: 14 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="false" backupGlobals="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
failOnRisky="true"
failOnWarning="true"
>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">lib</directory>
Expand Down