blob: a35b892146c8bc51fd3ed6070012a7915d88674c [file] [log] [blame]
Sergiusz Bazanskid0ec2c62019-11-21 00:08:52 +01001local mirko = import "../../kube/mirko.libsonnet";
2local kube = import "../../kube/kube.libsonnet";
3
4{
5 cfg:: {
6 secret: {
7 twilio_token: error "twilio_token must be set",
8 },
9 image: "registry.k0.hswaw.net/q3k/smsgs:1570049853-05c5b491c45de6d960979d4aee8635768f3178e9",
10 webhookFQDN: error "webhookFQDN must be set",
11 },
12
13 component(cfg, env):: mirko.Component(env, "smsgw") {
14 local smsgw = self,
15 cfg+: {
16 image: cfg.image,
17 container: smsgw.GoContainer("main", "/smsgw/smsgw") {
18 env_: {
19 TWILIO_TOKEN: kube.SecretKeyRef(smsgw.secret, "twilio_token"),
20 },
21 command+: [
22 "-twilio_friendly_phone", "48732168371",
23 "-twilio_sid", "AC806ed4bf4b6c80c8f8ea686379b69518",
24 "-twilio_token", "$(TWILIO_TOKEN)",
25 "-webhook_listen", "0.0.0.0:5000",
26 "-webhook_public", "https://%s/" % [ cfg.webhookFQDN ],
27 ],
28 },
29 ports+: {
30 publicHTTP: {
31 webhook: {
32 port: 5000,
33 dns: cfg.webhookFQDN,
34 }
35 },
36 },
37 },
38
39 secret: kube.Secret("smsgw") {
40 metadata+: smsgw.metadata,
41 data: cfg.secret,
42 },
43
44 // Temporary machinery to access gRPC from outsite.
45 // In the future, this will be handled by a proxy/API gateway.
46 // For now, we need this running.
47 // TODO(q3k): remove this when we have an API GW or proxy.
48 stopgap: {
49 local stopgap = self,
50
51 rpcLB: kube.Service("smsgw-tcp-rpc") {
52 metadata+: smsgw.metadata,
53 target_pod: smsgw.deployment.spec.template,
54 spec+: {
55 type: "LoadBalancer",
56 ports: [
57 { name: "grpc-external", port: 443, targetPort: 4200 },
58 ],
59 },
60 },
61
62 mkClientCert(name, cn):: kube.Certificate(name) {
63 metadata+: smsgw.metadata,
64 spec: {
65 secretName: name,
66 duration: "35040h0m0s", // 4 years
67 issuerRef: {
68 // Contract with cluster/lib/pki.libsonnet.
69 // Copied over.
70 name: "pki-ca",
71 kind: "ClusterIssuer",
72 },
73 commonName: cn,
74 },
75 },
76
77 kasownikCert: stopgap.mkClientCert("smsgw-tcp-rpc-consumer", "kasownik.external.hswaw.net"),
78 piorekfCert: stopgap.mkClientCert("smsgw-tcp-rpc-piorekf", "piorekf.person.hswaw.net"),
79 }
80 },
81}