Piotr Dobrowolski | 122d5e5 | 2021-09-10 23:54:34 +0200 | [diff] [blame^] | 1 | local kube = import "../../../kube/kube.libsonnet"; |
| 2 | |
| 3 | { |
| 4 | local app = self, |
| 5 | local cfg = app.cfg, |
| 6 | cfg:: { |
| 7 | image: error "cfg.image needs to be set", |
| 8 | |
| 9 | homeservers: [], |
| 10 | admins: [], |
| 11 | |
| 12 | s3: { |
| 13 | endpoint: error "cfg.s3.endpoint needs to be set", |
| 14 | accessKey: error "cfg.s3.accessKey needs to be set", |
| 15 | secretKey: error "cfg.s3.secretKey needs to be set", |
| 16 | bucketName: error "cfg.s3.bucketName needs to be set", |
| 17 | region: error "cfg.s3.region needs to be set", |
| 18 | }, |
| 19 | |
| 20 | db: { |
| 21 | username: error "cfg.db.username needs to be set", |
| 22 | password: error "cfg.db.password needs to be set", |
| 23 | database: error "cfg.db.database needs to be set", |
| 24 | host: error "cfg.db.host needs to be set", |
| 25 | }, |
| 26 | }, |
| 27 | |
| 28 | ns:: error "ns needs to be a kube.Namespace object", |
| 29 | |
| 30 | config:: { |
| 31 | repo: { |
| 32 | bindAddress: "0.0.0.0", |
| 33 | port: 8000, |
| 34 | }, |
| 35 | database: { |
| 36 | postgres: "postgres://%s:%s@%s/%s?sslmode=disable" % [cfg.db.username, cfg.db.password, cfg.db.host, cfg.db.database], |
| 37 | }, |
| 38 | homeservers: cfg.homeservers, |
| 39 | admins: cfg.admins, |
| 40 | datastores: [ |
| 41 | { |
| 42 | type: "s3", |
| 43 | enabled: true, |
| 44 | forKinds: ["all"], |
| 45 | opts: { |
| 46 | tempPath: "/tmp/mediarepo_s3_upload", |
| 47 | endpoint: cfg.s3.endpoint, |
| 48 | accessKeyId: cfg.s3.accessKey, |
| 49 | accessSecret: cfg.s3.secretKey, |
| 50 | ssl: false, |
| 51 | bucketName: cfg.s3.bucketName, |
| 52 | region: cfg.s3.region, |
| 53 | }, |
| 54 | } |
| 55 | ], |
| 56 | }, |
| 57 | |
| 58 | configSecret: app.ns.Contain(kube.Secret("media-repo-config")) { |
| 59 | data_: { |
| 60 | "config.yaml": std.manifestJsonEx(app.config, ""), |
| 61 | }, |
| 62 | }, |
| 63 | |
| 64 | deployment: app.ns.Contain(kube.Deployment("media-repo")) { |
| 65 | spec+: { |
| 66 | replicas: 1, |
| 67 | template+: { |
| 68 | spec+: { |
| 69 | volumes_: { |
| 70 | config: kube.SecretVolume(app.configSecret), |
| 71 | tempdir: kube.EmptyDirVolume(), |
| 72 | }, |
| 73 | containers_: { |
| 74 | repo: kube.Container("media-repo") { |
| 75 | image: cfg.image, |
| 76 | command: ["/usr/local/bin/media_repo"], |
| 77 | ports_: { |
| 78 | http: { containerPort: 8000 }, |
| 79 | }, |
| 80 | env_: { |
| 81 | REPO_CONFIG: "/config", |
| 82 | }, |
| 83 | volumeMounts_: { |
| 84 | config: { mountPath: "/config" }, |
| 85 | tempdir: { mountPath: "/tmp/mediarepo_s3_upload" }, |
| 86 | }, |
| 87 | }, |
| 88 | }, |
| 89 | }, |
| 90 | }, |
| 91 | }, |
| 92 | }, |
| 93 | |
| 94 | svc: app.ns.Contain(kube.Service("media-repo")) { |
| 95 | target_pod:: app.deployment.spec.template, |
| 96 | }, |
| 97 | } |