Deploying bedrock & sage project to server using DeployHQ - is this possible?

I’ve successfully deployed sage theme to 3 sites on the same shared host server using deployHQ. For my next project, I decided to use bedrock too.

I’ve created the bedrock file system on the live site and used .htaccess to make the document root the bedrock/web folder and WordPress is loading ok.

I’ve got the local version up and running with sage, so now I’m trying to get the deployment working but running into difficulties. My repo is the parent folder of bedrock. I’ve used the option in deployHQ to add the server appropriate .env file to the “config files” options.

My build pipeline looks like this:

cd bedrock
composer install --no-progress
---
cd bedrock/web/app/themes/mytheme
composer install --no-progress
---
cd bedrock/web/app/themes/mytheme
yarn
yarn run build:production

This fails at the yarn build command with the following message:

Running Yarn Build [cd bedrock/web/app/themes/castletowndistillery yarn yarn run build:production]

yarn install v1.22.4
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
info fsevents@2.3.2: The platform "linux" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
warning " > autoprefixer@10.4.0" has unmet peer dependency "postcss@^8.1.0".
warning " > eslint-loader@4.0.2" has incorrect peer dependency "eslint@^6.0.0 || ^7.0.0".
warning " > eslint-loader@4.0.2" has incorrect peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > file-loader@6.2.0" has incorrect peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > postcss-loader@4.3.0" has incorrect peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > postcss-loader@4.3.0" has unmet peer dependency "postcss@^7.0.0 || ^8.0.1".
warning " > sass-loader@6.0.7" has incorrect peer dependency "node-sass@^4.0.0".
warning " > stylelint-webpack-plugin@0.10.5" has incorrect peer dependency "stylelint@^8.0.0".
warning " > stylelint-webpack-plugin@0.10.5" has incorrect peer dependency "webpack@^1.13.2 || ^2.7.0 || ^3.11.0 || ^4.4.0".
warning " > url-loader@4.1.1" has incorrect peer dependency "webpack@^4.0.0 || ^5.0.0".
[5/5] Building fresh packages...
error /data/bedrock/web/app/themes/castletowndistillery/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments: 
Directory: /data/bedrock/web/app/themes/castletowndistillery/node_modules/node-sass
Output:
Building: /opt/nodejs/16/bin/node /data/bedrock/web/app/themes/castletowndistillery/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
.
.
gyp ERR! not ok 
Build failed with error code: 1
yarn run v1.22.4
$ webpack --env.production --progress --config resources/assets/build/webpack.config.js
 94% asset optimization ERROR  Failed to compile with 2 errors12:56:46 PM

 error  in ./resources/assets/styles/main.scss

Module build failed: ModuleBuildError: Module build failed: Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (93)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v5.0.0
    at module.exports (/data/bedrock/web/app/themes/castletowndistillery/node_modules/node-sass/lib/binding.js:13:13)
    at Object.<anonymous> (/data/bedrock/web/app/themes/castletowndistillery/node_modules/node-sass/lib/index.js:13:35)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)
    at Object.<anonymous> (/data/bedrock/web/app/themes/castletowndistillery/node_modules/sass-loader/lib/loader.js:3:14)

 @ multi ./scripts/main.js ./styles/main.scss

 error  in ./resources/assets/styles/main.scss

Module build failed: ModuleBuildError: Module build failed: Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (93)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v5.0.0
    at module.exports (/data/bedrock/web/app/themes/castletowndistillery/node_modules/node-sass/lib/binding.js:13:13)
 .
