Let me just start by saying that Build 2020 was awesome!!
There was a lot of great content going around for everyone, but as I was watching the “From code to scale! Build a static web app in minutes” session showing how easy it is to use Azure Static Web Apps, I couldn’t help but to try that for my own with this website!
My first attempt was to run through the “Tutorial: Publish a Gatsby site to Azure Static Web Apps Preview”, and in the end I was happy to see it created the Azure resources and the a new Github workflow showed up on my repository.
On close analysis of the workflow, I can see there’s a new
Azure/static-web-apps-deploy action in use doing all the heavy lifting! Internally, this action is using Oryx build system to identify the type of source code in the repo and compile it.
Once the workflow started and got to the
Azure/static-web-apps-deploy action, I quickly came to realize that it wasn’t happy with the fact that my “package.json” file had
"yarn": ">=1.22" on the
"engines" node… the build image only had yarn 1.17 and so the build failed:
error email@example.com: The engine "yarn" is incompatible with this module. Expected version ">=1.22". Got "1.17.3"error Found incompatible module.
At this point I edited my “package.json” file, lowered the yarn version requirement to “1.17”, and moved forward.
As expected, pushing this change caused a new workflow to start, but again, this failed:
error Processing /bin/staticsites/ss-oryx/app-int/content/assets/logo.jpg failedOriginal error:/bin/staticsites/ss-oryx/app-int/node_modules/cwebp-bin/vendor/cwebp: **error while loading shared libraries: libGL.so.1: cannot open shared object file: No such file or directory**
This time, the problem was a lot more complicated to fix: the libGL.so.1 library required by Gatsby to process the images was missing from the Oryx docker image!
At this stage I actually thought giving up and went to Twitter to somehow vent my frustration on what I just experienced:
I tried this yesterday with my own GatsbyJs website and unfortunately it failed... First it was Yarn version (had to lower my requirement), but once I fixed that it failed on some native component when processing the images. https://t.co/rnYuwtmYyj— Pedro Lamas (@pedrolamas) May 21, 2020
After some messages exchanged, I followed up on a tip from Annaji Sharma Ganti to compile the source code before the
Azure/static-web-apps-deploy action, and make the action point to the compiled static folder (the “public” folder in my case) - this way Orix would just skip the compilation bit and go directly to publishing the artifacts to Azure.
You can see here my changes to the workflow.
Finally, the workflow worked as expected and I could see my static GatsbyJs site hosted as an Azure Static Web App!
I then made a few more changes (like ensuring that GitHub would checkout the submodule with the website images and fixed some missing environment variables), added a custom domain, waited a few minutes for it to generate a valid SSL certificate, and… we are done!!
Took a bit more of effort than I initially expected, but I’m very happy and very impressed with the result!
The Azure Static Web Apps is currently in “preview” so be aware that changes and improvements will happen before it is ready for production - in the meantime, go and try it out for free!