Report: Add data
[csit.git] / resources / tools / terraform / 1n_nmd / prod_storage / prod-storage.nomad
1 job "prod-storage" {
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 = [ "yul1" ]
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   # All groups in this job should be scheduled on different hosts.
65   constraint {
66     operator = "distinct_hosts"
67     value    = "true"
68   }
69
70   # the same Nomad client. Any task within a group will be placed on the same
71   # client.
72   #
73   # For more information and examples on the "group" stanza, please see
74   # the online documentation at:
75   #
76   #     https://www.nomadproject.io/docs/job-specification/group.html
77   #
78   group "prod-group1-storage" {
79     # The "count" parameter specifies the number of the task groups that should
80     # be running under this group. This value must be non-negative and defaults
81     # to 1.
82     count = 2
83
84     # Hard coding prefered node as primary.
85     affinity {
86       attribute = "${attr.unique.hostname}"
87       value     = "s46-nomad"
88       weight    = 100
89     }
90
91     # https://www.nomadproject.io/docs/job-specification/volume
92     volume "prod-volume1-storage" {
93       type      = "host"
94       read_only = false
95       source    = "prod-volume-data1-1"
96     }
97
98     # The "task" stanza creates an individual unit of work, such as a Docker
99     # container, web application, or batch processing.
100     #
101     # For more information and examples on the "task" stanza, please see
102     # the online documentation at:
103     #
104     #     https://www.nomadproject.io/docs/job-specification/task.html
105     #
106     task "prod-task1-storage" {
107       # The "driver" parameter specifies the task driver that should be used to
108       # run the task.
109       driver = "docker"
110
111       volume_mount {
112         volume      = "prod-volume1-storage"
113         destination = "/data/"
114         read_only   = false
115       }
116
117       # The "config" stanza specifies the driver configuration, which is passed
118       # directly to the driver to start the task. The details of configurations
119       # are specific to each driver, so please see specific driver
120       # documentation for more information.
121       config {
122         image       = "minio/minio:RELEASE.2020-11-19T23-48-16Z"
123         dns_servers = [ "${attr.unique.network.ip-address}" ]
124         command     = "server"
125         args        = [ "/data/" ]
126         port_map {
127           http      = 9000
128         }
129         privileged  = false
130       }
131
132       env {
133         MINIO_ACCESS_KEY = "minio"
134         MINIO_SECRET_KEY = "minio123"
135         MINIO_BROWSER    = "off"
136       }
137
138       # The service stanza instructs Nomad to register a service with Consul.
139       #
140       # For more information and examples on the "task" stanza, please see
141       # the online documentation at:
142       #
143       #     https://www.nomadproject.io/docs/job-specification/service.html
144       #
145       service {
146         name       = "storage"
147         port       = "http"
148         tags       = [ "storage${NOMAD_ALLOC_INDEX}" ]
149         check {
150           name     = "alive"
151           type     = "http"
152           port     = "http"
153           protocol = "http"
154           method   = "GET"
155           path     = "/minio/health/live"
156           interval = "10s"
157           timeout  = "2s"
158           task     = "${TASK}"
159         }
160       }
161
162       # The "resources" stanza describes the requirements a task needs to
163       # execute. Resource requirements include memory, network, cpu, and more.
164       # This ensures the task will execute on a machine that contains enough
165       # resource capacity.
166       #
167       # For more information and examples on the "resources" stanza, please see
168       # the online documentation at:
169       #
170       #     https://www.nomadproject.io/docs/job-specification/resources.html
171       #
172       resources {
173         cpu        = 2000
174         memory     = 2048
175         network {
176           port "http" {
177             static = 9000
178           }
179         }
180       }
181     }
182
183     task "prod-task2-sync" {
184       # The "raw_exec" parameter specifies the task driver that should be used
185       # to run the task.
186       driver = "raw_exec"
187
188       # The "template" stanza instructs Nomad to manage a template, such as
189       # a configuration file or script. This template can optionally pull data
190       # from Consul or Vault to populate runtime configuration data.
191       #
192       # For more information and examples on the "template" stanza, please see
193       # the online documentation at:
194       #
195       #     https://www.nomadproject.io/docs/job-specification/template.html
196       #
197       template {
198         data        = <<EOH
199 #!/bin/bash
200
201 INOTIFY_OPTONS="--recursive --monitor"
202 VOLUMES="/data/logs.fd.io /data/docs.fd.io"
203
204 if [ '{{ env "attr.unique.network.ip-address" }}' = "10.32.8.14" ]; then
205 echo "Running notify daemon"
206     inotifywait -e moved_to ${INOTIFY_OPTONS} ${VOLUMES} | \
207         while read path action file; do
208             key="testuser"
209             secret="Csit1234"
210
211             resource=${path#"/data"}${file}
212             date=$(date -R)
213             _signature="PUT\n\napplication/octet-stream\n${date}\n${resource}"
214             signature=$(echo -en ${_signature} | openssl sha1 -hmac ${secret} -binary | base64)
215
216             curl -v -X PUT -T "${path}${file}" \
217                 -H "Host: storage0.storage.service.consul:9000" \
218                 -H "Date: ${date}" \
219                 -H "Content-Type: application/octet-stream" \
220                 -H "Authorization: AWS ${key}:${signature}" \
221                 http://storage0.storage.service.consul:9000${resource}
222         done
223 else
224     while :; do sleep 2073600; done
225 fi
226
227 EOH
228         destination = "local/sync.sh"
229         perms       = "755"
230       }
231
232       # The "config" stanza specifies the driver configuration, which is passed
233       # directly to the driver to start the task. The details of configurations
234       # are specific to each driver, so please see specific driver
235       # documentation for more information.
236       config {
237         command     = "local/sync.sh"
238       }
239
240       # The "resources" stanza describes the requirements a task needs to
241       # execute. Resource requirements include memory, network, cpu, and more.
242       # This ensures the task will execute on a machine that contains enough
243       # resource capacity.
244       #
245       # For more information and examples on the "resources" stanza, please see
246       # the online documentation at:
247       #
248       #     https://www.nomadproject.io/docs/job-specification/resources.html
249       #
250       resources {
251         cpu         = 500
252         memory      = 256
253       }
254     }
255   }
256 }