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

BLT post-code-deploy hook failing on ACSF #2673

Closed
malcolmp opened this issue Mar 22, 2018 · 8 comments
Closed

BLT post-code-deploy hook failing on ACSF #2673

malcolmp opened this issue Mar 22, 2018 · 8 comments
Labels
Support A support request

Comments

@malcolmp
Copy link

BLT version: 8.9.14

We've been referred to report a BLT issue we're encountering on D8 an Acquia Sitefactory deployment. As a result of this post-deploy hook the ACSF deployment is failing.

This is the portion of the stacktrace that is failing in BLT:

<< [Acquia\Blt\Robo\Tasks\DrushTask]  Exit code 1  Time 0.732s
<< [error]  Failed to import configuration!
<< [error]  Command `setup:config-import ` exited with code 1.
<< [2018-03-20 18:17:31] WARN: Command returned exit code 1: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git executing hook post-code-deploy

Full error log output:

[Acquia Cloud Site Factory Task 12833433]
- Description: Deploy code to 02devup
- Body:        {"repo":"asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git","repo_id":"1221","from_vcs_type":"git","to_site":"asf802devup","to_stage":"02devup","from_path":"8.x-1.x-dev","no_create":true}
- Sender:      58cf3f52-544c-487f-a76b-efbce6c6f282
- Server:      task-388.enterprise-g1.hosting.acquia.com
- Queue:       code-push
- State:       failed
- Created:     2018-03-20 18:17:19 UTC
- Started:     2018-03-20 18:17:20 UTC (1s)
- Completed:   2018-03-20 18:17:31 UTC (11s from start, 12s total)

[snip]

