· devops automation werker hugo

Automating Hugo deployments with Werker and Github.

I will assume you have a Github account, so the first step is to create a Werker account, I use my Github account to sign up with, I would recommend the same. Go here to grab an account. We want to be able to deploy Hugo as root, so its done correctly, and to be able to restart Nginx once complete.

So log into your webserver, where the site lives, and create a new user, this example is creating deployer as the user. The password is passed to the passwd command using stdin, I would suggest changing the password.

useradd deployer
echo YourS3curePAssw0rdisSUPERsecure | passwd deployer --stdin

Next create a file inside /etc/sudoers.d/ the name doesn’t matter but I suggest the username.

deployer   ALL=NOPASSWD: /usr/sbin/service nginx restart, /usr/bin/hugo

Now we’ll put the wercker.yaml file into the Github project. This page was super long with all the files, so grab this file here on Github.

Next up, go back to Werker and link your Github account, you can do this by going to your profile settings, and then “Git connections”, click on ‘Connect’ for Github, and follow those steps.

Adding you Project to Werker

Click on ‘Create’ at the top, then on ‘Applications’. Search for you repo once the list has been populated, then click in and then ‘Use Selected Repo’

The next step is entirely dependant on how you have your repo set, and its privacy settings, for most people, the below should do. The final part is whether to make your app public, this is 100% your choice, and there are no implications either way.

Setting up access

The next step is to Generate an SSH Key, and create an environmental variable for that key. The variables are used in the werker.yaml file, so ensure they are made, and spelt correctly. You can generated the SSH Key by going to your app, then its settings (Top right side), the image below should provide further clarification.

Once you are the app settings, click ‘SSH Keys’ on the left side, then ‘Generate new key pair’, give it a name, my is prod. The result should look like the image below.

Next click ‘Environmental variable’ on the left menu, and create and SSH key variable, this is used in the werker.yaml script.

The Wrap Up

The werker.yaml will need editing, you will need to change at least the ‘hostname’, ‘fingerprint’, and SSH user on the deplay steps. Most of the file is self explantory, and should be fairly easy to follow. Here is my Github repo so you can compare.

Pro tip: Manually deplay Hugo on your site first, and ensure that the folder ‘public’ that Hugo generates is owned the user we created before, otherwise you will get ‘Permission Denied’ errors.

I will have alomst certainly forgotten to add something, please let me know if have run into any issues, or spot a mistake in this post.

  • LinkedIn
  • Tumblr
  • Reddit