Skip to content

Commit

Permalink
Add logging to install script
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenoh committed Jan 16, 2025
1 parent 1ad6446 commit d2f3ed7
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 52 deletions.
32 changes: 10 additions & 22 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,8 @@ hooks:
post-start:
# Set up debugging.
- exec: 'test -f .vscode/launch.json || (mkdir -p .vscode && cp .ddev/launch.json .vscode/)'
# Get a local copy of Drupal CMS and check out the default branch.
# Patch for issue #3496399.
- exec: 'cd repos/drupal/drupal_cms && test -n "$(ls -A)" || (git submodule update --init --remote --recursive && git checkout $(git branch -r | grep "origin/HEAD" | cut -f 3 -d "/") && (git merge-base --is-ancestor 86d48c24bdf96494a8a017d15c368574794d580a HEAD 2> /dev/null || git apply $DDEV_COMPOSER_ROOT/patches/drupal/drupal_cms/373.patch))'
# If needed, regenerate `composer.json` and install dependencies.
# @see homeadditions/bin/generate-composer-json
- exec: 'test -f composer.lock || (.devpanel/generate-composer-json > composer.json && composer install)'
# The installer is part of the project template, so symlink it into the web root.
# It needs to be a relative symlink, or it will break Package Manager.
- exec: 'ln -s -f $(realpath -s --relative-to=$DDEV_DOCROOT/profiles repos/drupal/drupal_cms/project_template/web/profiles/drupal_cms_installer) $DDEV_DOCROOT/profiles'
# Install JavaScript dependencies if needed. The `--foreground-scripts`
# option is needed to ensure the Cypress binary is actually downloaded;
# see the warning about Node.js Snap for Linux at
# https://docs.cypress.io/guides/getting-started/installing-cypress.
- exec: 'cd repos/drupal/drupal_cms && test -d node_modules || npm clean-install --foreground-scripts'
# Build Experience Builder's JavaScript bundle, if needed.
- exec: 'XB_UI_PATH=$DDEV_DOCROOT/modules/contrib/experience_builder/ui; test -d $XB_UI_PATH/dist || ( npm --prefix $XB_UI_PATH install && npm --prefix $XB_UI_PATH run build )'
# Create the private files directory.
- exec: 'test -d private || mkdir private'
# Add the private files path to settings.php.
- exec: 'grep -qxF "\$settings[''file_private_path''] = ''../private'';" web/sites/default/settings.php || echo "\$settings[''file_private_path''] = ''../private'';" >> web/sites/default/settings.php'
# Pre-install starter recipe.
- exec: 'test -d recipes/drupal_cms_starter && test -z "$(drush status --fields=bootstrap)" && .devpanel/install > /dev/null && until drush recipe ../recipes/drupal_cms_starter; do :; done && drush -n pmu drupal_cms_installer && drush cr || true'
# Run initial setup tasks.
- exec: '.devpanel/init.sh'
web_environment:
# For faster performance, don't audit dependencies automatically.
- COMPOSER_NO_AUDIT=1
Expand All @@ -51,6 +31,14 @@ web_environment:
# Use the DDEV-provided database to run PHPUnit tests.
- SIMPLETEST_DB=$DDEV_DATABASE_FAMILY://db:db@db/db
- SIMPLETEST_BASE_URL=$DDEV_PRIMARY_URL
# Set up DevPanel variables.
- APP_ROOT=$DDEV_COMPOSER_ROOT
- WEB_ROOT=$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT
- DB_HOST=db
- DB_PORT=3306
- DB_USER=db
- DB_PASSWORD=db
- DB_NAME=db
webimage_extra_packages:
# Add Cypress' system dependencies.
# See https://docs.cypress.io/guides/getting-started/installing-cypress#UbuntuDebian
Expand Down
4 changes: 2 additions & 2 deletions .devpanel/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ hooks:
# echo "Hello World"
# date >> test.txt
cmd: |-
composer install --no-dev >> /tmp/composer_main.txt
composer -n install --no-dev >> /tmp/composer_main.txt
- branch: "develop"
# matches release on "develop" branch only
# run commands or scripts from cmd below... eg:
# echo "Hello World"
# date >> test.txt
cmd: |-
composer install >> /tmp/composer_develop.txt
composer -n install >> /tmp/composer_develop.txt
7 changes: 7 additions & 0 deletions .devpanel/custom_package_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@

sudo apt-get update
sudo apt-get install -y nano npm

sudo pecl update-channels
sudo pecl install apcu <<< ''
echo 'extension=apcu.so' | sudo tee /usr/local/etc/php/conf.d/apcu.ini
sudo pecl install uploadprogress
echo 'extension=uploadprogress.so' | sudo tee /usr/local/etc/php/conf.d/uploadprogress.ini
sudo /etc/init.d/apache2 reload
137 changes: 115 additions & 22 deletions .devpanel/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,161 @@
# For GNU Affero General Public License see <https://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------

LOG_FILE="$APP_ROOT/logs/init-$(date +%F-%T).log"
exec > >(tee $LOG_FILE) 2>&1