<< [2018-03-20 18:17:23] asf8.02devup: updating web_servers[staging-2112].
<< Updating asf8.02devup to deploy 8.x-1.x-dev
<< Deploying 8.x-1.x-dev on asf8.02devup
<< [2018-03-20 18:17:28] Starting hook: post-code-deploy
<< [2018-03-20 18:17:29] Executing: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git < /dev/null (as asf8.02devup@staging-2112})
<<
<< site="$1"
<< target_env="$2"
<< source_branch="$3"
<< deployed_tag="$4"
<< repo_url="$5"
<< repo_type="$6"
<<
<<
<<   . /var/www/html/$site.$target_env/vendor/acquia/blt/scripts/cloud-hooks/functions.sh
<< #!/bin/bash
<< # Common functions for cloud hooks.
<<
<< status=0
<<
<< drush_alias=${site}'.'${target_env}
<<
<< deploy_updates() {
<<
<<   case $target_env in
<<     01dev|01test|01live)
<<       acsf_deploy
<<       ;;
<<     01devup|01testup|01update)
<<       ;;
<<     *)
<<       ace_deploy
<<       ;;
<<     esac
<< }
<<
<< acsf_deploy() {
<<   sites=()
<<   # Prep for BLT commands.
<<   repo_root="/var/www/html/$site.$target_env"
<<   export PATH=$repo_root/vendor/bin:$PATH
<<   cd $repo_root
<<
<<   # Clear drush cache to make sure it can find ACSF tools.
<<   echo "Clearing Drush cache"
<<   drush cc drush
<<
<<   echo "Running updates for environment: $target_env"
<<
<<   # Generate an array of all site URIs on the Factory from parsed output of Drush utility.
<<   while IFS=$'\n' read -r line; do
<<       sites[i++]="$line"
<<       done < <(drush @"${drush_alias}" --include=./drush acsf-tools-list | grep domains: -A 1 | grep 0: | sed -e 's/^[0: ]*//')
<<       unset IFS
<<
<<   # Loop through each available site uri and run BLT deploy updates.
<<   for uri in "${sites[@]}"; do
<<   #Override BLT default deploy uri.
<<   blt deploy:update --define environment=$target_env --define drush.uri="$uri" -v -y
<<   if [ $? -ne 0 ]; then
<<       echo "Update errored for site $uri."
<<       exit 1
<<   fi
<<
<<   echo "Finished updates for site: $uri."
<<   done
<<
<<   echo "Finished updates for all $target_env sites."
<< }
<<
<< ace_deploy() {
<<
<<   echo "Running updates for environment: $target_env"
<<
<<   # Prep for BLT commands.
<<   repo_root="/var/www/html/$site.$target_env"
<<   export PATH=$repo_root/vendor/bin:$PATH
<<   cd $repo_root
<<
<<   blt deploy:update --define environment=$target_env -v -y
<<   if [ $? -ne 0 ]; then
<<       echo "Update errored."
<<       exit 1
<<   fi
<<
<<   echo "Finished updates for environment: $target_env"
<< }
<<
<< deploy_install() {
<<
<<   echo "Installing site for environment: $target_env"
<<
<<   # Prep for BLT commands.
<<   repo_root="/var/www/html/$site.$target_env"
<<   export PATH=$repo_root/vendor/bin:$PATH
<<   cd $repo_root
<<
<<   blt deploy:drupal:install --define environment=$target_env -v -y
<<   if [ $? -ne 0 ]; then
<<       echo "Install errored."
<<       exit 1
<<   fi
<<
<<   echo "Finished installing for environment: $target_env"
<< }
<<   deploy_updates
<< Running updates for environment: 02devup
<< Deploying updates to simpletest...
<< > setup:config-import
<< Executing pre-config-import target hook...
<< [ExecStack] echo 'No pre-config-import configured.'
<< [ExecStack] Running echo 'No pre-config-import configured.' in /var/www/html/asf8.02devup/docroot
<< No pre-config-import configured.
<< [ExecStack] Done in 0.002s
<< [Acquia\Blt\Robo\Tasks\DrushTask] Running /var/www/html/asf8.02devup/vendor/bin/drush cc drush --uri=simpletest --yes in /var/www/html/asf8.02devup/docroot
<< 'drush' cache was cleared.                                             [success]
<< [Acquia\Blt\Robo\Tasks\DrushTask] Done in 0.236s
<< [Acquia\Blt\Robo\Tasks\DrushTask] Running /var/www/html/asf8.02devup/vendor/bin/drush cache-rebuild --uri=simpletest --yes in /var/www/html/asf8.02devup/docroot
<< Drupal\Core\Database\ConnectionNotDefinedException: The specified        [error]
<< database connection is not defined: default in
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Core/Database/Database.php:361
<< Stack trace:
<< #0
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Core/Database/Database.php(166):
<< Drupal\Core\Database\Database::openConnection('default', 'default')
<< #1 [internal function]:
<< Drupal\Core\Database\Database::getConnection('default')
<< #2
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(248):
<< call_user_func_array(Array, Array)
<< #3
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171):
<< Drupal\Component\DependencyInjection\Container->createService(Array,
<< 'database')
<< #4
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(480):
<< Drupal\Component\DependencyInjection\Container->get('database', 1)
<< #5
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(230):
<< Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
<< #6
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171):
<< Drupal\Component\DependencyInjection\Container->createService(Array,
<< 'cache.backend.c...')
<< #7
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Core/Cache/CacheFactory.php(83):
<< Drupal\Component\DependencyInjection\Container->get('cache.backend.c...')
<< #8 [internal function]:
<< Drupal\Core\Cache\CacheFactory->get('bootstrap')
<< #9
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(248):
<< call_user_func_array(Array, Array)
<< #10
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171):
<< Drupal\Component\DependencyInjection\Container->createService(Array,
<< 'cache.bootstrap')
<< #11
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(480):
<< Drupal\Component\DependencyInjection\Container->get('cache.bootstrap',
<< 1)
<< #12
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(230):
<< Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
<< #13
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(171):
<< Drupal\Component\DependencyInjection\Container->createService(Array,
<< 'module_handler')
<< #14
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Core/DrupalKernel.php(549):
<< Drupal\Component\DependencyInjection\Container->get('module_handler')
<< #15
<< /mnt/www/html/asf802devup/docroot/core/lib/Drupal/Core/DrupalKernel.php(710):
<< Drupal\Core\DrupalKernel->preHandle(Object(Symfony\Component\HttpFoundation\Request))
<< #16 /mnt/www/html/asf802devup/docroot/core/includes/utility.inc(43):
<< Drupal\Core\DrupalKernel->prepareLegacyRequest(Object(Symfony\Component\HttpFoundation\Request))
<< #17
<< /mnt/www/html/asf802devup/vendor/drush/drush/commands/core/cache.drush.inc(302):
<< drupal_rebuild(Object(Composer\Autoload\ClassLoader),
<< Object(Symfony\Component\HttpFoundation\Request))
<< #18
<< /mnt/www/html/asf802devup/vendor/drush/drush/includes/command.inc(422):
<< drush_cache_rebuild()
<< #19
<< /mnt/www/html/asf802devup/vendor/drush/drush/includes/command.inc(231):
<< _drush_invoke_hooks(Array, Array)
<< #20
<< /mnt/www/html/asf802devup/vendor/drush/drush/includes/command.inc(199):
<< drush_command()
<< #21
<< /mnt/www/html/asf802devup/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67):
<< drush_dispatch(Array)
<< #22
<< /mnt/www/html/asf802devup/vendor/drush/drush/includes/preflight.inc(66):
<< Drush\Boot\BaseBoot->bootstrap_and_dispatch()
<< #23 /mnt/www/html/asf802devup/vendor/drush/drush/drush.php(12):
<< drush_main()
<< #24 {main}
<< [Acquia\Blt\Robo\Tasks\DrushTask]  Exit code 1  Time 0.732s
<< [error]  Failed to import configuration!
<< [error]  Command `setup:config-import ` exited with code 1.
<< 0.852s total time elapsed.
<< [2018-03-20 18:17:31] Finished hook: post-code-deploy
<<
<< [2018-03-20 18:17:31] Sending webhook hook: 'post-code-deploy' revision: ''!
<< [2018-03-20 18:17:31] WARN: Command returned exit code 1: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git executing hook post-code-deploy
<< zlib(finalizer): the stream was freed prematurely.
@grasmash grasmash added Support A support request acsf labels Mar 22, 2018
@lcatlett
Copy link
Contributor

