blob: 5b94e5316ef11c0d548f82162a3531059bf82bc7 [file] [log] [blame]
Radek Pietruszewskif5844312023-10-27 22:41:18 +02001local kube = import "../../kube/hscloud.libsonnet";
radex33fbaed2023-11-16 22:27:02 +01002local postgres = import '../../kube/postgres.libsonnet';
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +02003
4{
5 local top = self,
6 local cfg = top.cfg,
7
8 cfg:: {
9 name: 'inventory',
10 namespace: 'inventory',
11 domain: 'inventory.hackerspace.pl',
12
13 image: 'registry.k0.hswaw.net/palid/spejstore:1694280421',
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020014 oauthClientId: '82fffb65-0bbd-4d18-becd-0ce0b31373cf',
15 storageClassName: 'waw-hdd-redundant-3',
16
17 mediaPath: '/var/www/media',
18 },
19
radex1439fde2023-11-24 12:22:22 +010020 secretRefs:: {
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020021 postgres: { secretKeyRef: { name: cfg.name, key: 'postgres_password' } },
22 oauth: { secretKeyRef: { name: cfg.name, key: 'oauth_secret' } },
23 },
24
radex99ed6a72023-11-24 11:42:55 +010025 local ns = kube.Namespace(cfg.namespace),
26
27 deployment: ns.Contain(kube.Deployment(cfg.name)) {
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020028 spec+: {
29 template+: {
30 spec+: {
31 volumes_: {
radex4ffc64d2023-11-24 13:28:57 +010032 media: top.media.volume,
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020033 },
34 containers_: {
35 default: kube.Container('default') {
36 image: cfg.image,
37 ports_: {
38 web: { containerPort: 8000 },
39 },
40 env_: {
41 SPEJSTORE_ENV: 'prod',
radex37991742023-11-24 12:37:37 +010042 SPEJSTORE_DB_NAME: top.postgres.cfg.database,
43 SPEJSTORE_DB_USER: top.postgres.cfg.username,
44 SPEJSTORE_DB_PASSWORD: top.postgres.cfg.password,
45 SPEJSTORE_DB_HOST: top.postgres.svc.host,
46 SPEJSTORE_DB_PORT: top.postgres.svc.port,
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020047 SPEJSTORE_ALLOWED_HOSTS: cfg.domain,
48 SPEJSTORE_CLIENT_ID: cfg.oauthClientId,
radex1439fde2023-11-24 12:22:22 +010049 SPEJSTORE_SECRET: top.secretRefs.oauth,
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020050 SPEJSTORE_MEDIA_ROOT: cfg.mediaPath,
51 SPEJSTORE_REQUIRE_AUTH: 'true',
52 SPEJSTORE_LAN_ALLOWED_ADDRESS_SPACE: '185.236.240.5',
53 },
54 volumeMounts_: {
55 media: { mountPath: cfg.mediaPath },
56 },
57 },
58 },
59 },
60 },
61 },
62 },
63
radex99ed6a72023-11-24 11:42:55 +010064 media: ns.Contain(kube.PersistentVolumeClaim(cfg.name)) {
radex36964dc2023-11-24 11:19:46 +010065 storage:: '20Gi',
66 storageClass:: cfg.storageClassName,
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020067 },
68
radex0e128492023-11-24 12:47:27 +010069 postgres: ns.Contain(postgres) {
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020070 cfg+: {
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020071 appName: cfg.name,
72 storageClassName: cfg.storageClassName,
73 version: '15.4',
74
radex37991742023-11-24 12:37:37 +010075 database: 'inventory',
76 username: 'inventory',
radex1439fde2023-11-24 12:22:22 +010077 password: top.secretRefs.postgres,
radex33fbaed2023-11-16 22:27:02 +010078 versionedNames: true,
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020079 },
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020080 },
81
radex99ed6a72023-11-24 11:42:55 +010082 service: ns.Contain(kube.Service(cfg.name)) {
radex8b8f3872023-11-24 11:09:46 +010083 target:: top.deployment,
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020084 },
85
radex99ed6a72023-11-24 11:42:55 +010086 ingress: ns.Contain(kube.SimpleIngress(cfg.name)) {
Radek Pietruszewskif5844312023-10-27 22:41:18 +020087 hosts:: [cfg.domain],
radexd45584a2023-11-24 12:51:57 +010088 target:: top.service,
Dariusz Niemczyk62b83e02023-08-13 20:14:15 +020089 },
90}