Tag Website

Deploying Hugo site using Bitbucket pipelines

I have a spare Mac mini running which has all sorts of projects running on it. One of them had a hook into a git repository of a Hugo website which would build it once I committed it to the master and coopy it over to my webserver. It was tedious and sometimes it broke, last week I had enoughof it and looked for a solution that is stable and has less maintenace. The solution I ended up with are the Bitbucket Pipelines

The setup in the end was quite easy, I only had to gather the required examples, configuration and settings from several diffent places. So for prosperity and for other people in the same situation I’m describing my solution here.

First in bitbucket you have to login and go to the repository where you store your Hugo website (source and such) then on the left and bottom go to “Repository settings” in the new itemlist go to the bottom en select “Settings” where you can “Enable Pipelines”.

Then goto “Repository variables” where you can define variables that can be used in your later scripts. I use a variable for the username, server address and the version of Hugo required.

USER    my username on the destination machine
SERVER  name of the destination server.
HUGO_VERION the version of Hugo, in my case 0.108.0

Then goto “SSH Keys” where you generate a keypair and copy the public key for later use. At the bottom add you destination server to the list of “Known hosts”

The public key is something you should add to the destination server. Log in with the user you set in your variable earlier and add the public key to the file ~/.ssh/authorized_keys. This will enable access to the destination server.

The last item is to add the file bitbucket-pipelines to the root of your repository. The content will look like:


image: atlassian/default-image:3

   # run the script for a maximum of 5 minutes
   max-time: 5

      - step:
         name: Build Hugo
            - apt-get update -y && apt-get install wget
            - apt-get -y install git
            - echo Hugo version is $HUGO_VERSION
            - export HUGO_ENV=production
            - wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-amd64.deb
            - dpkg -i hugo*.deb
            - git submodule update --init --remote
            - hugo --minify
            - public/**
      - step:
         name: Deploy artifacts using SCP to PROD
         deployment: production
            - pipe: atlassian/scp-deploy:1.2.1
                USER: $USER
                SERVER: $SERVER
                REMOTE_PATH: '/destination'
                LOCAL_PATH: 'public/*'

That’s it, then commit these files to your repository and things should start moving.

Next evolution of site

It was time to take a fresh look at this blog, the template I used had too many connections to third party components that were capable of tracking you and me. I didn’t like it so I switched to a cleaner setup, edited all the third party content out of it. Hosting the fonts locally and this is the current result, but still not 100% happy with the looks so there might be some tweaks coming along. Also up, automatically deploy when I change anything, because currently it’s a manual task.

Update: I’ve succeeded in getting the automated process running with the help of git hooks, namely post-recieve. After writing or changing content I commit it to my git repository and then push it to my test server in the cloud from which the site is rebuild. From there I can test it and if there aren’t to many blatant spelling mistakes I merge the changes into the master branch and commit and push again. This results in a fresh production rebuild and a copy via scp to the actual web server.