Skip to content

Commit

Permalink
Merge pull request #70 from UN-OCHA/rbaumbach/simplify-local-setup
Browse files Browse the repository at this point in the history
Simplify local setup
  • Loading branch information
berliner authored Mar 30, 2023
2 parents 3fcbcac + 4d205b8 commit 39407f6
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 327 deletions.
63 changes: 27 additions & 36 deletions .docksal/commands/init-site
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ SITEDIR_PATH="${DOCROOT_PATH}/sites/${SITE_DIRECTORY}"

#-------------------------- Helper functions --------------------------------

# Console colors
red='\033[0;31m'
green='\033[0;32m'
green_bg='\033[1;97;42m'
yellow='\033[1;33m'
NC='\033[0m'

echo-red () { echo -e "${red}$1${NC}"; }
echo-green () { echo -e "${green}$1${NC}"; }
echo-green-bg () { echo -e "${green_bg}$1${NC}"; }
echo-yellow () { echo -e "${yellow}$1${NC}"; }

# Copy a settings file.
# Skips if the destination file already exists.
# @param $1 source file
Expand All @@ -46,64 +34,67 @@ copy_settings_file()
cp $source $dest
else
echo "${dest} already in place."
cp -f $source $dest
fi
}

#-------------------------- END: Helper functions --------------------------------

#-------------------------- Functions --------------------------------

composer_install ()
# Check if the local docksal environment file exists.
check_requirements()
{
cd "$PROJECT_ROOT"
echo-green "Installing dependencies..."
composer install
local_docksal_env="${PROJECT_ROOT}/.docksal/docksal-local.env"
if [[ ! -f "${local_docksal_env}" ]]; then
echo "Missing local environment file ${local_docksal_env}"
echo "You can use the following command to create the file based on a template."
echo "Once created, you need to fill in the values for the required environment variables."
echo ""
echo " fin exec cp ${PROJECT_ROOT}/.docksal/default.docksal-local.env ${PROJECT_ROOT}/.docksal/docksal-local.env"
echo ""
exit 1
fi
}

# Initialize local settings files
init_settings ()
# Copy repo settings.php file into project
copy_settings ()
{
# drupal-composer/drupal-project creates settings.php from default.settings.php.
# Since we supply our own settings.php below, we have to drop the default file first.
# TODO: Uncomment the local config (settings.local.php) include section in settings.php inline instead.
# That'a the only change we need in the stock settings.php
rm -f "${SITEDIR_PATH}/settings.php"

copy_settings_file "${PROJECT_ROOT}/.docksal/settings/settings.php" "${SITEDIR_PATH}/settings.php"
copy_settings_file "${PROJECT_ROOT}/.docksal/settings/settings.local.php" "${SITEDIR_PATH}/settings.local.php"
}

# Fix file/folder permissions
fix_permissions ()
{
echo-green "Making site directory writable..."
echo "Making site directory writable..."
chmod 755 "${SITEDIR_PATH}"
}

# Install site
site_install ()
{
cd "$DOCROOT_PATH"

echo-green "Installing Drupal..."
cd $DOCROOT_PATH
# We disable email sending here so site-install does not return an error
# Credit: https://www.drupal.org/project/phpconfig/issues/1826652#comment-12071700
drush site-install standard -y \
install_configure_form.enable_update_status_module=NULL \
--site-name='Indicator Registry'
php -d sendmail_path=/bin/true /usr/local/bin/drush site-install -y --site-name='Humanitarian Action'
}

composer_install ()
{
cd $PROJECT_ROOT
composer install
}
#-------------------------- END: Functions --------------------------------

#-------------------------- Execution --------------------------------

# Project initialization steps
time -p composer_install
check_requirements
composer_install
copy_settings
fix_permissions
init_settings
time -p site_install
time site_install

echo -e "Open ${yellow}http://${VIRTUAL_HOST}${NC} in your browser to verify the setup."
echo-yellow "Look for admin login credentials in the output above."

#-------------------------- END: Execution --------------------------------
9 changes: 9 additions & 0 deletions .docksal/default.docksal-local.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Credentials for HID.
HID_CLIENT_ID=''
HID_CLIENT_SECRET=''

# Credentials for GraphQL access.
GRAPHQL_KEY=''

# Optional: Map internal docksal port to a fixed free port on the host machine.
# MYSQL_PORT_MAPPING='3312:3306'
10 changes: 10 additions & 0 deletions .docksal/docksal.yml
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
version: "2.1"

services:
cli:
volumes:
- ${PROJECT_ROOT}/html/sites/simpletest/:/var/www/html/sites/simpletest:rw
environment:
- HID_CLIENT_ID
- HID_CLIENT_SECRET
- GRAPHQL_KEY
- COMPOSER_MEMORY_LIMIT=-1
166 changes: 5 additions & 161 deletions .docksal/settings/settings.local.php
Original file line number Diff line number Diff line change
@@ -1,164 +1,8 @@
<?php

// @codingStandardsIgnoreFile