.
.
    at FSReqCallback.readFileAfterOpen [as oncompl 2 assets
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
An error occurred executing Yarn Build [Exit code: 2]

Is what I’m attempting even possible?

If not what do you recommend to deploy? I looked at the recommendation of capistrano but in the help file it says

Warning - The topics and tools in this screencast won’t work unless you’re deploying to a *nix based server that you have SSH and root access to. Don’t expect to be able to use Capistrano to deploy to a shared host or a Windows server.

…and my server runs on Litespeed so I don’t think this is suitable for me. Also I’m paid up now to DeployHQ and would much prefer to use it for simplicity if its possible.

DeployHQ help seems to suggest my server has the wrong versions of various dependencies but since I never ran into any of those issues when deploying Sage via DeploHQ I wonder if this is more to do with the bedrock setup or something not working there? ANy advice much appreciated!

It’s failing trying to build node-sass because that environment doesn’t support it. If you can switch to Dart sass (the sass package) you’ll resolve that error.

If node-sass is the problem, this isn’t bedrock related.

Thank you! So you’re saying it is feasible but I have to update the sass package?

A bit of a noob to all of this so would be grateful if you could possibly help me understand how to do that? Do I just open the server with the terminal and try and install it via the command line there? Or do I just change the package.json file removing this line "node-sass": "^5.0.0", and replacing it with "dart-sass": ???.

I’m just not sure why I don’t run into the same difficulties when just using the sage theme?

You would need to start by changing the node-sass package in your package.json to sass. I don’t know the details of your project but if you have an older version of sass-loader (I think) and are on an older version of node it’ll still try and install node-sass as a required dependency so you may need to update those.

I’m just on the standard sage 9 install with no amendments. Here are the node-sass and sass dependencies:

 "node-sass": "^5.0.0",
 "sass-loader": "~6.0",

I changed it to

 "sass": "^1.0.0",
 "sass-loader": "~6.0",

It builds locally but not on deployHQ. The error window has much less content in it so I reckon something has changed but not sure again where to go from here. It seems it is now looking for node-sass.

 error  in ./resources/assets/styles/main.scss

Module build failed: ModuleBuildError: Module build failed: Error: Cannot find module 'node-sass'

 @ multi ./scripts/main.js ./styles/main.scss

 error  in ./resources/assets/styles/main.scss

Module build failed: ModuleBuildError: Module build failed: Error: Cannot find module 'node-sass'

if you have an older version of sass-loader (I think) and are on an older version of node it’ll still try and install node-sass as a required dependency so you may need to update those.

Where would they be? There aren’t any dependencies in the package.json so is there somewhere else I should look? And how do I change this?

  "dependencies": {
    "jquery": "^3.3.1",
    "purecss": "^2.0.6"
  }

Playing with different version numbers for sass-loader as I think that’s what you meant? But just getting a variety of different errors now. Searching for the errors is leading me nowhere understandable.

Time to just forget Bedrock?

The workflow on other projects without bedrock is working, so I’ve tried copying over the package.json file in the theme from one of the working projects. The shared server has exactly the same settings/ versions etc. But still failing at the same spot.

Bedrock doesn’t have anything to do with node, yarn, npm, etc: it only deals with loading PHP dependencies and and managing the PHP parts of your site. It shouldn’t have any effect on how the theme build process runs.

Your original problem with node-sass looked like it was running into a problem when trying to install, where it was failing it build the ruby stuff it needs in order to create the connection between node and ruby sass. Dart sass doesn’t have this problem because it compiles to pure JavaScript, which is why I suggested it.

I don’t know how DeployHQ functions (I’ve never used it) but it looks like it allows you to run build commands in an environment it spins up for your deploy: Build Pipelines - DeployHQ Is that what you’re doing? Or are you trying to run these commands on your production server, in place? We recommend running the build commands in a separate environment and then uploading the build artifacts to the remote server—the build process isn’t meant to be run on a publicly accessible server and doing so can involve some security risks. This is how Trellis does it: trellis/build-before.yml at master · roots/trellis · GitHub

If your build environment is throwing errors you aren’t seeing in your development environment, I would start by looking at how those environments differ and trying to bring them into parity. Also check and see if your build environment uses any sort of caching (most do) and how that caching is cleared: you may be changing your dependencies but those changes are ignored in favor of a cache.

1 Like

As for whether or not you should push forward with Bedrock: In my personal opinion bedrock is very worth it if you are developing and managing WordPress sites for clients. One of the biggest benefits is the ability to strictly control plug-in versions and prevent clients from messing them up. If you deliver sites to clients and then don’t work on the site again, bedrock’s helpfulness to you will be limited or negative.

If you haven’t already, I’d recommend reading our “12-Factor App” piece: Twelve-Factor WordPress App | Roots It’s a bit old at this point, but still extremely relevant and it explains a lot of the reasoning behind why Roots products work the way they do, why that’s good, and how it can be useful to you (or not).

1 Like

Thank you! I was using Deploy HQ build pipeline but thought that DeployHQ was building on my server.
I didn’t realise it was doing this on its own server before deploying. I have changed the node version used on DeployHQ in the build section and this has allowed it to deploy to the server. That’s great to clear up my understanding there.

Unfortunately, it seems like some folders are missing in the theme directory “app, config, dist, resources & vendor”. On github I can see the app folder is there in my repo so not sure why this wouldn’t copy up?

I copied all those manually and now the theme is loading, however, I’ve updated /resources/views/page.blade.php and redeployed and those changes have not been updated on the live site.

This sounds like something that’s part of how DeployHQ’s deployment works, which I can’t help you with. app, config, and resources should be committed to your repo. dist is generated by the js/css build process and should be deployed but not committed to your repo. vendor is where Composer installs its dependencies, and should be deployed by not committed.

I don’t know deployHQ’s internals, but if it has some kind of system that parses .gitignore files and doesn’t deploy items that match there, it could be causing problems for you.

Thanks, just odd I haven’t encountered any of this on my previous sage deployments but you’ve given me a great place to start looking!

Thank you so much for your help - all working now and can’t wait to get to the actual build in the news year!