blob: 9e2454d39ead8a2709fa6ff2045e01f2e237fba1 [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,
24 fsGroup: 70,
25 },
26 container: sourcegraph.Container("main") {
27 volumeMounts_+: {
28 data: { mountPath: "/var/opt/sourcegraph" },
29 etc: { mountPath: "/etc/sourcegraph" },
30 },
31 resources: {
32 requests: {
33 cpu: "100m",
34 memory: "1Gi",
35 },
36 limits: {
37 cpu: "1",
38 memory: "2Gi",
39 },
40 },
41 },
42 ports+: {
43 publicHTTP: {
44 public: {
45 port: 7080,
46 dns: cfg.publicFQDN,
47 // Authenticate as 'Anonymous' user by default. This is done in tandem
48 // with Sourcegraphs authenticate-by-http-header feature, and is a
49 // workaround for the lack of a public view in the self-hosted free
50 // version of Sourcegraph.
51 // https://twitter.com/sqs/status/1272659451292422144
52 setHeaders: ["X-Forwarded-User Anonymous"],
53 },
54 },
55 },
56 extraPaths: [
57 {
58 // Redirect anonymous user settings to a service that doesn't
59 // have any endpoints/backends.
60 path: "/users/Anonymous/settings",
61 backend: { serviceName: sourcegraph.blocksvc.metadata.name, servicePort: 8080 },
62 },
63 ],
64 },
65
66 blocksvc: kube.Service(sourcegraph.makeName("blocksvc")) {
67 metadata+: sourcegraph.metadata,
68 spec+: {
69 selector: null,
70 ports: [{ port: 2137, targetPort: 2137 }],
71 },
72 },
73
74 pvc: {
75 data: kube.PersistentVolumeClaim(sourcegraph.makeName("data")) {
76 metadata+: sourcegraph.metadata,
77 spec+: {
78 storageClassName: cfg.storageClassName,
79 accessModes: [ "ReadWriteOnce" ],
80 resources: {
81 requests: {
82 storage: "40Gi",
83 },
84 },
85 },
86 },
87 etc: kube.PersistentVolumeClaim(sourcegraph.makeName("etc")) {
88 metadata+: sourcegraph.metadata,
89 spec+: {
90 storageClassName: cfg.storageClassName,
91 accessModes: [ "ReadWriteOnce" ],
92 resources: {
93 requests: {
94 storage: "4Gi",
95 },
96 },
97 },
98 },
99 },
100 }
101}