Deploying Hugo sites - rclone to the rescue?!

Mon, Feb 7, 2022 3-minute read

I’ve posted earlier in this series my thoughts and experiences of migrating a Wordpress blog over to Hugo. So far I have not been too favourable although the majority of that is down to the muscle-memory invested in having a browser-based CMS publishing platform and the many conveniences that provides you.

One of the major teething issues I was having was with the literal publishing process of new content. For a brand new site - it’s pretty simple, you create your output and then just SFTP the whole dang lot up to your webhost.

Or if you happen to be using one of the major supported configurations - basically any of the big cloud providers or any of the static webhosts or major source control repositories, again this scenario is fairly well supported.

But what if you are using a ‘traditional’ webhost and your deployment method is just SFTP? For the initial deploy this is OK; but given the nature of a static site and how many files are created or modified by publishing a new page, incrementally deploying is not completely straight-forward. Hugo creates SEO friendly URLs by creating literal folders for the intended path, as well as all the additional index pages to go with categories, tags and navigation / pagination. So publishing one new article could lead to the generation of many actual files and folders, and because of this is, it’s not necessarily foolproof or simple to identify all the pages or resources that have changed and which require uploading to the host.

One option - and I’m not sure if this is just the preferred default - is to just upload everything every time. This would work. But it’s incredibly inefficient and in the case of a reasonably-sized blog is far too time consuming. One of the main reasons for moving off Wordpress was that it had become incredibly bloated which meant that using the publishing side of things was quite slow - especially to e.g. preview new a new post before publishing - but we’re onyly talking about 10s of seconds… so compared with 10s of minutes to upload your whole site to publish a new post, it is not even comparable.

Fortunately, there are potentially alternatives - assuming of course you can get SSH access to your host environment, which is a far from a given. My host is friendly and this was easy to enable. If you can’t get SSH then you may need to consider one of the more supported environments.

But with SSH then deployment with rsync or rclone becomes viable. Both of them are SSH based synchronisation and the Hugo site has a page about deploying with rsync. Particularly need is the one-line option:

hugo && rsync -avz --delete public/ www-data@ftp.topologix.fr:~/www/

I have been experimenting with rclone. Mainly because it is on the Hugo forums as an option and a PR on the docs. If you want to know the difference between rclone and rsync, here’s a nice explanation.

It’s very easy to get going (macOS):

brew update
brew install rclone

then to configure use the wizard:

rclone config

and then after that

hugo
rclone sync --interactive public/ {whateveryoucalledyoursite}]:{thelocationtocloneto}/

you can also snappily chain the commands with

hugo && rclone sync --interactive public/ {whateveryoucalledyoursite}]:{thelocationtocloneto}/

for a 1-line deploy. –interactive can get a bit naggy but it does otherwise work; and in my testing after the first couple of passes was acceptably faster to make publishing less of a pain. (Which I’m about to hopefully prove with the publishing of this…!)

Hope it helps!

Posts in this Series