(or AWS, or Digital Ocean, or...)
If you’ve been following my mumbling on twitter you may already know I have been trying to find a better workflow for my blog. I want something that loads fast for my users, but also something that I do not have to spend a lot of time maintaining.
Static generators like Gatsby, Nextjs, React, Vuejs and the likes are great, but for now I did not want to introduce a lot of complexity while I explore possible solutions. I want an easy workflow that I can jump on easily after a few days (or weeks) without touching the blog and know that it’s simple enough that I won’t have to go through notes to remember how I was deploying this (my attempt at Kubernetes for a personal site, although instructive and fun, it was definitely an overkill).
I did already know the excellent job Mortensen was dedicating to his Tome module, and gave it a few tries before. Where I was a bit stuck and not 100% convinced was with the build process. See how I was doing it.
My old ”build all the things” way
- Build your content locally,
- Push to Netlify ,
- Execute the builds in there:
- composer install && ./vendor/bin/drush tome:install -y && ./vendor/bin/drush tome:static -l $DEPLOY_PRIME_URL
- Your static content is deployed to an html where Netlify will serve it from
This meant that pretty much every small change in my blog, regardless if it was a new post, fixing a typo or adding a new batch of views, was requiring a full build in Netlify. Each build at this point was surpassing already the 30 minutes, and was making Netlify to fail because… well, the free tier does not give you more than those 30 minutes. Fair enough that they even give that for free to be honest.
And, full disclosure, building in the CI is the good practice. It ensure that your site is fully functional and you are not breaking anything.
However, give the limitation on build time, and that this is a personal blog where I should not spend too much time maintaining, I think I found a better way.
My “build on site” new way
Using ddev you can have a machine ready in your repo to pull, make changes and push back to the repo. And when I say DDEV I mean Lando with ADS if you require more complex setup with BLT, DrupalVM, bare metal, … you get the point of choose your own potion.
And actually on my case I have ”bare metal, one extra step in the middle with a dedicated cheap workstation that I acquired a few months back for a 100 pounds. That’s not really needed for this but I’ll talk about that on a future article.
So, coming back to the build, this is my final workflow (drum roll here):
- [OPTIONAL] ddev start, drush uli, etc (if you have the MV or your docker containers stopped)
- Create your content, make changes on your site, etc
- Export it with Tome:
- ddev exec drush tome:export
- ddev exec drush tome:static --uri=http://alexmoreno.net
- Push to Netlify (or aws, digital ocean, bare metal, ...)
Note the uri. Using that you ensure that your local images and files are translated into proper production urls. Given you don’t have a remote server you can’t really play with your settings to differentiate between local and prod, but that’s the uri argument purpose in tome:static.
All you need now is configure your Netlify to:
- Point to your git repository (github, gitlab, bitbucket, …)
- Tell Netlify to build your artefact from the html folder that tome has created
- Enjoy your shiny site in prod.