Deploying sage with rsync?

Hi!

I’ve been trying to automatize a deployment workflow for Sage. I got my remote server on Digital Ocean running a regular WordPress install without Trellis nor Bedrock.

What I’ve tried so far is creating a deploy command in a makefile that uses rsync to upload the changes, ssh’s to run yarn run build:production and finally runs wp blade compile to compile the cache. Problem is, I’m trying to run ‘yarn run build:production’ from the makefile too and it just doesn’t work. Yarn throws a ‘Node is required’ error which has to do with the available PATH when commands are ran with SSH in that way (i.e. without loading the interactive shell. Tried -t flag, doesn’t work either). wp blade compile runs okay.

So I wanted to know if someone has a simple deployment workflow for sage that allows to run yarn run build:production or what other deployment scrips/workflows are you guys using to deploy sage without ansible.

1 Like

Why do you have to run yarn remotely? Why not run it locally (or on a CI service) and then rsync the files to your server?

2 Likes

Thanks for replying!
I thought deploying the compiled resources was bad practice but I’m realizing that it isn’t that much… I’m currently excluding the dist/ directory when rsyncing the files. Any gotcha I should be aware of?

So long as you aren’t generating any urls in your assets, you should be fine.

awesome, sounds like a plan. Thanks!

Here’s a sample file I use to deploy everything with bitbucket pipelines.

Create a bitbucket-pipelines.yml in the root project, and activate bitbucket pipelines. You’ll need to make sure all the variables are configured too. Let me know if you have any questions.

# 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: thenatives/ci-php-yarn:1.0

pipelines:
  custom: # Pipelines that are triggered manually
    production-deployment:
      - step:
          deployment: production
          caches:
            - composer
            - node
          script:
            - cd "wp-content/themes/$PROJECT"
            - composer install
            - yarn
            - yarn build:production
            - ssh $USER@$PRODUCTION "/root/Scripts/Backup-MySQL.sh"
            - ssh $USER@$PRODUCTION "/root/Scripts/Backup-Sites.sh"
            - ssh $USER@$PRODUCTION "/root/Scripts/Backup-Migration.sh Deployment"
            - cd "/opt/atlassian/pipelines/agent/build"
            - rsync -avz  --no-perms --no-owner --no-group --exclude-from="wp-content/themes/$PROJECT/resources/assets/build/deployment-ignore-files.txt" -e ssh ./ $USER@$PRODUCTION:/var/www/$PROJECT
            - ssh $USER@$PRODUCTION "chown www-data:www-data -R /var/www/$PROJECT"
            - ssh $USER@$PRODUCTION "chmod 775 /var/www/$PROJECT/wp-content/uploads"

  default:
    - step:
        caches:
          - composer
          - node
        script:
          - cd "wp-content/themes/$PROJECT"
          - yarn
          - yarn build:production # Ensures we have the right dependencies in main.scss etc

  branches:
    master:
      - step:
          deployment: test
          caches:
            - composer
            - node
          script:
            - pwd
            - cd "wp-content/themes/$PROJECT"
            - composer install
            - yarn
            - yarn build
            - cd "/opt/atlassian/pipelines/agent/build"
            - rsync -avz  --no-perms --no-owner --no-group --exclude-from="wp-content/themes/$PROJECT/resources/assets/build/deployment-ignore-files.txt" -e ssh ./ $USER@$STAGING:/var/www/$PROJECT
            - ssh $USER@$STAGING "chown www-data:www-data -R /var/www"
            - ssh $USER@$STAGING "chmod 775 /var/www/$PROJECT/wp-content/uploads"

I am working currently on a dockerized version of wordpress with sage and have been trying (when I get time) to automate my deployments with bitbucket-pipelines. Do you use Docker? If not, would you be willing to work together on automating this? I truly believe docker, wordpress, sage and bitbucket-pipelines (or whatever ci/cd tool) can be used to automate the deployment process with just a git push…

1 Like

Lots of us are already doing this with CircleCI + Docker :slight_smile: Deploys with Trellis + Sage in ~2mins.

I’d be interested in checking out an example :slight_smile:

There’s a few examples you can find by searching this forum :slight_smile: