Roots Discourse

Using Branch CI to deploy Sage 10 to Pantheon

I’m building a new site using sage10. I’m deploying to pantheon using Branch CI to build assets and deploy from github. Things seem to be working okay as far as the steps go. The site does not load, however.

I get this:
Warning: require(/code/wp-content/themes/firstpitch-reebok/vendor/composer/ClassLoader.php): failed
to open stream: No such file or directory in /code/wp-content/themes/firstpitch-
reebok/vendor/composer/autoload_real.php on line 12 Fatal error: require(): Failed opening required
‘/code/wp-content/themes/firstpitch-reebok/vendor/composer/ClassLoader.php’
(include_path=’.:/usr/share/pear:/usr/share/php’) in /code/wp-content/themes/firstpitch-
reebok/vendor/composer/autoload_real.php on line 12`

For my build steps, I run
composer install
yarn install && yarn build:production

And my assets get built just fine. But there are obviously files missing from composer.

I was ignoring all files in the sage’s /vendor folder like so
wp-content/themes/firstpitch-reebok/vendor/
!wp-content/themes/firstpitch-reebok/vendor/autoload.php
!wp-content/themes/firstpitch-reebok/vendor/composer/autoload_real.php

Clearly, I’m not understanding a key part of this.

1 Like

I’m just following up my own post. While I’m using Branch CI for this, I think this would apply to Circle CI in some way also.

There are a couple of steps that are required during the CI build process in order to deploy Sage 10 to Pantheon.

The Problem
There are a pair of problems first off:

  1. Pantheon does not allow write access to the filesystem. Sage 10 requires write access to {your_theme}/storage/famework/cache. Thus, Sage 10 cannot write to this directory on Pantheon.

  2. Another problem is that Pantheon will not allow you to commit anything to the uploads folder at all, so it cannot be in your source nor can you exclude a custom folder within the uploads directory. You’ll understand why this part matters in a bit.

Workaround
One way users often get around filesystem write perm issues on Pantheon is to symlink the files or directories that need to be written to by symlinking to the wp-content/uploads folder.

  1. In your local install, move {your_theme}/storage directory to uploads/storage
  2. In a terminal cd to your local {your_theme} folder
  3. Create a symlink to uploads/storage ie ln -sfn ./../../uploads/storage
  4. Commit the symlink to your local repository.
  5. Upload the uploads/storage directory to your Pantheon site via SFTP. This is required because when you push your repo to GitHub the uploads/storage directory will not be present since you cannot commit anything in the uploads folder. Your commits will be rejected by Pantheon if you try to exclude a directory/file within /uploads.

Branch Steps
In Branch, you only need a few steps in order to deploy to Pantheon.

  1. Clone code from Github repo. This fires whenever you push code to Github. (command provided by Branch recipe)
  2. Create storage directory in uploads.
    cd wp-content && mkdir -p uploads/storage/framework/cache
  3. Composer install
    cd wp-content/themes/firstpitch-reebok && composer install --prefer-dist --no-dev
  4. Build sage assets
    cd wp-content/themes/firstpitch-reebok && yarn install && yarn build && yarn build:production
  5. Deploy to Pantheon. (command provided as part of Branch Pantheon recipe.

This is awesome @digisavvy. Thanks for sharing your solution!

1 Like

Can you write to the application root path? With WPE I put tmp/cache at the same level as wp-config.

No, unfortunately. The symlink is a workaround, although not a great one. I’m going to send to the Pantheon forum and see what they have to say. Pantheon’s WP circle ci example has some interesting tidbits. Paricularly that .gitignore file: https://github.com/pantheon-systems/example-wordpress-composer. They’re doing something hacky with it where things you might commit to github does not get sent to pantheon and vice-versa. It’s weird but they managed to get around some of these issues I’m having by doing that.

What about this idea? Can you put the compiled blades inside the theme dir itself? I have not experimented with this in Sage 10 but I think Acorn can compile templates prior to runtime?

At one point in time I used this script from @alwaysblank https://github.com/alwaysblank/blade-generate