Automatic Hugo blog deploy with Gitea and Drone

From series: Blogging with hugo

Today I will tell how my blog posts automatically deployed with one only git push command.

Hugo is a generator which build static site from text files. Since everything is text, version control system such as Git is a great choice for data storage.

Using hooks, we can trigger any actions after source code modification. In this case, when we make command git push, changes are pushing to self-hosted source code hosting system, where push web hook executed. This web hook give command to Drone to build the site.

Gitea

On my server I have installed source code hosting system Gitea. Gitea — is lightweight free and open Git service.

Earlier I have an expirience with Gitlab, that was like voracious monster doing to many extra moves. Gitea compared to it is very handy quick tool.

Drone

Drone — free continious delivery system. Drone works flowlessly with Gitea, easy to configure and doens‘t need much of system resources.

To make it work we need to create pipeline file in the root of our repo: .drone.yml. Documentation contains detailed instructions on how to use it.

My configuration for deploying blog on hosting:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
kind: pipeline
type: docker
name: default
platform:
    os: linux
    arch: amd64
steps:
    - name: submodules
      image: alpine/git
      commands:
      - git submodule update --init --recursive

    - name: building
      image: alpine
      environment:
          LANGUAGE: en_US.UTF-8
          LC_ALL: en_US.UTF-8
          KEY_FILE: id_ecdsa
          KEY:
              from_secret: rsync_key
      commands:
          - mkdir ~/.ssh/
          - echo "$KEY" > ~/.ssh/$KEY_FILE
          - chmod 0600 ~/.ssh/$KEY_FILE
          - echo Host <Host IP> >> ~/.ssh/config
          - echo Hostname <Host IP> >> ~/.ssh/config
          - echo StrictHostKeyChecking no >> ~/.ssh/config
          - echo Port <Host Port> >> ~/.ssh/config
          - chmod 0700 ~/.ssh/config
          - apk add --no-cache hugo npm rsync openssh
          - npm install
          - hugo -b https://<Site Base URL>/ -d ./public/ --minify
          - rsync -P -rvzc --include tags --cvs-exclude --delete public/ <Host User>@<Host IP>:<WebServer Directory>

    - name: send telegram notification
      image: appleboy/drone-telegram
      settings:
          token:
              from_secret: telegram_token
          to: 
              from_secret: telegram_room_id
      when:
          status:
              - success
              - failure
trigger:
    branch:
        - master

volumes:
    - name: docker
      host: 
          path: /var/run/docker.sock

There is only one docker pipeline based on alpine.

Series: Blogging with hugo

  1. Implementing «Rich CSS Tooltip» in Hugo
  2. Automatic Hugo blog deploy with Gitea and Drone