There are two issues:

  1. The post-code-deploy Cloud Hook is deprecated and unsupported so it should not be executed on ACSF environments Acsf hooks deploy #2227 made this change in BLT 9.x and it was not backported to BLT 8.x. You should instead us the db-update Factory Hook such as the one in BLT 9 which will run blt deploy:update tasks on each site during a code deploy. Additional documentation and examples of using BLT with the db-update Factory Hook is available in the Acquia ACSF documentation as well: https://docs.acquia.com/index.php/site-factory/extend/hooks/dbupdate#blt.

  2. Update environments are explicitly excluded from all Cloud Hook execution because in ACSF deployment / platform code updates, this is actually your "live" environment. The BLT Cloud Hooks scripts already have this exclusion for the standard environments:
    https://github.com/acquia/blt/blob/8.9.14/scripts/cloud-hooks/functions.sh#L14

BLT provides post-code-update hooks (as opposed to post-code-deploy) for default ACSF environments 01dev, 01test but not custom environments like 02dev. In your case the hook actually executed in your 02devup environment which is your update environment and since the deploy was a branch as opposed to a tag, the post-code-update executed against the 02devup environment a second time using the Acquia Cloud scripts rather than the acsf_deploy script in functions.sh. You can add environments to this list and modify your post-code-update.sh script to execute your custom fucntions.sh script. Before making these changes you should review the ACSF Hooks documentation, particularly the section "Using Acquia Cloud hooks" and the hooks which are not supported on ACSF.

