3c4761c5674f20a38840f20c5613fc9c5f5adef7
[csit.git] / terraform-ci-infra / 1n_nmd / nginx / conf / nomad / nginx.hcl
1 job "${job_name}" {
2   # The "region" parameter specifies the region in which to execute the job.
3   # If omitted, this inherits the default region name of "global".
4   # region = "global"
5   #
6   # The "datacenters" parameter specifies the list of datacenters which should
7   # be considered when placing this task. This must be provided.
8   datacenters = "${datacenters}"
9
10   # The "type" parameter controls the type of job, which impacts the scheduler's
11   # decision on placement. This configuration is optional and defaults to
12   # "service". For a full list of job types and their differences, please see
13   # the online documentation.
14   #
15   # For more information, please see the online documentation at:
16   #
17   #     https://www.nomadproject.io/docs/jobspec/schedulers.html
18   #
19   type = "service"
20
21   update {
22     # The "max_parallel" parameter specifies the maximum number of updates to
23     # perform in parallel. In this case, this specifies to update a single task
24     # at a time.
25     max_parallel      = 0
26
27     # The "min_healthy_time" parameter specifies the minimum time the allocation
28     # must be in the healthy state before it is marked as healthy and unblocks
29     # further allocations from being updated.
30     min_healthy_time  = "10s"
31
32     # The "healthy_deadline" parameter specifies the deadline in which the
33     # allocation must be marked as healthy after which the allocation is
34     # automatically transitioned to unhealthy. Transitioning to unhealthy will
35     # fail the deployment and potentially roll back the job if "auto_revert" is
36     # set to true.
37     healthy_deadline  = "3m"
38
39     # The "progress_deadline" parameter specifies the deadline in which an
40     # allocation must be marked as healthy. The deadline begins when the first
41     # allocation for the deployment is created and is reset whenever an allocation
42     # as part of the deployment transitions to a healthy state. If no allocation
43     # transitions to the healthy state before the progress deadline, the
44     # deployment is marked as failed.
45     progress_deadline = "10m"
46
47     # The "auto_revert" parameter specifies if the job should auto-revert to the
48     # last stable job on deployment failure. A job is marked as stable if all the
49     # allocations as part of its deployment were marked healthy.
50     auto_revert       = false
51
52     # The "canary" parameter specifies that changes to the job that would result
53     # in destructive updates should create the specified number of canaries
54     # without stopping any previous allocations. Once the operator determines the
55     # canaries are healthy, they can be promoted which unblocks a rolling update
56     # of the remaining allocations at a rate of "max_parallel".
57     #
58     # Further, setting "canary" equal to the count of the task group allows
59     # blue/green deployments. When the job is updated, a full set of the new
60     # version is deployed and upon promotion the old version is stopped.
61     canary            = 0
62   }
63
64   # The reschedule stanza specifies the group's rescheduling strategy. If
65   # specified at the job level, the configuration will apply to all groups
66   # within the job. If the reschedule stanza is present on both the job and the
67   # group, they are merged with the group stanza taking the highest precedence
68   # and then the job.
69   reschedule {
70     delay             = "30s"
71     delay_function    = "constant"
72     unlimited         = true
73   }
74
75   # The "group" stanza defines a series of tasks that should be co-located on
76   # the same Nomad client. Any task within a group will be placed on the same
77   # client.
78   #
79   # For more information and examples on the "group" stanza, please see
80   # the online documentation at:
81   #
82   #     https://www.nomadproject.io/docs/job-specification/group.html
83   #
84   group "prod-group1-nginx" {
85     # The "count" parameter specifies the number of the task groups that should
86     # be running under this group. This value must be non-negative and defaults
87     # to 1.
88     count = 1
89
90     # https://www.nomadproject.io/docs/job-specification/volume
91     %{ if use_host_volume }
92     volume "prod-volume1-nginx" {
93       type      = "host"
94       read_only = false
95       source    = "${host_volume}"
96     }
97     %{ endif }
98
99     # The restart stanza configures a tasks's behavior on task failure. Restarts
100     # happen on the client that is running the task.
101     restart {
102       interval  = "10m"
103       attempts  = 2
104       delay     = "15s"
105       mode      = "fail"
106     }
107
108     # The "task" stanza creates an individual unit of work, such as a Docker
109     # container, web application, or batch processing.
110     #
111     # For more information and examples on the "task" stanza, please see
112     # the online documentation at:
113     #
114     #     https://www.nomadproject.io/docs/job-specification/task.html
115     #
116     task "prod-task1-nginx" {
117       # The "driver" parameter specifies the task driver that should be used to
118       # run the task.
119       driver = "docker"
120
121       # The "config" stanza specifies the driver configuration, which is passed
122       # directly to the driver to start the task. The details of configurations
123       # are specific to each driver, so please see specific driver
124       # documentation for more information.
125       config {
126         image        = "nginx:stable"
127         dns_servers  = [ "$${attr.unique.network.ip-address}" ]
128         port_map {
129           https      = 443
130         }
131         privileged   = false
132         volumes      = [
133           "/etc/consul.d/ssl/consul.pem:/etc/ssl/certs/nginx-cert.pem",
134           "/etc/consul.d/ssl/consul-key.pem:/etc/ssl/private/nginx-key.pem",
135           "custom/upstream.conf:/etc/nginx/conf.d/upstream.conf",
136           "custom/logs.conf:/etc/nginx/conf.d/logs.conf",
137           "custom/docs.conf:/etc/nginx/conf.d/docs.conf"
138         ]
139       }
140
141       # The "template" stanza instructs Nomad to manage a template, such as
142       # a configuration file or script. This template can optionally pull data
143       # from Consul or Vault to populate runtime configuration data.
144       #
145       # For more information and examples on the "template" stanza, please see
146       # the online documentation at:
147       #
148       #     https://www.nomadproject.io/docs/job-specification/template.html
149       #
150       template {
151         data = <<EOH
152           upstream storage {
153             server storage0.storage.service.consul:9000;
154             server storage1.storage.service.consul:9000;
155             server storage2.storage.service.consul:9000;
156             server storage3.storage.service.consul:9000;
157           }
158         EOH
159         destination = "custom/upstream.conf"
160       }
161       template {
162         data = <<EOH
163           server {
164             listen 443 ssl default_server;
165             server_name logs.nginx.service.consul;
166             keepalive_timeout 70;
167             ssl_session_cache shared:SSL:10m;
168             ssl_session_timeout 10m;
169             ssl_protocols TLSv1.2;
170             ssl_prefer_server_ciphers on;
171             ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384";
172             ssl_certificate /etc/ssl/certs/nginx-cert.pem;
173             ssl_certificate_key /etc/ssl/private/nginx-key.pem;
174             location / {
175               chunked_transfer_encoding off;
176               proxy_connect_timeout 300;
177               proxy_http_version 1.1;
178               proxy_set_header Host $host:$server_port;
179               proxy_set_header Connection "";
180               proxy_pass http://storage/logs.fd.io/;
181               server_name_in_redirect off;
182             }
183             location ~ (.*html.gz)$ {
184               add_header Content-Encoding gzip;
185               add_header Content-Type text/html;
186               chunked_transfer_encoding off;
187               proxy_connect_timeout 300;
188               proxy_http_version 1.1;
189               proxy_set_header Host $host:$server_port;
190               proxy_set_header Connection "";
191               proxy_pass http://storage/logs.fd.io/$1;
192               server_name_in_redirect off;
193             }
194             location ~ (.*txt.gz|.*log.gz)$ {
195               add_header Content-Encoding gzip;
196               add_header Content-Type text/plain;
197               chunked_transfer_encoding off;
198               proxy_connect_timeout 300;
199               proxy_http_version 1.1;
200               proxy_set_header Host $host:$server_port;
201               proxy_set_header Connection "";
202               proxy_pass http://storage/logs.fd.io/$1;
203               server_name_in_redirect off;
204             }
205             location ~ (.*xml.gz)$ {
206               add_header Content-Encoding gzip;
207               add_header Content-Type application/xml;
208               chunked_transfer_encoding off;
209               proxy_connect_timeout 300;
210               proxy_http_version 1.1;
211               proxy_set_header Host $host:$server_port;
212               proxy_set_header Connection "";
213               proxy_pass http://storage/logs.fd.io/$1;
214               server_name_in_redirect off;
215             }
216         }
217         EOH
218         destination = "custom/logs.conf"
219       }
220       template {
221         data = <<EOH
222           server {
223             listen 443 ssl;
224             server_name docs.nginx.service.consul;
225             keepalive_timeout 70;
226             ssl_session_cache shared:SSL:10m;
227             ssl_session_timeout 10m;
228             ssl_protocols TLSv1.2;
229             ssl_prefer_server_ciphers on;
230             ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384";
231             ssl_certificate /etc/ssl/certs/nginx-cert.pem;
232             ssl_certificate_key /etc/ssl/private/nginx-key.pem;
233             location / {
234               chunked_transfer_encoding off;
235               proxy_connect_timeout 300;
236               proxy_http_version 1.1;
237               proxy_set_header Host $host:$server_port;
238               proxy_set_header Connection "";
239               proxy_pass http://storage/docs.fd.io/;
240               server_name_in_redirect off;
241             }
242           }
243         EOH
244         destination = "custom/docs.conf"
245       }
246
247       # The service stanza instructs Nomad to register a service with Consul.
248       #
249       # For more information and examples on the "task" stanza, please see
250       # the online documentation at:
251       #
252       #     https://www.nomadproject.io/docs/job-specification/service.html
253       #
254       service {
255         name       = "nginx"
256         port       = "https"
257         tags       = [ "docs", "logs" ]
258       }
259
260       # The "resources" stanza describes the requirements a task needs to
261       # execute. Resource requirements include memory, network, cpu, and more.
262       # This ensures the task will execute on a machine that contains enough
263       # resource capacity.
264       #
265       # For more information and examples on the "resources" stanza, please see
266       # the online documentation at:
267       #
268       #     https://www.nomadproject.io/docs/job-specification/resources.html
269       #
270       resources {
271         cpu        = 1000
272         memory     = 1024
273         network {
274           mode     = "bridge"
275           port "https" {
276             static = 443
277           }
278         }
279       }
280     }
281   }
282 }