Deploying Sage 9 with Bitbucket Pipelines

Hello everyone,

Currently I’m using a Sage 9 beta 3 without Trellis.
Code is hosted on BitBucket, and my production website is on Siteground (shared hosting with ssh access)

I would like to know if someone has an experience or an example of the Bitbucket Pipelines deploying script for Sage 9 without Trellis, using SSH or FTP.

I’ve found some threads, but they’ve custom solutions, not a general one for Sage 9 without Trellis - https://discourse.roots.io/t/has-someone-tips-for-deploying-sage-with-bitbucket-pipelines/8842

I would be really appreciate if someone will help me.

Thank you in advance, waiting for your answers.

1 Like

I’m currently playing with this myself. Curious to hear about what others have learned.

It seems that the biggest problem with Sage9 + WPEngine is that they don’t allow (in production) php flock, which (I assume) is involved in the Blade compile process.

I’ve attempted this myself on a recent install and had a lot of problems.

Even attempted to use the wp cli package to pre-compile the blades to no avail.

Now I’m thinking about using pipelines to compile and populate the templates files and deploy with sftp rather than git.

Tuning in to thread…

I haven’t yet attempted these steps, but it is worth looking at this as it points out some pitfalls to the pipeline business: https://tobyschrapel.com/2017/05/deploying-sage-9-blade-templates-to-wp-engine-using-gitlab-ci-pipelines/

Yeap. This is what I have at the moment.

bitbucket-pipelines.yml

# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
#
# Deployment Guide - https://documentation.codeship.com/basic/continuous-deployment/deployment-with-ftp-sftp-scp/
#
image: kkarczmarczyk/node-yarn:latest

pipelines:
  default:
    - step:
        script:
          - npm install
          - npm test
          - yarn
          - yarn build:production # Ensures we have the right dependencies in main.scss etc

  branches:
    production:
      - step:
          script:
          - npm install
          - npm test
          - yarn
          - yarn build:production
          - ls
          - ssh $USER@$HOST 'sh /home/bitnami/backups/Backup-Site.sh' 'BitBucket-Deployment'
          - scp -rp * $USER@$HOST:/opt/bitnami/apache2/htdocs/site/wp-content/themes/sage9

A couple of things to note:
$USER and $HOST are environment variables configured in Bitbucket Pipeline > Settings.

You will need to configure the project with SSH

  • ssh $USER@$HOST ‘sh /home/bitnami/backups/Backup-Site.sh’ ‘BitBucket-Deployment’

Is run the backup script on the server.

Thank you very much for your example.

Could you please clarify some things:

  1. I can’t see here composer install in your code, why?
  2. Also as I can see you’re copying the whole project/theme folder, without excluding any dev directories, could you please let me know why, and how do you handle this, for example there are some folders that Node uses, etc…

Thank you in advance.

1 Like

1. I can’t see here composer install in your code, why?

My project didn’t need it.

2. Also as I can see you’re copying the whole project/theme folder, without excluding any dev directories, could you please let me know why, and how do you handle this, for example there are some folders that Node uses, etc…

You will need to use rsync instead of scp because rsync has the exclude option. I have tested this, but it will be something like the following.

Replace this line
- scp -rp * $USER@$HOST:/opt/bitnami/apache2/htdocs/site/wp-content/themes/sage9

With
- rsync -avz ssh --exclude ".git" --exclude "node_modules" * $USER@HOST:/path/to/site

I get this error cjpeg: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory

Just a bump: was wondering if any of you perhaps perfected Bitbucket CI/CD procedure for Roots/Bedrock/Sage projects? Wanna improve my deployment procedures (currently using custom bash script -.-) and wouldn’t wanna spend days just trying this stuff if there are perhaps limitations / issues someone already ran into. Any info appreciated. Thanks!

Another bump for this.

I would be very keen to know how to do this with a bedrock and sage setup deploying using pipelines.

I feel like @BeyondLimts99 had it close but since sage dev files are gitignored for deployment might it be better just to deploy the dist/ folder…


- scp -rp * $USER@$HOST:/opt/bitnami/apache2/htdocs/site/wp-content/themes/sage9/dist

as I say I’m new to pipelines and Sage for that matter so I might be competely wrong.

I am confused as to why there wasn’t a composer install too though as you said you didn’t need it but both Bedrock and Sage require a composer install?

Hey, Im using Gitlab and wrote my own approach here, perhaps its useful.

It does run composer install twice as expected, but also does stuff on the server, like cleaning up files and copying over files from the existing folder you are deploying to (keeping uploads folder etc.).

Its best if you 1st create a folder with just .env file in it, and then try the deploy. Or you could first try the bash script approach to see if it works for you, then move on to CD approach via pipelines

I wrote an article on this a while back.
Note: the article is meant for Sage 10, to use with Sage 9, you’ll need to change public to dist in bitbucket-pipelines.yml

The trickiest part for me was the SSH. Lemme know if you faced any issues after following the article.

1 Like