3bbbe5309f38d07a2dfa6a1cea1239bb58ab51e7
[csit.git] / fdio.infra.terraform / 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     #
102     # https://www.nomadproject.io/docs/job-specification/restart
103     #
104     restart {
105       interval        = "30m"
106       attempts        = 40
107       delay           = "15s"
108       mode            = "delay"
109     }
110
111     # The constraint allows restricting the set of eligible nodes. Constraints
112     # may filter on attributes or client metadata.
113     #
114     # For more information and examples on the "volume" stanza, please see
115     # the online documentation at:
116     #
117     #     https://www.nomadproject.io/docs/job-specification/constraint
118     #
119     constraint {
120       attribute       = "$${attr.cpu.arch}"
121       operator        = "!="
122       value           = "arm64"
123     }
124
125     constraint {
126       attribute      = "$${node.class}"
127       value          = "builder"
128     }
129
130     # The "task" stanza creates an individual unit of work, such as a Docker
131     # container, web application, or batch processing.
132     #
133     # For more information and examples on the "task" stanza, please see
134     # the online documentation at:
135     #
136     #     https://www.nomadproject.io/docs/job-specification/task.html
137     #
138     task "prod-task1-nginx" {
139       # The "driver" parameter specifies the task driver that should be used to
140       # run the task.
141       driver          = "docker"
142
143       # The "config" stanza specifies the driver configuration, which is passed
144       # directly to the driver to start the task. The details of configurations
145       # are specific to each driver, so please see specific driver
146       # documentation for more information.
147       config {
148         image         = "nginx:stable"
149         port_map {
150           https       = 443
151         }
152         privileged    = false
153         volumes       = [
154           "/etc/ssl/certs/logs.nginx.service.consul.crt:/etc/ssl/certs/logs.nginx.service.consul.crt",
155           "/etc/ssl/private/logs.nginx.service.consul.key:/etc/ssl/private/logs.nginx.service.consul.key",
156           "custom/upstream.conf:/etc/nginx/conf.d/upstream.conf",
157           "custom/server_logs.conf:/etc/nginx/conf.d/server_logs.conf"
158         ]
159       }
160
161       # The "template" stanza instructs Nomad to manage a template, such as
162       # a configuration file or script. This template can optionally pull data
163       # from Consul or Vault to populate runtime configuration data.
164       #
165       # For more information and examples on the "template" stanza, please see
166       # the online documentation at:
167       #
168       #     https://www.nomadproject.io/docs/job-specification/template.html
169       #
170       template {
171         data = <<EOH
172           upstream storage {
173             {{ range service "storage" }}
174               server {{ .Address }}:{{ .Port }};
175             {{ end }}
176           }
177         EOH
178         destination = "custom/upstream.conf"
179       }
180       template {
181         data = <<EOH
182           server {
183             listen 443 ssl default_server;
184             server_name logs.nginx.service.consul;
185
186             ssl_certificate /etc/ssl/certs/logs.nginx.service.consul.crt;
187             ssl_certificate_key /etc/ssl/private/logs.nginx.service.consul.key;
188             ssl_protocols TLSv1.2;
189             ssl_prefer_server_ciphers on;
190             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";
191             ssl_session_timeout 10m;
192             ssl_session_cache shared:SSL:10m;
193             ssl_session_tickets off;
194             ssl_stapling on;
195             ssl_stapling_verify on;
196
197             fastcgi_hide_header X-Powered-By;
198
199             client_max_body_size 0;
200             client_header_timeout 60;
201             client_body_timeout 86400;
202             fastcgi_read_timeout 86400;
203             proxy_connect_timeout 60;
204             proxy_read_timeout 86400;
205             proxy_send_timeout 86400;
206             send_timeout 86400;
207
208             keepalive_timeout 70;
209             location / {
210               chunked_transfer_encoding off;
211               proxy_connect_timeout 300;
212               proxy_http_version 1.1;
213               proxy_set_header Host $host:$server_port;
214               proxy_set_header Connection "";
215               proxy_pass http://storage/logs.fd.io/;
216               server_name_in_redirect off;
217             }
218             location ~ (.*html.gz)$ {
219               add_header Content-Encoding gzip;
220               add_header Content-Type text/html;
221               chunked_transfer_encoding off;
222               proxy_connect_timeout 300;
223               proxy_http_version 1.1;
224               proxy_set_header Host $host:$server_port;
225               proxy_set_header Connection "";
226               proxy_pass http://storage/logs.fd.io/$1;
227               server_name_in_redirect off;
228             }
229             location ~ (.*txt.gz|.*log.gz)$ {
230               add_header Content-Encoding gzip;
231               add_header Content-Type text/plain;
232               chunked_transfer_encoding off;
233               proxy_connect_timeout 300;
234               proxy_http_version 1.1;
235               proxy_set_header Host $host:$server_port;
236               proxy_set_header Connection "";
237               proxy_pass http://storage/logs.fd.io/$1;
238               server_name_in_redirect off;
239             }
240             location ~ (.*xml.gz)$ {
241               add_header Content-Encoding gzip;
242               add_header Content-Type application/xml;
243               chunked_transfer_encoding off;
244               proxy_connect_timeout 300;
245               proxy_http_version 1.1;
246               proxy_set_header Host $host:$server_port;
247               proxy_set_header Connection "";
248               proxy_pass http://storage/logs.fd.io/$1;
249               server_name_in_redirect off;
250             }
251         }
252         EOH
253         destination = "custom/logs.conf"
254       }
255
256       # The service stanza instructs Nomad to register a service with Consul.
257       #
258       # For more information and examples on the "task" stanza, please see
259       # the online documentation at:
260       #
261       #     https://www.nomadproject.io/docs/job-specification/service.html
262       #
263       service {
264         name       = "nginx"
265         port       = "https"
266         tags       = [ "logs" ]
267       }
268
269       # The "resources" stanza describes the requirements a task needs to
270       # execute. Resource requirements include memory, network, cpu, and more.
271       # This ensures the task will execute on a machine that contains enough
272       # resource capacity.
273       #
274       # For more information and examples on the "resources" stanza, please see
275       # the online documentation at:
276       #
277       #     https://www.nomadproject.io/docs/job-specification/resources.html
278       #
279       resources {
280         cpu        = 2000
281         memory     = 4096
282         network {
283           mode     = "bridge"
284           port "https" {
285             static = 443
286           }
287         }
288       }
289     }
290   }
291 }