Building and Deploying This WebsiteFebruary 15, 2020
For a static website being hosted on a single server instance, your build and deploy pipeline don’t have to be particularly complex. I find the standard Hugo build tools and rsync to be more than enough for a personal site like this one.
First, I make sure that I have an updated build of my site in my workspace.
With Hugo, this isn’t too hard, I just go into the root of my project repository
hugo --gc. The
--gc flag stands for “garbage collection”,
it helps remove the outdated files that occasionally get left behind by
Hugo, and should always be used for a small site.
Any time I come across some kind of bash incantation that I know I won’t remember, I stick it into my bashrc as an alias so I can call upon it later. To deploy this site, I use this alias:
alias sync_website='rsync -avzze ssh --progress --delete ~/workspaces/devinadooley/public/ devinadooley.com:/var/www/devinadooley.com'
If you happen to still be more human than machine, this won’t be very intuitive.
You could get this all from running
man rsync, but I’ll break it down anyway:
alias sync_website: Just the bash alias definition, so that I can deploy from any terminal on my local machine by typing in
-a: Transfer in archive mode. Preserves symbolic links, permissions and so on. Just use it.
-v: Verbose mode. Unless you have an insanely low memory requirement on your machine (you don’t), use it.
-zz: Some kind of new style compression. If you are running Arch, you might have to use
-z. Can’t remember why it breaks, but if
-zdoesn’t work use
-e ssh: Specifies the protocol to use while transferring the files. If you’re like me, you haven’t thought about opening up any ports other than 22, so this will probably be useful.
--progress: Provide status updates on file transfers.
--delete: Delete any files that are not in sync with the directory you are copying from. Only use this if you want to overwrite server files that are no longer in the client’s build directory. In the case of this website, I want the server directory to match my build directory exactly, so this is necessary.
~/workspaces/devinadooley/public/: The directory of the client’s build. The trailing forward-slash is important if you want to copy the files within the directory and not the directory itself.
devinadooley.com:/var/www/devinadooley.com: The server location and directory to copy into, separated by a colon.
Running some version of that command should get your local files onto the server location where you need them. Apologies if you were expecting a more complex deploy system, but in my opinion, any extra tooling for a site like this would be a waste of time – rsync is a perfectly capable tool for a site with a single developer and deploy target. It can be fun to create and configure deployment systems, but it can also be an easy way to waste your time if your objective is to serve static content on the web.