|
| 1 | +local kube = import '../vendor/kube-prod-runtime/lib/kube.libsonnet'; |
| 2 | +local utils = import '../vendor/kube-prod-runtime/lib/utils.libsonnet'; |
| 3 | + |
| 4 | +local IMAGE = 'nginx:1.15.12'; |
| 5 | +local WWW_VOLUME_PATH = '/usr/share/nginx/html'; |
| 6 | +local CONFIG_PATH = '/etc/nginx/conf.d'; |
| 7 | +local HTTP_PORT = 80; |
| 8 | + |
| 9 | +{ |
| 10 | + p:: '', |
| 11 | + |
| 12 | + app:: 'landingpage', |
| 13 | + |
| 14 | + index:: false, |
| 15 | + |
| 16 | + name:: $.p + $.app, |
| 17 | + |
| 18 | + domain:: 'example.net', |
| 19 | + |
| 20 | + sslRedirectDomains:: ['redirect1.example.net', 'redirect2.example.net'], |
| 21 | + |
| 22 | + namespace:: 'auth', |
| 23 | + |
| 24 | + labels:: { |
| 25 | + metadata+: { |
| 26 | + labels+: { |
| 27 | + app: $.app, |
| 28 | + }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + |
| 32 | + metadata:: $.labels { |
| 33 | + metadata+: { |
| 34 | + namespace: $.namespace, |
| 35 | + }, |
| 36 | + }, |
| 37 | + |
| 38 | + redirectStatement:: if std.length($.sslRedirectDomains) > 0 then |
| 39 | + 'server {\n' + |
| 40 | + ' listen 80;\n' + |
| 41 | + ' server_name ' + std.join(' ', $.sslRedirectDomains) + ';\n' + |
| 42 | + ' return 301 https://$host$request_uri;\n' + |
| 43 | + '}\n' |
| 44 | + else |
| 45 | + '', |
| 46 | + |
| 47 | + configMap: kube.ConfigMap($.name) + $.metadata { |
| 48 | + data+: { |
| 49 | + 'default.conf': ||| |
| 50 | + server { |
| 51 | + listen 80; |
| 52 | + server_name _; |
| 53 | +
|
| 54 | + location / { |
| 55 | + root /usr/share/nginx/html; |
| 56 | + index index.html index.htm; |
| 57 | + } |
| 58 | +
|
| 59 | + error_page 500 502 503 504 /50x.html; |
| 60 | + location = /50x.html { |
| 61 | + root /usr/share/nginx/html; |
| 62 | + } |
| 63 | + if ($http_x_forwarded_proto = "http") { |
| 64 | + return 301 https://$host$request_uri; |
| 65 | + } |
| 66 | + } |
| 67 | + ||| + $.redirectStatement, |
| 68 | + }, |
| 69 | + }, |
| 70 | + |
| 71 | + Link(cloud, link, text):: std.manifestXmlJsonml([ |
| 72 | + 'div', |
| 73 | + { class: 'col s12 m4' }, |
| 74 | + '\n ', |
| 75 | + [ |
| 76 | + 'div', |
| 77 | + {}, |
| 78 | + [ |
| 79 | + 'img', |
| 80 | + { |
| 81 | + width: 56, |
| 82 | + height: 56, |
| 83 | + alt: cloud, |
| 84 | + src: cloud + '.svg', |
| 85 | + }, |
| 86 | + ], |
| 87 | + ], |
| 88 | + [ |
| 89 | + 'div', |
| 90 | + {}, |
| 91 | + [ |
| 92 | + 'a', |
| 93 | + { |
| 94 | + class: 'btn-large waves-effect waves-light blue', |
| 95 | + href: link, |
| 96 | + }, |
| 97 | + text, |
| 98 | + ], |
| 99 | + ], |
| 100 | + '\n', |
| 101 | + ]), |
| 102 | + |
| 103 | + content:: '', |
| 104 | + |
| 105 | + wwwConfigMap: if $.index then kube.ConfigMap($.name + '-www') + $.metadata { |
| 106 | + data+: { |
| 107 | + 'index.html': std.strReplace( |
| 108 | + (importstr './landingpage/index.html'), |
| 109 | + '#CONTENT#', |
| 110 | + $.content, |
| 111 | + ), |
| 112 | + 'amazon.svg': importstr './landingpage/amazon.svg', |
| 113 | + 'google.svg': importstr './landingpage/google.svg', |
| 114 | + 'digitalocean.svg': importstr './landingpage/digitalocean.svg', |
| 115 | + }, |
| 116 | + }, |
| 117 | + |
| 118 | + deployment: kube.Deployment($.name) + $.metadata { |
| 119 | + local this = self, |
| 120 | + spec+: { |
| 121 | + replicas: 1, |
| 122 | + template+: { |
| 123 | + metadata+: { |
| 124 | + annotations+: { |
| 125 | + 'config/hash': std.md5(std.escapeStringJson($.configMap)), |
| 126 | + } + if $.index then { 'www/hash': std.md5(std.escapeStringJson($.wwwConfigMap)) } else {}, |
| 127 | + }, |
| 128 | + spec+: { |
| 129 | + affinity: kube.PodZoneAntiAffinityAnnotation(this.spec.template), |
| 130 | + default_container: $.app, |
| 131 | + volumes_+: { |
| 132 | + config: kube.ConfigMapVolume($.configMap), |
| 133 | + } + if $.index then { www: kube.ConfigMapVolume($.wwwConfigMap) } else {}, |
| 134 | + containers_+: { |
| 135 | + landingpage: kube.Container($.app) { |
| 136 | + local container = self, |
| 137 | + image: IMAGE, |
| 138 | + resources: { |
| 139 | + requests: { cpu: '10m', memory: '64Mi' }, |
| 140 | + }, |
| 141 | + ports_+: { |
| 142 | + http: { containerPort: HTTP_PORT }, |
| 143 | + }, |
| 144 | + volumeMounts_+: { |
| 145 | + config: { mountPath: CONFIG_PATH }, |
| 146 | + } + if $.index then { www: { mountPath: WWW_VOLUME_PATH } } else {}, |
| 147 | + readinessProbe: { |
| 148 | + httpGet: { path: '/', port: HTTP_PORT }, |
| 149 | + }, |
| 150 | + livenessProbe: self.readinessProbe { |
| 151 | + // elasticsearch_logging_discovery has a 5min timeout on cluster bootstrap |
| 152 | + initialDelaySeconds: 2 * 60, |
| 153 | + failureThreshold: 4, |
| 154 | + }, |
| 155 | + }, |
| 156 | + }, |
| 157 | + }, |
| 158 | + }, |
| 159 | + }, |
| 160 | + }, |
| 161 | + |
| 162 | + |
| 163 | + ingress: if std.length($.sslRedirectDomains) > 0 || $.index then kube.Ingress($.name) + $.metadata { |
| 164 | + local hosts = $.sslRedirectDomains + if $.index then [$.domain] else [], |
| 165 | + metadata+: { |
| 166 | + annotations+: { |
| 167 | + 'kubernetes.io/ingress.class': 'contour', |
| 168 | + }, |
| 169 | + }, |
| 170 | + spec+: { |
| 171 | + rules+: std.map( |
| 172 | + (function(h) { |
| 173 | + host: h, |
| 174 | + http: { |
| 175 | + paths: [ |
| 176 | + { path: '/', backend: $.svc.name_port }, |
| 177 | + ], |
| 178 | + }, |
| 179 | + }), hosts |
| 180 | + ), |
| 181 | + } + if $.index && $.certificate != null then { |
| 182 | + tls: [{ |
| 183 | + hosts: [$.domain], |
| 184 | + secretName: $.certificate.spec.secretName, |
| 185 | + }], |
| 186 | + } else {}, |
| 187 | + }, |
| 188 | + |
| 189 | + |
| 190 | + svc: kube.Service($.name) + $.metadata { |
| 191 | + target_pod: $.deployment.spec.template, |
| 192 | + spec+: { |
| 193 | + sessionAffinity: 'None', |
| 194 | + }, |
| 195 | + }, |
| 196 | +} |
0 commit comments