Sergiusz Bazanski | 91e1a8c | 2020-06-25 12:16:29 +0200 | [diff] [blame] | 1 | local mirko = import "../../kube/mirko.libsonnet"; |
| 2 | local 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 Bazanski | b7898a8 | 2020-08-23 11:05:27 +0000 | [diff] [blame] | 24 | 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 Bazanski | 91e1a8c | 2020-06-25 12:16:29 +0200 | [diff] [blame] | 37 | }, |
| 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, |
| 89 | spec+: { |
| 90 | storageClassName: cfg.storageClassName, |
| 91 | accessModes: [ "ReadWriteOnce" ], |
| 92 | resources: { |
| 93 | requests: { |
| 94 | storage: "40Gi", |
| 95 | }, |
| 96 | }, |
| 97 | }, |
| 98 | }, |
| 99 | etc: kube.PersistentVolumeClaim(sourcegraph.makeName("etc")) { |
| 100 | metadata+: sourcegraph.metadata, |
| 101 | spec+: { |
| 102 | storageClassName: cfg.storageClassName, |
| 103 | accessModes: [ "ReadWriteOnce" ], |
| 104 | resources: { |
| 105 | requests: { |
| 106 | storage: "4Gi", |
| 107 | }, |
| 108 | }, |
| 109 | }, |
| 110 | }, |
| 111 | }, |
| 112 | } |
| 113 | } |