HUGO

"Best" way to deploy from GitHub repo to a VPS? (not using S3, GitHub pages, Netlify, etc...)

I have my site almost done and it’s working great on the DEV URL. Currently, my workflow is:

  1. Write on my local machine
  2. run hugo
  3. create zip of public directory
  4. SFTP to webserver, unzip, etc…

I have a VPS I host other things on, and would like to host my site on the same server. I have my Hugo source checked into GitHub. Is there a way to automatically rebuild/refresh my site (on the VPS) on every commit to master (on GitHub)?

So far, my ideas are:

  • Run hugo locally, push rendered HTML to separate repo. Use GitHub to trigger webhook to Caddy server (example here).
  • Run hugo locally, push rendered HTML to separate repo. Create cronjob on server to run git pull every X hours.
  • Run a webhook server on the VPS. Use GitHub to trigger webhook to run custom script that runs git pull && hugo on the server (example here).

So far, I think the third option is the best. I’d be open to any ideas. Thanks!

Another very simple way is to use Rsync on the /public/ repo.

I considered that, but would really prefer to push from GitHub itself to the VPS. This will be my fallback option.

You can try GitHub actions with Hugo setup · Actions · GitHub Marketplace · GitHub plus e.g. Action - rsync · Actions · GitHub Marketplace · GitHub

This is exactly what I do, with rsync and Github actions . Have a look at my github actions e.g. here:

How do you get your webserver to restart after the files are uploaded? I can get the files to the server successfully, but Nginx doesn’t see them until I manually restart the server.

I got it working, thanks @martignoni !

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.