@malcolmp
Copy link
Author

I'm not sure I understand what the proposed resolution is. We're just using the same default hooks that were created for the previous version of the BLT project. Are they still needed in 9.x (and must be moved) or should they be removed entirely?

Also, this custom environment is a D8 stack https://docs.acquia.com/site-factory/tiers/stacks so I feel it is reasonable to expect ACSF and BLT to fully support it.

@lcatlett
Copy link
Contributor

@malcolmp I created #2676 to track your feature request. I should have clarified in my response that by "custom environment" I meant environments that are not the default 01dev, 01test, or 01live on ACSF which in your case would include Stacks.

If you would like to use post-code-update hooks immediately to resolve your error message you can follow the recommendations above which I have pasted below to clarify that it is an action item:

  1. You should instead use the db-update Factory Hook such as the one in BLT 9 which will run blt deploy:update tasks on each site during a code deploy. Additional documentation and examples of using BLT with the db-update Factory Hook is available in the Acquia ACSF documentation as well: docs.acquia.com/index.php/site-factory/extend/hooks/dbupdate#blt.

  2. You can add environments to this list and modify your post-code-update.sh script to execute your custom functions.sh script. Before making these changes you should review the ACSF Hooks documentation, particularly the section "Using Acquia Cloud hooks" and the hooks which are not supported on ACSF.

@malcolmp
Copy link
Author

malcolmp commented Mar 23, 2018

So I've commented out the code from the post-code-deploy hook, however the deployment is still failing.

WARN: Command returned exit code 1: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git executing hook post-code-deployzlib(finalizer): the stream was freed prematurely.[requestStatus] => 200[retryLog] => Array()[failureState] => 1)

It seems like it's failing on the existing 8.x-1.x-dev branch while I'm deploying the feature/8.4.x-dev branch so removing the deploy_updates function isn't working. Can you think of any reason that would be an issue?

@lcatlett
Copy link
Contributor

@malcolmp I put in #2682 which should resolve your issue and also adds some additional ACSF backports from BLT 9.x. You can patch your version of BLT with the PR or update to the latest version once it is merged and then run blt setup:cloud-hooks to update your Cloud Hooks and then blt acsf:init to update your Factory Hooks

@malcolmp
Copy link
Author

@lcatlett I merged in the PR and ran both commands but am still getting the below error attempting to deploy our new branch.

[staging-389] - Checking hosting task 12993668; stdClass Object
([id] => 12993668[queue] => code-push[state] => failed[description] => Deploy code to 02devup[created] => 1522098001[started] => 1522098001[completed] => 1522098013[sender] => 58cf3f52-544c-487f-a76b-efbce6c6f282[result] =>[cookie] =>[logs] => [21:00:01] [21:00:01] Started[21:00:13] [2018-03-26 21:00:05] asf8.02devup: updating web_servers[staging-2112].Updating asf8.02devup to deploy 8.x-1.x-devDeploying 8.x-1.x-dev on asf8.02devup[2018-03-26 21:00:10] Starting hook: post-code-deploy[2018-03-26 21:00:11] Executing: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git < /dev/null (as asf8.02devup@staging-2112})site="$1"target_env="$2"source_branch="$3"deployed_tag="$4"repo_url="$5"repo_type="$6". /var/www/html/$site.$target_env/vendor/acquia/blt/scripts/cloud-hooks/functions.sh#!/bin/bash# Common functions for cloud hooks.status=0drush_alias=${site}'.'${target_env}deploy_updates() {case $target_env in01dev|01test|01live)acsf_deploy;;...endor/drush/drush/includes/command.inc(231):_drush_invoke_hooks(Array, Array)#20/mnt/www/html/asf802devup/vendor/drush/drush/includes/command.inc(199):drush_command()#21/mnt/www/html/asf802devup/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67):drush_dispatch(Array)#22/mnt/www/html/asf802devup/vendor/drush/drush/includes/preflight.inc(66):Drush\Boot\BaseBoot->bootstrap_and_dispatch()#23 /mnt/www/html/asf802devup/vendor/drush/drush/drush.php(12):drush_main()#24 {main}[Acquia\Blt\Robo\Tasks\DrushTask] Exit code 1 Time 0.73s[error] Failed to import configuration![error] Command `setup:config-import ` exited with code 1.0.849s total time elapsed.[2018-03-26 21:00:13] Finished hook: post-code-deploy[2018-03-26 21:00:13] Sending webhook hook: 'post-code-deploy' revision: ''![2018-03-26 21:00:13] WARN: Command returned exit code 1: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git executing hook post-code-deployzlib(finalizer): the stream was freed prematurely.[requestStatus] => 200[retryLog] => Array()[failureState] => 1)

