Continuously Deploy a Hugo blog with GitHub Actions, Docker and a VPS

Disclaimer: In this tutorial I will just explain my solution for a problem that I had. If you have any suggestion feel free to contact me!

In August I decided to create a new blog where I can post some stories about Machine Learning, my idea is to publish these stories in italian (I’m a native speaker) because I believe that for some topics there are not a lot of informations in italian.

To create this blog I had some constraints:

To solve my problem I decided to use Hugo, an open source static site generator, Github Actions and Docker on my VPS.

Let’s see how to generate our Hugo website and continuously deploy it using Github Actions and Docker.

mkdir HugoTest
hugo new site HugoTest
!.gitignore
git init
git add .
git commit -m "First commit"
git remote add origin https://github.com/<USERNAME>/<REPO>.git
git push -u origin master
git clone https://github.com/<USERNAME>/<REPO>.git

PROJECT_PATH

PROJECT_PATH is the path of the repo that you cloned on your VPS, in my case is /home/luca/TestHugo/TestHugo

SERVER_IP

The IP address of your VPS

SERVER_PASSWORD

The vps’s password

SERVER_USERNAME

The username that you use to login to your VPS

TOKEN

The token you generated in the previous step.

git submodule add https://github.com/matsuyoshi30/harbor.git ./themes/harborecho 'theme = "harbor"' >> config.toml
docker-compose up 

If everything is ok you should see something like this:

If you connect to the IP of your VPS using the port 1313 you should also see your newly created blog:

hugo new post/test.md
nano content/post/test.md
docker-compose up -d

Conclusions

That’s all for today, I hope that this tutorial was useful for you, if so, clap your hands!

If you have any suggestions feel free to contact me on Twitter or just leave a comment here.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store