TIMEFORMAT=%lR
DDEV_DOCROOT=${WEB_ROOT##*/}
SETTINGS_FILE_PATH=$WEB_ROOT/sites/default/settings.php

#== Clone source code.
if [ -z "$(ls -A $APP_ROOT/repos/drupal/drupal_cms)" ]; then
git submodule update --init --remote --recursive
echo
time git submodule update --init --remote --recursive
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi

cd $APP_ROOT/repos/drupal/drupal_cms
git checkout $(git branch -r | grep "origin/HEAD" | cut -f 3 -d '/')
echo
time git checkout $(git branch -r | grep "origin/HEAD" | cut -f 3 -d '/')
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi

#== Patch for issue #3497485.
if ! git merge-base --is-ancestor 86d48c24bdf96494a8a017d15c368574794d580a HEAD 2> /dev/null; then
git apply $APP_ROOT/patches/drupal/drupal_cms/373.patch
echo
echo 'Apply patch for issue #3497485.'
time git apply $APP_ROOT/patches/drupal/drupal_cms/373.patch
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
fi
fi

#== Remove root-owned files.
cd $APP_ROOT
sudo rm -rf lost+found
echo
echo Remove root-owned files.
time sudo rm -rf lost+found
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi

#== Composer install.
if [ ! -f composer.lock ]; then
.devpanel/generate-composer-json > composer.json
composer install
echo
echo 'Generate composer.json.'
time .devpanel/generate-composer-json > composer.json
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi

echo
time composer -n install --no-progress
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
fi

#== Symlink the installer into the web root.
ln -s -f $(realpath -s --relative-to=$DDEV_DOCROOT/profiles repos/drupal/drupal_cms/project_template/$DDEV_DOCROOT/profiles/drupal_cms_installer) $DDEV_DOCROOT/profiles
#== Symlink Drupal CMS installer into web root.
echo
echo 'Symlink Drupal CMS installer into web root.'
time ln -s -f $(realpath -s --relative-to=$DDEV_DOCROOT/profiles repos/drupal/drupal_cms/project_template/$DDEV_DOCROOT/profiles/drupal_cms_installer) $DDEV_DOCROOT/profiles
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi

#== Install JavaScript dependencies if needed.
cd $APP_ROOT/repos/drupal/drupal_cms
if [ ! -d node_modules ]; then
npm clean-install --foreground-scripts
time npm -q clean-install
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
fi

#== Build Experience Builder's JavaScript bundle, if needed.
cd $APP_ROOT
XB_UI_PATH=$DDEV_DOCROOT/modules/contrib/experience_builder/ui
if [ -d $XB_UI_PATH/dist ]; then
npm --prefix $XB_UI_PATH install
npm --prefix $XB_UI_PATH run build
if [ ! -d $XB_UI_PATH/dist ]; then
echo
time npm -q --prefix $XB_UI_PATH install
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
echo
time npm -q --prefix $XB_UI_PATH run build
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
fi

#== Create the private files directory.
cd $APP_ROOT
if [ ! -d private ]; then
mkdir private
echo
echo 'Create the private files directory.'
time mkdir private
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
fi

#== Set up settings.php file.
if [ ! -f $SETTINGS_FILE_PATH ]; then
echo "Set up settings.php file."
cp $APP_ROOT/.devpanel/drupal-settings.php $SETTINGS_FILE_PATH
echo
echo 'Set up settings.php file.'
time cp $APP_ROOT/.devpanel/drupal-settings.php $SETTINGS_FILE_PATH
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
fi

#== Pre-install starter recipe.
cd $APP_ROOT
if [ -d recipes/drupal_cms_starter ] && [ -z "$(mysql -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASSWORD $DB_NAME -e 'show tables')" ]; then
while [ -z "$(drush status --fields=bootstrap)" ]; do
.devpanel/install > /dev/null
echo
echo 'Install Drupal base system.'
while [ -z "$(drush sget drupal_cms_profile.profile_modules_installed 2> /dev/null)" ]; do
time .devpanel/install > /dev/null
done
until drush recipe $APP_ROOT/recipes/drupal_cms_starter; do
drush sdel drupal_cms_profile.profile_modules_installed

echo
echo 'Apply the Drupal CMS starter recipe.'
until time drush -q recipe $APP_ROOT/recipes/drupal_cms_starter; do
:
done
drush -n pmu drupal_cms_installer
drush cr

echo
time drush -n pmu drupal_cms_installer
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi

echo
time drush cr
RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
exit $RETURN_CODE
fi
fi

INIT_DURATION=$SECONDS
INIT_HOURS=$(($INIT_DURATION / 3600))
INIT_MINUTES=$(($INIT_DURATION % 3600 / 60))
INIT_SECONDS=$(($INIT_DURATION % 60))
printf "\nTotal elapsed time: %d:%02d:%02d\n" $INIT_HOURS $INIT_MINUTES $INIT_SECONDS
13 changes: 8 additions & 5 deletions .devpanel/install
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ $_GET['site_name'] = 'Drupal CMS';
register_shutdown_function('_install_drupal_cms_profile_modules');

function _install_drupal_cms_profile_modules() {
$install_state['profile_info'] = install_profile_info('drupal_cms_installer');
$batch = install_profile_modules($install_state);
$context = ['results' => []];
foreach ($batch['operations'] as $step) {
call_user_func_array($step[0], array_merge($step[1], [&$context]));
global $install_state;
if ($install_state['base_system_verified']) {
$batch = install_profile_modules($install_state);
$context = ['results' => []];
foreach ($batch['operations'] as $step) {
call_user_func_array($step[0], array_merge($step[1], [&$context]));
}
\Drupal::state()->set('drupal_cms_profile.profile_modules_installed', TRUE);
}
}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/composer.json
/composer.lock
/config/
/logs/
/packages.json
/patches.lock.json
/private/
Expand Down
Empty file added logs/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion repos/drupal/drupal_cms
Submodule drupal_cms updated from 1774e7 to 0447ac

0 comments on commit d2f3ed7

Please sign in to comment.