[OCaml] High Intensity Training Online
1
#!
2
#
3
# hito post-receive hook. Runs as the git user after every push to the bare
4
# repo. The git user owns the bare repo and /srv/hito (except data/, which
5
# belongs to the hito runtime user), so this
6
# hook builds and publishes directly, with no privilege hop. The only
7
# privileged action is restarting the service, through one scoped sudoers rule.
8
#
9
# For an accepted push to master: check out the verified revision into a fresh
10
# timestamped release, build it against the shared opam switch, flip
11
# /srv/hito/current, restart the service, and confirm it answers HTTP. The
12
# pre-receive hook rejects a failed master verification. Any build failure
13
# leaves the live release untouched. A failed health check restores the
14
# previous release.
15
#
16
# Style: Google Shell Style Guide.
17
18
set-euopipefail
19
20
readonlyDEPLOY_BRANCH="master"
21
readonlySRV="/srv/hito"
22
readonlyBARE="/srv/git/hito.git"
23
readonlySHARED="${SRV}/shared"
24
readonlyRELEASES="${SRV}/releases"
25
readonlyKEEP=5
26
readonlyHEALTH_URL="http://127.0.0.1:8080/login"
27
readonlyHEALTH_TRIES=10
28
readonlyHEALTH_DELAY=1
29
30
exportOPAMROOT="/srv/git/.opam"
31
exportOPAMSWITCH="${SHARED}"
32
33
err(){
34
printf'
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
88
89
90
91
'
92
93
'
94
95
96
''
97
98
99
''
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168