Deploy fails after working correctly previously

So I deployed a staging version of my site and it worked great. I made one minor change (css change in the theme) and deployed and now it’s giving me an error. Reverted the change just to test, and it’s still giving the same error.

*changed domain to sitename for this post

$ ansible-playbook server.yml -e env=staging
$ ./deploy.sh staging sitename.com

PHP Fatal error:  Uncaught Error: Class 'Roots\Sage\Assets\JsonManifest' not
found in /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/helpers.php:27
Stack trace:
#0 /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/
setup.php(67): App\asset_path('styles/main.css')
#1 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-
includes/plugin.php(524): App\{closure}('')
#2 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-settings.php(395):
do_action('after_setup_the...')
#3 phar:///usr/bin/wp/php/WP_CLI/Runner.php(971):
require('/srv/www/site...')
#4 phar:///usr/bin/wp/php/commands/eval.php(44):
WP_CLI\Runner->load_wordpress()
#5 [internal function]: Eval_Command->__invoke(Array, Array)
#6 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(67):
call_user_func(Array, Array, Array)
#7 [internal function]:
WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#8 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(372):
call_user_func(Object(Cl in /srv/www/sitename.com/releases/20161118223156/web
/app/themes/sitename/src/helpers.php on line 27
Fatal error: Uncaught Error: Class 'Roots\Sage\Assets\JsonManifest' not found
in /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/
helpers.php:27
Stack trace:
#0 /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/
setup.php(67): App\asset_path('styles/main.css')
#1 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-
includes/plugin.php(524): App\{closure}('')
#2 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-settings.php(395):
do_action('after_setup_the...')
#3 phar:///usr/bin/wp/php/WP_CLI/Runner.php(971):
require('/srv/www/site...')
#4 phar:///usr/bin/wp/php/commands/eval.php(44):
WP_CLI\Runner->load_wordpress()
#5 [internal function]: Eval_Command->__invoke(Array, Array)
#6 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(67):
call_user_func(Array, Array, Array)
#7 [internal function]:
WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#8 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(372):
call_user_func(Object(Cl in /srv/www/sitename.com/releases/20161118223156/web
/app/themes/sitename/src/helpers.php on line 27
fatal: [staging.sitename.com]: FAILED! => {"changed": true, "cmd": ["wp", "eval", "wp_clean_themes_cache(); switch_theme(get_stylesheet());"], "delta": "0:00:00.357373", "end": "2016-11-18 22:32:16.978570", "failed": true, "rc": 255, "start": "2016-11-18 22:32:16.621197", "stderr": "PHP Fatal error:  Uncaught Error: Class 'Roots\\Sage\\Assets\\JsonManifest' not found in /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/helpers.php:27\nStack trace:\n#0 /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/setup.php(67): App\\asset_path('styles/main.css')\n#1 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-includes/plugin.php(524): App\\{closure}('')\n#2 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-settings.php(395): do_action('after_setup_the...')\n#3 phar:///usr/bin/wp/php/WP_CLI/Runner.php(971): require('/srv/www/sitenam...')\n#4 phar:///usr/bin/wp/php/commands/eval.php(44): WP_CLI\\Runner->load_wordpress()\n#5 [internal function]: Eval_Command->__invoke(Array, Array)\n#6 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(67): call_user_func(Array, Array, Array)\n#7 [internal function]: WP_CLI\\Dispatcher\\CommandFactory::WP_CLI\\Dispatcher\\{closure}(Array, Array)\n#8 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(372): call_user_func(Object(Cl in /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/helpers.php on line 27\nFatal error: Uncaught Error: Class 'Roots\\Sage\\Assets\\JsonManifest' not found in /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/helpers.php:27\nStack trace:\n#0 /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/setup.php(67): App\\asset_path('styles/main.css')\n#1 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-includes/plugin.php(524): App\\{closure}('')\n#2 /srv/www/sitename.com/releases/20161118223156/web/wp/wp-settings.php(395): do_action('after_setup_the...')\n#3 phar:///usr/bin/wp/php/WP_CLI/Runner.php(971): require('/srv/www/sitename...')\n#4 phar:///usr/bin/wp/php/commands/eval.php(44): WP_CLI\\Runner->load_wordpress()\n#5 [internal function]: Eval_Command->__invoke(Array, Array)\n#6 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(67): call_user_func(Array, Array, Array)\n#7 [internal function]: WP_CLI\\Dispatcher\\CommandFactory::WP_CLI\\Dispatcher\\{closure}(Array, Array)\n#8 phar:///usr/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(372): call_user_func(Object(Cl in /srv/www/sitename.com/releases/20161118223156/web/app/themes/sitename/src/helpers.php on line 27", "stdout": "", "stdout_lines": [], "warnings": []}

So as noted in here, i should run composer install but that means logging into the server and doing that in the theme folder in ...releases/20161118230317/web/app/themes/sitename everytime i do a deploy? Shouldn’t Ansible be doing this?

Did you follow the https://github.com/roots/roots-example-project.com way?

If so, you’ll need to add one thing to the deploy hooks:

- name: Install Composer dependencies
  command: composer install --no-ansi --no-dev --no-interaction --no-progress --optimize-autoloader --no-scripts
  args:
    chdir: "{{ deploy_helper.new_release_path }}/web/app/themes/sage"

That example project is still based on Sage 8, not Sage 9 alpha.

1 Like

The issue here, as you seem to have identified, are the tasks needed to build the site. When setting up Sage locally, you had to run NPM install and Composer install, the same work needs to be done for your remote site.

You should not login to the server and install the Dev tools. Those tools are supposed to be for you as a developer building the site, not for running on the live site’s server.

TL;DR

Trellis has built in functionality to build the theme as the deployment is running. Have a look at the build-before hooks. To use them, just uncomment the relevant lines from your file in trellis, and make sure all your paths and file names are updated to match your setup.

1 Like

Ok! I saw the “Install Composer dependencies” in build-after.yml so thought that should have covered it. But I see that that’s just for bedrock not sage. That solved the issue. Thanks @swalkinshaw @thisolivier