Browse Source

new entry about hugo + drone and copyright year update

Lennart Weller 2 years ago
parent
commit
e9f1215eb1
3 changed files with 92 additions and 2 deletions
  1. 1
    1
      config.toml
  2. 90
    0
      content/hugo-automatic-deploy.md
  3. 1
    1
      content/new-blog-software-again.md

+ 1
- 1
config.toml View File

@@ -14,4 +14,4 @@ theme = "ring0"
14 14
 
15 15
 [params]
16 16
 	description = "ring0"
17
-	copyright = "Copyright © 2015 ring0"
17
+	copyright = "Copyright © 2016 ring0"

+ 90
- 0
content/hugo-automatic-deploy.md View File

@@ -0,0 +1,90 @@
1
++++
2
+authors = "lhw"
3
+date = "2016-01-27T13:25:20+01:00"
4
+tags = ["hugo", "drone", "ci"]
5
+title = "Automatic deployment of hugo sites"
6
++++
7
+Something I wanted to try out since I set up the blog as hugo static site was
8
+the automatic testing and deployment straight from the git to our webserver. As
9
+we are not using any of the common hosts for static sites, because why would we
10
+when we have a server at our disposal, it was a bit more interesting to find
11
+a cool solution without using third-party services.
12
+
13
+Our current setup is a VPS running a nginx and a docker environment for
14
+everything we don't quite trust and or want to run on bare metal.
15
+Two of those docker containers are [Gogs](https://gogs.io) and
16
+[Drone CI](https://drone.io), which work miraculously
17
+well together.
18
+<!--more-->
19
+
20
+The later has quite the list of possible deploy/publish plugins including
21
+`scp`, `sftp` and `rsync`. I chose the `rsync` plugin  which I set up with the
22
+`rssh` shell on the server side. But the other two are also valid choices for
23
+this task but they do require direct config entries in the `sshd_config` to
24
+restrict user access.
25
+
26
+The drone configuration lives in the root of the hugo-site git in the
27
+`.drone.yml` file and would look something like this:
28
+{{< highlight yaml >}}
29
+build:
30
+  image: r0/hugo
31
+  commands:
32
+    - hugo
33
+
34
+publish:
35
+  rsync:
36
+    host: ring0.de
37
+    user: hugo-deploy
38
+    source: public/
39
+    target: /blog
40
+    delete: true
41
+    recursive: true
42
+{{< /highlight >}}
43
+
44
+drone.io internally uses docker containers for basically everything, which means
45
+images, plugins and so on are not limited to some predermined ones but can be
46
+basically anything. I am using a custom builder instance for hugo and an
47
+official drone publisher instance with `drone-rsync`. As not to rebuild the
48
+builder instance every time I made a small debian/testing based image which has
49
+the hugo binary preinstalled.
50
+
51
+The Dockerfile for creating the builder image is very simple and results in a
52
+quite small image:
53
+{{< highlight docker >}}
54
+#docker build --tag=r0/hugo builderfile
55
+FROM debian:stretch
56
+RUN apt-get update && apt-get -y install hugo python-pygments
57
+RUN rm -rf /var/lib/apt/lists/\*
58
+{{< /highlight >}}
59
+
60
+On the server side I installed rssh via the usual channels then added a user for
61
+the upload:
62
+
63
+{{< highlight shell>}}
64
+adduser --system --group blog --home /var/lib/hugo --shell /usr/bin/rssh hugo-deploy
65
+{{< /highlight >}}
66
+
67
+The rssh is configured by adding a single line to the bottom of `/etc/rssh.conf`
68
+
69
+{{< highlight properties >}}
70
+user=hugo-deploy:002:100000:/var/lib/hugo
71
+{{< /highlight >}}
72
+
73
+The format for this line is not quite obvious but it is somewhat explained by
74
+the example lines: `user=<user>:<umask>:<action bitfield>:<chroot>`.
75
+And because it is a real chroot it needs a bit of a setup before you can use it.
76
+rssh comes with a script which adds all the necessary files to the user chroot
77
+for the programs you need.
78
+As rsync is not added by default I
79
+[patched](https://git.ring0.de/ring0/microblog/src/master/extras/mkchroot.diff)
80
+the script up little to also copy rsync. 
81
+
82
+Then execute the script, copying all the necessary files 
83
+(`mkchroot.sh /var/lib/hugo`) and create a directory within the chroot with
84
+write permissions for the deploy user.
85
+
86
+Set up your nginx to serve the deploy user directory and tell drone to hook into
87
+the Gogs repository and you are done. Every push to the repo should now be
88
+automatically build, tested and then deployed to the server. In case you want to
89
+commit something without it being deployed you can simply add a `[ci skip]` to
90
+the commit message.

+ 1
- 1
content/new-blog-software-again.md View File

@@ -1,7 +1,7 @@
1 1
 +++
2 2
 authors = "lhw"
3 3
 date = "2015-12-29T12:53:15+01:00"
4
-tags = ["ring0", "blog"]
4
+tags = ["ring0", "blog", "hugo"]
5 5
 title = "new blog software ... again"
6 6
 +++
7 7
 

Loading…
Cancel
Save