Pantheon Community

Using Branch CI + Sage/Roots Theme and Deploy to Pantheon

I’m on a project where we’re using Roots/Sage theme. It requires building of assets for production so I figured a CI process would be ideal. I decided to give Branch CI a try 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.

Ultimately, I’d like to know if there’s a cleaner way to deploy. I’ve seen the pantheon composer example: https://github.com/pantheon-systems/example-wordpress-composer. And it looks interesting. What I think is of particular interest is the .gitignore, where they make use of a ‘cut line’ to figure out what files do and don’t get committed to your local and pantheon repos based on where they sit on that line. Interesting hack.

2 Likes