summaryrefslogtreecommitdiff
path: root/provider/posts/blog/git-deploy.md
blob: 443f8d8f5e30e30b20d40a85e9553e270a4ce3cd (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: dirty-haskell.org´s git-based publication system
published: 2016-12-08
tags: Blog Software
---

Initially I set up dirty-haskell.org (which is currently powered by [hakyll])
to [rsync] the results of compiling up onto my server whenever I intone
`dirty-haskell deploy`{.sh}.

In my ever continuing quest to have my life consist mostly of an array of git
repositories however this didn't seem satisfactory.
Therefore I configured my [gitolite] instance to automatically compile und
publish the current git version whenever I push to `master`.

Gitolite provides us with facilities to install [githooks]. Publishing will be
handled by `post-update`:

~~~{.sh}
#!/usr/bin/env zsh


touchedMaster=false

for ref ($@); do
    [[ ${ref} =~ .*/master$ ]] || continue

    touchedMaster=true
    break
done

$touchedMaster || exit 0

{
    checkoutDir=/srv/git/checkouts/$(basename $(pwd))

    print ${checkoutDir}

    mkdir -p $(dirname ${checkoutDir})

    unset GIT_DIR

    if [[ -d ${checkoutDir} ]]; then
        git -C ${checkoutDir} fetch origin
    else
        rm -rf ${checkoutDir}
        git clone --depth 1 file://$(pwd) ${checkoutDir}
    fi

    git -C ${checkoutDir} checkout -f origin/master

    {
        umask 0022
        cd ${checkoutDir}

        script=$(mktemp)
        delScript() {
            rm -v ${script}
        }
        trap delScript EXIT
        chmod +x ${script}

        >${script} <<EOF
#! /usr/bin/env nix-shell
#! nix-shell -i sh ${checkoutDir}/shell.nix

dirty-haskell build && dirty-haskell deploy
EOF
        
        ${script}
    }
} 2>&1 | stdbuf -o 0 tr '\r' '\n' | logger --id=$$ -p daemon.info -t dirty-haskell
~~~

The script checks if the master branch was moved to a new commit or otherwise
touched and, if so, clones a copy of the repo to a temporary directory and runs
hakyll´s deploy command in it, which is set to rsync the compiled version to a
folder where it´ll be picked up by nginx.

## Update ##

It works.

[hakyll]: https://jaspervdj.be/hakyll/
[rsync]: https://git.samba.org/rsync.git
[gitolite]: http://gitolite.com
[githooks]: http://githooks.com