@malcolmp
Copy link
Author

With the patch from #2685 I am able to apply to do a fresh deployment to our 02test environment but still getting the below error on 02dev.

[staging-389] - Checking hosting task 13088487; stdClass Object
([id] => 13088487[queue] => code-push[state] => failed[description] => Deploy code to 02devup[created] => 1522364038[started] => 1522364039[completed] => 1522364052[sender] => 58cf3f52-544c-487f-a76b-efbce6c6f282[result] =>[cookie] =>[logs] => [22:53:59] [22:53:59] Started[22:54:12] [2018-03-29 22:54:03] asf8.02devup: updating web_servers[staging-2112].Updating asf8.02devup to deploy 8.x-1.x-devDeploying 8.x-1.x-dev on asf8.02devup[2018-03-29 22:54:09] Starting hook: post-code-deploy[2018-03-29 22:54:10] Executing: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git < /dev/null (as asf8.02devup@staging-2112})site="$1"target_env="$2"source_branch="$3"deployed_tag="$4"repo_url="$5"repo_type="$6". /var/www/html/$site.$target_env/vendor/acquia/blt/scripts/cloud-hooks/functions.sh#!/bin/bash# Common functions for cloud hooks.status=0drush_alias=${site}'.'${target_env}deploy_updates() {case $target_env in01dev|01test|01live)acsf_deploy;;...ndor/drush/drush/includes/command.inc(231):_drush_invoke_hooks(Array, Array)#20/mnt/www/html/asf802devup/vendor/drush/drush/includes/command.inc(199):drush_command()#21/mnt/www/html/asf802devup/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67):drush_dispatch(Array)#22/mnt/www/html/asf802devup/vendor/drush/drush/includes/preflight.inc(66):Drush\Boot\BaseBoot->bootstrap_and_dispatch()#23 /mnt/www/html/asf802devup/vendor/drush/drush/drush.php(12):drush_main()#24 {main}[Acquia\Blt\Robo\Tasks\DrushTask] Exit code 1 Time 0.736s[error] Failed to import configuration![error] Command `setup:config-import ` exited with code 1.0.857s total time elapsed.[2018-03-29 22:54:11] Finished hook: post-code-deploy[2018-03-29 22:54:12] Sending webhook hook: 'post-code-deploy' revision: ''![2018-03-29 22:54:12] WARN: Command returned exit code 1: /mnt/users/asf8/02devup.shell /var/www/html/asf8.02devup/hooks/common/post-code-deploy/post-code-deploy.sh asf8 02devup 8.x-1.x-dev 8.x-1.x-dev asf8@svn-1402.enterprise-g1.hosting.acquia.com:asf8.git git executing hook post-code-deployzlib(finalizer): the stream was freed prematurely.[requestStatus] => 200[retryLog] => Array()[failureState] => 1)

@grasmash
Copy link
Contributor

grasmash commented Apr 2, 2018

@lcatlett is following up on this issue in an Acquia support ticket. It seems to be a project-specific issue.

@grasmash grasmash closed this as completed Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Support A support request
Projects
None yet
Development

No branches or pull requests

3 participants