blob: 651bfc402d926bb4109cbb62e2ffb7a950b6a153 [file] [log] [blame]
Sergiusz Bazanski91e1a8c2020-06-25 12:16:29 +02001local mirko = import "../../kube/mirko.libsonnet";
2local kube = import "../../kube/kube.libsonnet";
3
4// Deploy SourceGraph, a code serach tool. Its configuration is fully managed
5// within sourcegraph itself, including user accounts.
6
7{
8 cfg:: {
9 image: "sourcegraph/server:3.17.1",
10 publicFQDN: error "public FQDN must be set",
11 storageClassName: "waw-hdd-redundant-3",
12 },
13
14 component(cfg, env):: mirko.Component(env, "sourcegraph") {
15 local sourcegraph = self,
16 cfg+: {
17 image: cfg.image,
18 volumes+: {
19 data: kube.PersistentVolumeClaimVolume(sourcegraph.pvc.data),
20 etc: kube.PersistentVolumeClaimVolume(sourcegraph.pvc.etc),
21 },
22 securityContext: {
23 runAsUser: 0,
Serge Bazanskib7898a82020-08-23 11:05:27 +000024 fsGroup: 0,
25 },
26 // This container fixes some permissions that Kubernetes volume mounts break.
27 initContainer: sourcegraph.Container("fixperms") {
28 image: "alpine:3",
29 volumeMounts_+: {
30 data: { mountPath: "/var/opt/sourcegraph" },
31 },
32 ports_: {},
33 command: [
34 "sh", "-c",
35 "chmod 755 /var/opt/sourcegraph; chmod -R 700 /var/opt/sourcegraph/postgresql",
36 ],
Sergiusz Bazanski91e1a8c2020-06-25 12:16:29 +020037 },
38 container: sourcegraph.Container("main") {
39 volumeMounts_+: {
40 data: { mountPath: "/var/opt/sourcegraph" },
41 etc: { mountPath: "/etc/sourcegraph" },
42 },
43 resources: {
44 requests: {
45 cpu: "100m",
46 memory: "1Gi",
47 },
48 limits: {
49 cpu: "1",
50 memory: "2Gi",
51 },
52 },
53 },
54 ports+: {
55 publicHTTP: {
56 public: {
57 port: 7080,
58 dns: cfg.publicFQDN,
59 // Authenticate as 'Anonymous' user by default. This is done in tandem
60 // with Sourcegraphs authenticate-by-http-header feature, and is a
61 // workaround for the lack of a public view in the self-hosted free
62 // version of Sourcegraph.
63 // https://twitter.com/sqs/status/1272659451292422144
64 setHeaders: ["X-Forwarded-User Anonymous"],
65 },
66 },
67 },
68 extraPaths: [
69 {
70 // Redirect anonymous user settings to a service that doesn't
71 // have any endpoints/backends.
72 path: "/users/Anonymous/settings",
73 backend: { serviceName: sourcegraph.blocksvc.metadata.name, servicePort: 8080 },
74 },
75 ],
76 },
77
78 blocksvc: kube.Service(sourcegraph.makeName("blocksvc")) {
79 metadata+: sourcegraph.metadata,
80 spec+: {
81 selector: null,
82 ports: [{ port: 2137, targetPort: 2137 }],
83 },
84 },
85
86 pvc: {
87 data: kube.PersistentVolumeClaim(sourcegraph.makeName("data")) {
88 metadata+: sourcegraph.metadata,
radex36964dc2023-11-24 11:19:46 +010089 storage:: "40Gi",
90 storageClass:: cfg.storageClassName,
Sergiusz Bazanski91e1a8c2020-06-25 12:16:29 +020091 },
92 etc: kube.PersistentVolumeClaim(sourcegraph.makeName("etc")) {
93 metadata+: sourcegraph.metadata,
radex36964dc2023-11-24 11:19:46 +010094 storage:: "4Gi",
95 storageClass:: cfg.storageClassName,
Sergiusz Bazanski91e1a8c2020-06-25 12:16:29 +020096 },
97 },
98 }
99}