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

Add DDEV first-run experience ✨ #235

Merged
merged 5 commits into from
Feb 17, 2021
Merged
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
18 changes: 18 additions & 0 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: api-library
type: php
docroot: ""
php_version: "7.4"
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
mariadb_version: "10.3"
mysql_version: ""
provider: default
use_dns_when_possible: true
composer_version: "2"
hooks:
post-start:
- exec: "./.ddev/mautic-setup.sh"
74 changes: 74 additions & 0 deletions .ddev/local.config.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Authentication/Authorization Method
|--------------------------------------------------------------------------
|
| Specifies which Class to use when creating the Auth class
|
| Currently supported values are:
| OAuth - Uses the default OAuth class
| BasicAuth - Uses Basic Authentication - Mautic >= 2.4
|
| Pass this as the second parameter to specify which to use.
|
| If commented out, will default OAuth. see MauticApiTestCase::getAuth()
|
*/
'AuthMethod' => 'BasicAuth',

/*
|--------------------------------------------------------------------------
| Basic Authentication credentials
|--------------------------------------------------------------------------
|
| Basic Auth uses a simple username password method.
|
| It's important to note, that this is not recommended unless you are
| using HTTPS as your username and password are exposed.
|
| BOTH the username and password are required. It's recommended that
| you add a specific user and ensure a long passPhrase!
|
*/
'userName' => 'admin',
'password' => 'mautic',

/*
|--------------------------------------------------------------------------
| OAuth credentials
|--------------------------------------------------------------------------
|
| The API supports both OAuth1a and OAuth2.
|
| I've found there is more control if you specify which version you want
| to use.
|
| Required mainly for OAuth 1a testing; 'OAuth1a' or 'OAuth2'
|
*/
'version' => 'OAuth1a',

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

// Required for All tests
'apiUrl' => 'http://localhost/mautic/index_dev.php/api/',
// Required for EmailsTest
'testEmail' => '[email protected]',

// Required for both OAuth 1a and 2 testing
'accessToken' => '',

// Required only for OAuth 1a testing
'accessTokenSecret' => '',
'requestTokenUrl' => '', // Set with any string to force the library to use the OAuth1.a spec; leave blank to use OAuth2
'clientKey' => '',
'clientSecret' => '',
'callback' => '',

// Required only for OAuth 2 testing.
'refreshToken' => '',
];
17 changes: 17 additions & 0 deletions .ddev/mautic-local.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Parameter overrides for DDEV.
*/
$parameters = [
'api_enabled' => true,
'api_enable_basic_auth' => true,
'db_driver' => 'pdo_mysql',
'db_host' => 'db',
'db_table_prefix' => null,
'db_port' => 3306,
'db_name' => 'db',
'db_user' => 'db',
'db_password' => 'db',
'admin_email' => '[email protected]',
'admin_password' => 'mautic',
];
68 changes: 68 additions & 0 deletions .ddev/mautic-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

setup_mautic() {
cp ./.ddev/local.config.php.dist ./tests/local.config.php

printf "Cloning the \"features\" branch from mautic/mautic...\n"
git clone -b features --single-branch --depth 1 https://github.com/mautic/mautic.git mautic
cp ./.ddev/mautic-local.php.dist ./mautic/app/config/local.php
cd mautic

# Need to downgrade to Composer v1 until Mautic 4 is out
printf "Installing Mautic Composer dependencies...\n"
composer self-update --1
composer install --prefer-dist --no-progress

printf "Installing Mautic...\n"
php bin/console mautic:install http://localhost/mautic \
--mailer_from_name="DDEV" --mailer_from_email="[email protected]" \
--mailer_transport="smtp" --mailer_host="localhost" --mailer_port="1025"
php bin/console cache:warmup --no-interaction --env=dev

printf "Enabling Twilio plugin for tests...\n"
mysql -udb -pdb -P3306 -hdb -e "USE db; INSERT INTO plugin_integration_settings (id, plugin_id, name, is_published, supported_features, api_keys, feature_settings) VALUES (2, 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

tput setaf 2
printf "All done! Run \"ddev exec composer test\" to run PHPUnit tests.\n"
printf "If you want to open the Mautic instance, go to https://api-library.ddev.site/mautic in your browser.\n"
tput sgr0
}

# Check if the user has indicated their preference for the Mautic installation
# already (DDEV-managed or self-managed)
if ! test -f ./.ddev/mautic-preference
then
printf "Installing the API library Composer dependencies...\n"
composer install
tput setab 3
tput setaf 0
printf "Do you want us to set up a Mautic instance for you to test against?\n"
printf "If you answer \"no\", you will have to set up a Mautic instance yourself."
tput sgr0
printf "\nAnswer [yes/no]: "
read MAUTIC_PREF

if [[ $MAUTIC_PREF == "yes" ]]
then
printf "Okay, setting up a Mautic instance...\n"
echo "ddev-managed" > ./.ddev/mautic-preference
setup_mautic
else
printf "Okay, you'll have to set up a Mautic instance yourself. "
printf "Copy /tests/local.config.php.dist to /tests/local.config.php and add your Mautic instance settings.\n"
echo "unmanaged" > ./.ddev/mautic-preference
fi
else
# Ensure our mautic/mautic clone is up-to-date
echo "Updating the cloned Mautic instance..."
cd mautic
git pull
# Need to downgrade to Composer v1 until Mautic 4 is out
composer self-update --1
composer install --prefer-dist --no-progress
tput setaf 2
printf "Run \"ddev exec composer test\" to run PHPUnit tests.\n"
printf "If you want to open the Mautic instance, go to https://api-library.ddev.site/mautic in your browser.\n"
tput sgr0
fi
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
/tests/phpunit.phar
/vendor
.DS_Store
/.ddev
.phpunit.result.cache
.phpunit.result.cache
/.ddev/mautic-preference
/mautic