/**
* @file
* Local development override configuration feature.
*
* To activate this feature, copy and rename it such that its path plus
* filename is 'sites/default/settings.local.php'. Then, go to the bottom of
* 'sites/default/settings.php' and uncomment the commented lines that mention
* 'settings.local.php'.
*
* If you are using a site name in the path, such as 'sites/example.com', copy
* this file to 'sites/example.com/settings.local.php', and uncomment the lines
* at the bottom of 'sites/example.com/settings.php'.
*/

/**
* Assertions.
*
* The Drupal project primarily uses runtime assertions to enforce the
* expectations of the API by failing when incorrect calls are made by code
* under development.
*
* @see http://php.net/assert
* @see https://www.drupal.org/node/2492225
*
* If you are using PHP 7.0 it is strongly recommended that you set
* zend.assertions=1 in the PHP.ini file (It cannot be changed from .htaccess
* or runtime) on development machines and to 0 in production.
*
* @see https://wiki.php.net/rfc/expectations
*/
assert_options(ASSERT_ACTIVE, TRUE);
\Drupal\Component\Assertion\Handle::register();

/**
* Enable local development services.
*/
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

/**
* Show all error messages, with backtrace information.
*
* In case the error level could not be fetched from the database, as for
* example the database connection failed, we rely only on this value.
*/
$config['system.logging']['error_level'] = 'verbose';

/**
* Disable CSS and JS aggregation.
*/
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;

/**
* Disable the render cache.
*
* Note: you should test with the render cache enabled, to ensure the correct
* cacheability metadata is present. However, in the early stages of
* development, you may want to disable it.
*
* This setting disables the render cache by using the Null cache back-end
* defined by the development.services.yml file above.
*
* Only use this setting once the site has been installed.
*/
# $settings['cache']['bins']['render'] = 'cache.backend.null';

/**
* Disable caching for migrations.
*
* Uncomment the code below to only store migrations in memory and not in the
* database. This makes it easier to develop custom migrations.
*/
# $settings['cache']['bins']['discovery_migration'] = 'cache.backend.memory';

/**
* Disable Internal Page Cache.
*
* Note: you should test with Internal Page Cache enabled, to ensure the correct
* cacheability metadata is present. However, in the early stages of
* development, you may want to disable it.
*
* This setting disables the page cache by using the Null cache back-end
* defined by the development.services.yml file above.
*
* Only use this setting once the site has been installed.
*/
# $settings['cache']['bins']['page'] = 'cache.backend.null';

/**
* Disable Dynamic Page Cache.
*
* Note: you should test with Dynamic Page Cache enabled, to ensure the correct
* cacheability metadata is present (and hence the expected behavior). However,
* in the early stages of development, you may want to disable it.
*/
# $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

/**
* Allow test modules and themes to be installed.
*
* Drupal ignores test modules and themes by default for performance reasons.
* During development it can be useful to install test extensions for debugging
* purposes.
*/
# $settings['extension_discovery_scan_tests'] = TRUE;

/**
* Enable access to rebuild.php.
*
* This setting can be enabled to allow Drupal's php and database cached
* storage to be cleared via the rebuild.php page. Access to this page can also
* be gained by generating a query string from rebuild_token_calculator.sh and
* using these parameters in a request to rebuild.php.
*/
$settings['rebuild_access'] = TRUE;

/**
* Skip file system permissions hardening.
*
* The system module will periodically check the permissions of your site's
* site directory to ensure that it is not writable by the website user. For
* sites that are managed with a version control system, this can cause problems
* when files in that directory such as settings.php are updated, because the
* user pulling in the changes won't have permissions to modify files in the
* directory.
*/
$settings['skip_permissions_hardening'] = TRUE;



// Docksal DB connection settings.
$databases['default']['default'] = array (
'database' => 'gho',
'username' => 'gho',
'password' => 'gho',
'host' => 'mysql',
'driver' => 'mysql',
);

// Workaround for permission issues with NFS shares
$settings['file_chmod_directory'] = 0777;
$settings['file_chmod_file'] = 0666;

# File system settings.
$config['system.file']['path']['temporary'] = '/tmp';

// Reverse proxy configuration (Docksal vhost-proxy)
if (PHP_SAPI !== 'cli') {
$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = array($_SERVER['REMOTE_ADDR']);
// HTTPS behind reverse-proxy
if (
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' &&
!empty($settings['reverse_proxy']) && in_array($_SERVER['REMOTE_ADDR'], $settings['reverse_proxy_addresses'])
) {
$_SERVER['HTTPS'] = 'on';
// This is hardcoded because there is no header specifying the original port.
$_SERVER['SERVER_PORT'] = 443;
}
// If everything is setup correctly, all we need to do is to include the
// docksal specific settings that will get all necessary credentials from
// ./docksal/docksal-local.env
if (file_exists($app_root . '/' . $site_path . '/settings.docksal.php')) {
include $app_root . '/' . $site_path . '/settings.docksal.php';
}
Loading

0 comments on commit 39407f6

Please sign in to comment.