blob: 9c1ed6a006e406be45370285045eb371d07e0d0a [file] [log] [blame]
Piotr Dobrowolski0572fff2021-02-06 22:23:53 +01001local kube = import "../../kube/kube.libsonnet";
2local postgres = import "../../kube/postgres.libsonnet";
3
4{
5 local app = self,
6 local cfg = app.cfg,
7
8 cfg:: {
9 namespace: "redmine",
10 image: "registry.k0.hswaw.net/informatic/redmine@sha256:b04d1fd04549424e505722c9feb0b6741a057cb8f0fab68ad3730ecb167417df",
11 domain: error "domain must be set",
12 storageClassName: "waw-hdd-redundant-3",
13 database: {
14 host: "postgres",
15 name: "redmine",
16 username: "redmine",
17 password: { secretKeyRef: { name: "redmine", key: "postgres_password" } },
18 port: 5432,
19 },
20
Serge Bazanski877cf0a2021-02-08 00:34:34 +010021 b: {
22 domains: [],
23 image: "registry.k0.hswaw.net/q3k/b:315532800-6cc2f867951e123909b23955cd7bcbcc3ec24f8a",
24 },
25
Piotr Dobrowolski0572fff2021-02-06 22:23:53 +010026 storage: {
27 endpoint: error "storage.endpoint must be set",
28 region: error "storage.region must be set",
29 bucket: error "storage.bucket must be set",
30 accessKey: error "storage.accessKey must be set",
31 secretKey: error "storage.secretKey must be set",
32 },
33
34 oidc: {
35 server: error "oidc.server must be set",
36 clientID: error "oidc.clientID must be set",
37 clientSecret: error "oidc.clientSecret must be set",
38 },
39 },
40
41 ns: kube.Namespace(app.cfg.namespace),
42
43 postgres: postgres {
44 cfg+: {
45 namespace: cfg.namespace,
46 appName: "redmine",
47 database: cfg.database.name,
48 username: cfg.database.username,
49 password: cfg.database.password,
50 storageClassName: cfg.storageClassName,
51 },
52 },
53
54 deployment: app.ns.Contain(kube.Deployment("redmine")) {
55 spec+: {
56 replicas: 1,
57 template+: {
58 spec+: {
59 securityContext: {
60 runAsUser: 999,
61 runAsGroup: 999,
62 fsGroup: 999,
63 },
64 containers_: {
65 web: kube.Container("redmine") {
66 image: cfg.image,
67 ports_: {
68 http: { containerPort: 3000 },
69 },
70 env_: {
71 REDMINE_DB_POSTGRES: cfg.database.host,
72 REDMINE_DB_PORT: cfg.database.port,
73 REDMINE_DB_USERNAME: cfg.database.username,
74 REDMINE_DB_PASSWORD: cfg.database.password,
75 REDMINE_DB_DATABASE: cfg.database.name,
76
77 REDMINE_SECRET_KEY_BASE: { secretKeyRef: { name: "redmine", key: "secret_key" } },
78
79 REDMINE_OIDC_SERVER: cfg.oidc.server,
80 REDMINE_OIDC_CLIENT_ID: cfg.oidc.clientID,
81 REDMINE_OIDC_CLIENT_SECRET: cfg.oidc.clientSecret,
82 REDMINE_OIDC_ADMIN_GROUP: "issues-admin",
83
84 REDMINE_S3_ENDPOINT: cfg.storage.endpoint,
85 REDMINE_S3_BUCKET: cfg.storage.bucket,
86 REDMINE_S3_ACCESS_KEY_ID: cfg.storage.accessKey,
87 REDMINE_S3_SECRET_ACCESS_KEY: cfg.storage.secretKey,
88 REDMINE_S3_REGION: cfg.storage.region,
89 },
90 },
91 },
92 },
93 },
94 },
95 },
96
97 svc: app.ns.Contain(kube.Service("redmine")) {
98 target_pod:: app.deployment.spec.template,
99 },
100
101 ingress: app.ns.Contain(kube.Ingress("redmine")) {
102 metadata+: {
103 annotations+: {
104 "kubernetes.io/tls-acme": "true",
105 "certmanager.k8s.io/cluster-issuer": "letsencrypt-prod",
106 "nginx.ingress.kubernetes.io/proxy-body-size": "0",
107 },
108 },
109 spec+: {
110 tls: [
111 {
112 hosts: [cfg.domain],
113 secretName: "redmine-tls",
114 },
115 ],
116 rules: [
117 {
118 host: cfg.domain,
119 http: {
120 paths: [
121 { path: "/", backend: app.svc.name_port },
122 ]
123 },
124 }
125 ],
126 },
127 },
Serge Bazanski877cf0a2021-02-08 00:34:34 +0100128
129 b: (if std.length(cfg.b.domains) > 0 then {
130 deployment: app.ns.Contain(kube.Deployment("b")) {
131 spec+: {
132 replicas: 3,
133 template+: {
134 spec+: {
135 containers_: {
136 default: kube.Container("default") {
137 image: "registry.k0.hswaw.net/q3k/b:315532800-6cc2f867951e123909b23955cd7bcbcc3ec24f8a",
138 ports_: {
139 http: { containerPort: 8000 },
140 },
141 command: [
142 "/devtools/issues/b",
143 ],
144 },
145 },
146 },
147 },
148 },
149 },
150 svc: app.ns.Contain(kube.Service("b")) {
151 target_pod:: app.b.deployment.spec.template,
152 },
153 ingress: app.ns.Contain(kube.Ingress("b")) {
154 metadata+: {
155 annotations+: {
156 "kubernetes.io/tls-acme": "true",
157 "certmanager.k8s.io/cluster-issuer": "letsencrypt-prod",
158 "nginx.ingress.kubernetes.io/proxy-body-size": "0",
159 },
160 },
161 spec+: {
162 tls: [
163 {
164 hosts: cfg.b.domains,
165 secretName: "b-tls",
166 },
167 ],
168 rules: [
169 {
170 host: domain,
171 http: {
172 paths: [
173 { path: "/", backend: app.b.svc.name_port },
174 ]
175 },
176 }
177 for domain in cfg.b.domains
178 ],
179 },
180 }
181 } else {}),
182
Piotr Dobrowolski0572fff2021-02-06 22:23:53 +0100183}