-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yaml
249 lines (243 loc) · 9.91 KB
/
docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Kibana/Elastic Setup
# Add the following lines for more nodes between lines 46 and 47
# See for reference: https://github.com/elastic/elasticsearch/blob/8.17/docs/reference/setup/install/docker/docker-compose.yml
# " - name: es02\n"\
# " dns:\n"\
# " - es02\n"\
# " - localhost\n"\
# " ip:\n"\
# " - 127.0.0.1\n"\
# " - name: es03\n"\
# " dns:\n"\
# " - es03\n"\
# " - localhost\n"\
# " ip:\n"\
# " - 127.0.0.1\n"\
services:
setup:
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- certs:/usr/share/elasticsearch/config/certs
- shared_secrets:/usr/share/elasticsearch/shared_secrets
- ./mapping.json:/usr/share/elasticsearch/mapping.json
- ./model_mapping.json:/usr/share/elasticsearch/model_mapping.json
# - ./.env:/usr/share/elasticsearch/.env
# - ./store_initial_model_metrics_in_elastic.py:/usr/share/elasticsearch/store_initial_model_metrics_in_elastic.py
user: "0"
command: >
bash -c '
if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1;
fi;
if [ ! -f config/certs/ca.zip ]; then
echo "Creating CA";
bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
unzip config/certs/ca.zip -d config/certs;
fi;
if [ ! -f config/certs/certs.zip ]; then
echo "Creating certs";
echo -ne \
"instances:\n"\
" - name: es01\n"\
" dns:\n"\
" - es01\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
> config/certs/instances.yml;
bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
unzip config/certs/certs.zip -d config/certs;
fi;
echo "Setting file permissions"
chown -R root:root config/certs;
find . -type d -exec chmod 750 \{\} \;;
find . -type f -exec chmod 640 \{\} \;;
echo "Waiting for Elasticsearch availability";
until curl -s --cacert config/certs/ca/ca.crt https://es01:9200 | grep -q "missing authentication credentials"; do sleep 5; done;
if [ ! -e /usr/share/elasticsearch/shared_secrets/not_first_start ]; then
echo "-- First container startup --"
# JUST_ONCE_LOGIC_HERE
echo "Importing network_flow mapping";
until curl -u elastic:${ELASTIC_PASSWORD} -X PUT "https://es01:9200/${NETWORK_FLOW_INDEX_NAME}" -H "Content-Type: application/json" -d @/usr/share/elasticsearch/mapping.json --insecure; do sleep 5; done;
echo "Importing model mapping";
until curl -u elastic:${ELASTIC_PASSWORD} -X PUT "https://es01:9200/${MODEL_DATA_INDEX_NAME}" -H "Content-Type: application/json" -d @/usr/share/elasticsearch/model_mapping.json --insecure; do sleep 5; done;
echo "Writing api-token for ${NETWORK_FLOW_INDEX_NAME}" into file server-api-key.txt;
until curl -X POST "https://es01:9200/_security/api_key" -u elastic:${ELASTIC_PASSWORD} -H "Content-Type: application/json" --insecure -d "{
\"name\": \"server_key_generated_from_setup\",
\"role_descriptors\": {
\"sensor_read_and_write_flows\": {
\"index\": [
{
\"names\": [\"${NETWORK_FLOW_INDEX_NAME}\", \"${MODEL_DATA_INDEX_NAME}\"],
\"privileges\": [ \"all\" ]
}
]
}
}
}" | sed -e "s/.*encoded\":/ELASTIC_SERVER_KEY=/" | sed -e "s/}//" > /usr/share/elasticsearch/shared_secrets/server-api-key.env; do sleep 5; done;
echo "All done!";
touch /usr/share/elasticsearch/shared_secrets/not_first_start
echo "Creating file as flag for first Startup"
touch /usr/share/elasticsearch/shared_secrets/upload_initial_model_metrics
# chmod 666 /usr/share/elasticsearch/keys/elastic-sensor-token.txt;
# echo "Use this api-key: $(cat /usr/share/elasticsearch/keys/elastic-sensor-token.txt) for your sensors! ";
else
echo "-- Not the first container startup, so other initialisation is skipped --"
fi
'
healthcheck:
test: ["CMD-SHELL", "[ -f config/certs/es01/es01.crt ]"]
interval: 1s
timeout: 5s
retries: 120
es01:
depends_on:
setup:
condition: service_healthy
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- certs:/usr/share/elasticsearch/config/certs
- esdata01:/usr/share/elasticsearch/data
ports:
- ${ES_PORT}:9200
environment:
- node.name=es01
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01 #,es02,es03 # Uncomment for extra nodes
# Uncomment for extra nodes
# - discovery.seed_hosts=es02,es03
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/es01/es01.key
- xpack.security.http.ssl.certificate=certs/es01/es01.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/es01/es01.key
- xpack.security.transport.ssl.certificate=certs/es01/es01.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
- xpack.ml.use_auto_machine_memory_percent=true
- ES_JAVA_OPTS=${ES_JAVA_OPTS}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
# Uncomment for extra nodes
# es02:
# depends_on:
# - es01
# image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
# volumes:
# - certs:/usr/share/elasticsearch/config/certs
# - esdata02:/usr/share/elasticsearch/data
# environment:
# - node.name=es02
# - cluster.name=${CLUSTER_NAME}
# - cluster.initial_master_nodes=es01,es02,es03
# - discovery.seed_hosts=es01,es03
# - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
# - bootstrap.memory_lock=true
# - xpack.security.enabled=true
# - xpack.security.http.ssl.enabled=true
# - xpack.security.http.ssl.key=certs/es02/es02.key
# - xpack.security.http.ssl.certificate=certs/es02/es02.crt
# - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
# - xpack.security.transport.ssl.enabled=true
# - xpack.security.transport.ssl.key=certs/es02/es02.key
# - xpack.security.transport.ssl.certificate=certs/es02/es02.crt
# - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
# - xpack.security.transport.ssl.verification_mode=certificate
# - xpack.license.self_generated.type=${LICENSE}
# - xpack.ml.use_auto_machine_memory_percent=true
# mem_limit: ${MEM_LIMIT}
# ulimits:
# memlock:
# soft: -1
# hard: -1
# healthcheck:
# test:
# [
# "CMD-SHELL",
# "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
# ]
# interval: 10s
# timeout: 10s
# retries: 120
# es03:
# depends_on:
# - es02
# image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
# volumes:
# - certs:/usr/share/elasticsearch/config/certs
# - esdata03:/usr/share/elasticsearch/data
# environment:
# - node.name=es03
# - cluster.name=${CLUSTER_NAME}
# - cluster.initial_master_nodes=es01,es02,es03
# - discovery.seed_hosts=es01,es02
# - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
# - bootstrap.memory_lock=true
# - xpack.security.enabled=true
# - xpack.security.http.ssl.enabled=true
# - xpack.security.http.ssl.key=certs/es03/es03.key
# - xpack.security.http.ssl.certificate=certs/es03/es03.crt
# - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
# - xpack.security.transport.ssl.enabled=true
# - xpack.security.transport.ssl.key=certs/es03/es03.key
# - xpack.security.transport.ssl.certificate=certs/es03/es03.crt
# - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
# - xpack.security.transport.ssl.verification_mode=certificate
# - xpack.license.self_generated.type=${LICENSE}
# - xpack.ml.use_auto_machine_memory_percent=true
# mem_limit: ${MEM_LIMIT}
# ulimits:
# memlock:
# soft: -1
# hard: -1
# healthcheck:
# test:
# [
# "CMD-SHELL",
# "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
# ]
# interval: 10s
# timeout: 10s
# retries: 120
dash-server:
build:
context: .
dockerfile: DOCKERFILE
depends_on:
setup:
condition: service_completed_successfully
volumes:
- certs:/usr/share/elasticsearch/config/certs # TODO import these certs!
- shared_secrets:/shared_secrets
- ./instance:/dash/instance
ports:
- ${FLASK_PORT}:5000
environment:
- TZ=Europe/Berlin
- ES_PORT=9200
- FLASK_PORT_NUMBER=${FLASK_PORT}
volumes:
certs:
driver: local
esdata01:
driver: local
shared_secrets:
driver: local