Deploying Hexo with Rsync over SSH on WSL

This is a hexo driven blog. For the last few years, the deployment has been something that has been done in Docker with Gitlab CI integration. However, my Gitlab setup has been having aggravating issues with its base operating system (Catalina…). So in the mean time I had to fall back on something I’ve used since nearly Day 0 in my web development. I remember when I was using FTP in the last 90s to upload content to a website and having read up on Rysnc. It was so different that it felt impossible. However, it has easily become the workhorse tool over the years.

So of course with all the great experiences it makes sense do deploy with Rsync. Hexo provides a plugin architecture that can be used to extend the framework including deployments. Luckily there is already an extension for Rsync deployments so no need to invent some scripts.

With that, defining the _config.yml couldn’t be easier.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
deploy:
type: rsync # This is what we are going to talk about
host: geedew.com # Where to SSH to
user: DEPLOYMENT_USER # This is the user to SSH with
root: PATH_TO_REMOTE_DIRECTORY # This is the path the files are served from
port: 22 # SSL!
# Custom args can be passed
# `--chown` is important. The files need to owned by the users that is hosting them.
# This is the user that owns the HTTP process, the nginx processes in my case.
# `--chmod` is to set the correct permissions. Most importantly removing the
# write permissions that the files do not need to have.
args: --chown=USER:GROUP --chmod=g-w,o-w
# Delete what is existing. I use Git to keep all versions of my files so
# I don't mind it wiping the remote files.
delete: true
verbose: true
ignore_errors: false

So for now, running npm run deploy, like I will do shortly with this post, couldn’t be easier. Note: this assumes you have previously setup some SSH keys to do the logging in.

Resources

  1. Geedew - SSH Remote Keys
  2. Linuxize - Rsync ove SSH
  3. Hexo Deployer Rsync
  4. Cover Image