blob: cff307ef89c7c41a6884622efd9729edf9cbfe91 [file] [log] [blame]
Radek Pietruszewskif5844312023-10-27 22:41:18 +02001local kube = import "../../../kube/hscloud.libsonnet";
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +02002
3{
radexc995c212023-11-24 12:01:49 +01004 local top = self,
5 local cfg = top.cfg,
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +02006
7 cfg:: {
8 namespace: error "namespace must be set",
9 appName: "gerrit",
10 prefix: "", # if set, should be 'foo-'
11 domain: error "domain must be set",
12 identity: error "identity (UUID) must be set",
13
14 // The secret must contain a key named 'secure.config' containing (at least):
15 // [auth]
16 // registerEmailPrivateKey = <random>
17 // [plugin "gerrit-oauth-provider-warsawhackerspace-oauth"]
18 // client-id = foo
19 // client-secret = bar
20 // [sendemail]
21 // smtpPass = foo
22 // [receiveemail]
23 // password = bar
24 secureSecret: error "secure secret name must be set",
25
26 storageClass: error "storage class must be set",
27 storageSize: {
28 git: "50Gi", // Main storage for repositories and NoteDB.
29 index: "10Gi", // Secondary Lucene index
30 cache: "10Gi", // H2 cache databases
31 db: "1Gi", // NoteDB is used, so database is basically empty (H2 accountPatchReviewDatabase)
32 etc: "1Gi", // Random site stuff.
33 },
34
35 email: {
36 server: "mail.hackerspace.pl",
37 username: "gerrit",
38 address: "gerrit@hackerspace.pl",
39 },
40
Serge Bazanski7f5f2092023-10-08 14:01:04 +000041 tag: "3.7.5-r7",
Serge Bazanskiee2f8a32020-12-17 23:06:10 +010042 image: "registry.k0.hswaw.net/q3k/gerrit:" + cfg.tag,
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +020043 resources: {
44 requests: {
45 cpu: "100m",
46 memory: "500Mi",
47 },
48 limits: {
49 cpu: "1",
50 memory: "2Gi",
51 },
52 },
53 },
54
55 name(suffix):: cfg.prefix + suffix,
56
57 metadata(component):: {
58 namespace: cfg.namespace,
59 labels: {
60 "app.kubernetes.io/name": cfg.appName,
61 "app.kubernetes.io/managed-by": "kubecfg",
62 "app.kubernetes.io/component": "component",
63 },
64 },
65
radexc995c212023-11-24 12:01:49 +010066 configmap: kube.ConfigMap(top.name("gerrit")) {
67 metadata+: top.metadata("configmap"),
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +020068 data: {
69 "gerrit.config": |||
70 [gerrit]
71 basePath = git
72 canonicalWebUrl = https://%(domain)s/
73 serverId = %(identity)s
Serge Bazanskic9f48fe2021-02-08 00:44:56 +010074 reportBugUrl = https://b.hackerspace.pl/new
Serge Bazanskic68343c2023-10-08 12:58:05 +000075 primaryWeblinkName = Forgejo
Serge Bazanskic9f48fe2021-02-08 00:44:56 +010076
77 [commentlink "b"]
78 match = [Bb]/(\\d+)
79 link = https://b.hackerspace.pl/$1
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +020080
Serge Bazanskic68343c2023-10-08 12:58:05 +000081 [gitweb]
82 url = https://git.hackerspace.pl/
83 type = custom
84 revision = hswaw/${project}/commit/${commit}
85 project = hswaw/${project}
86 branch = hswaw/${project}/src/branch/${branch}
87 tag = hswaw/${project}/releases/tag/${tag}
88 roottree = hswaw/${project}/src/commit/${commit}
89 file = hswaw/${project}/src/commit/${hash}/${file}
90 filehistory = hswaw/${project}/commits/branch/${branch}/${file}
91 linkname = Forgejo
92
Sergiusz Bazanski9b5359d2019-07-20 17:20:53 +020093 [sshd]
94 advertisedAddress = %(domain)s
95
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +020096 [container]
97 javaOptions = -Djava.security.edg=file:/dev/./urandom
98
99 [auth]
100 type = OAUTH
101 gitBasicAuthPolicy = HTTP
102
103 [httpd]
104 listenUrl = proxy-http://*:8080
105
106 [sshd]
107 advertisedAddress = %(domain)s
108
109 [user]
110 email = %(emailAddress)s
111
112 [sendemail]
113 enable = true
114 from = MIXED
115 smtpServer = %(emailServer)s
116 smtpServerPort = 465
117 smtpEncryption = ssl
118 smtpUser = %(emailUser)s
119
120 [receiveemail]
121 protocol = IMAP
122 host = %(emailServer)s
123 username = %(emailUser)s
124 encryption = TLS
125 enableImapIdle = true
126
Serge Bazanski28b52602023-10-27 20:58:45 +0200127 [plugin "avatars-gravatar"]
128 gravatarUrl = https://profile.hackerspace.pl/avatar/
129 changeAvatarUrl = https://profile.hackerspace.pl/vcard
130
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200131 ||| % {
132 domain: cfg.domain,
133 identity: cfg.identity,
134 emailAddress: cfg.email.address,
135 emailServer: cfg.email.server,
136 emailUser: cfg.email.username,
137 },
138 },
139 },
140
141 volumes: {
radexc995c212023-11-24 12:01:49 +0100142 [name]: kube.PersistentVolumeClaim(top.name(name)) {
143 metadata+: top.metadata("storage"),
radex36964dc2023-11-24 11:19:46 +0100144 storage:: cfg.storageSize[name],
145 storageClass:: cfg.storageClassName,
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200146 }
147 for name in ["etc", "git", "index", "cache", "db"]
148 },
149
150 local volumeMounts = {
151 [name]: { mountPath: "/var/gerrit/%s" % name }
152 for name in ["etc", "git", "index", "cache", "db"]
153 } {
154 // ConfigMap gets mounted here
155 config: { mountPath: "/var/gerrit-config" },
156 // SecureSecret gets mounted here
157 secure: { mountPath: "/var/gerrit-secure" },
158 },
radexc995c212023-11-24 12:01:49 +0100159 keys: kube.Secret(top.name("keys")) {
160 metadata+: top.metadata("deployment"),
Serge Bazanski7f5f2092023-10-08 14:01:04 +0000161 //data_: {
162 // FORGEJO_TOKEN: "fill me when deploying, TODO(q3k): god damn secrets",
163 //},
164 },
radexc995c212023-11-24 12:01:49 +0100165 deployment: kube.Deployment(top.name("gerrit")) {
166 metadata+: top.metadata("deployment"),
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200167 spec+: {
168 replicas: 1,
169 template+: {
170 spec+: {
171 securityContext: {
172 fsGroup: 1000, # gerrit uid
173 },
174 volumes_: {
radexc995c212023-11-24 12:01:49 +0100175 config: kube.ConfigMapVolume(top.configmap),
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200176 secure: { secret: { secretName: cfg.secureSecret} },
177 } {
radexc995c212023-11-24 12:01:49 +0100178 [name]: kube.PersistentVolumeClaimVolume(top.volumes[name])
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200179 for name in ["etc", "git", "index", "cache", "db"]
180 },
181 containers_: {
radexc995c212023-11-24 12:01:49 +0100182 gerrit: kube.Container(top.name("gerrit")) {
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200183 image: cfg.image,
184 ports_: {
185 http: { containerPort: 8080 },
186 ssh: { containerPort: 29418 },
187 },
Serge Bazanski7f5f2092023-10-08 14:01:04 +0000188 env_: {
radexc995c212023-11-24 12:01:49 +0100189 FORGEJO_TOKEN: { secretKeyRef: { name: top.keys.metadata.name, key: "FORGEJO_TOKEN" }},
Serge Bazanski7f5f2092023-10-08 14:01:04 +0000190 },
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200191 resources: cfg.resources,
192 volumeMounts_: volumeMounts,
Piotr Dobrowolski69957c32023-09-17 21:43:51 +0200193
194 livenessProbe: {
195 httpGet: {
196 path: "/",
197 port: 8080,
198 },
199 initialDelaySeconds: 60,
200 periodSeconds: 10,
201 },
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200202 },
203 },
204 },
205 },
206 },
207 },
208
radexc995c212023-11-24 12:01:49 +0100209 svc: kube.Service(top.name("gerrit")) {
210 metadata+: top.metadata("service"),
211 target:: top.deployment,
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200212 spec+: {
213 ports: [
214 { name: "http", port: 80, targetPort: 8080, protocol: "TCP" },
215 { name: "ssh", port: 22, targetPort: 29418, protocol: "TCP" },
216 ],
217 type: "ClusterIP",
218 },
219 },
220
radexc995c212023-11-24 12:01:49 +0100221 ingress: kube.SimpleIngress(top.name("gerrit")) {
Radek Pietruszewskif5844312023-10-27 22:41:18 +0200222 hosts:: [cfg.domain],
radexc995c212023-11-24 12:01:49 +0100223 target_service:: top.svc,
224 metadata+: top.metadata("ingress"),
Sergiusz Bazanskia7e26cc2019-06-21 20:38:35 +0200225 },
226}