forked from aneoconsulting/ArmoniK.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
288 lines (230 loc) · 9.84 KB
/
justfile
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# Enable positional args
set positional-arguments
# Enable bash output
set shell := ["bash", "-exc"]
# Default values for the deployment
tag := "0.0.0.0-local"
local_images := "false"
log_level := "Information"
queue := "activemq"
worker := "htcmock"
object := "redis"
replicas := "3"
partitions := "2"
builder := "regular"
platform := "linux/arm64"
# Export them as terraform environment variables
export TF_VAR_core_tag := tag
export TF_VAR_use_local_image := local_images
export TF_VAR_serilog := '{ loggin_level = "' + log_level + '" }'
export TF_VAR_num_replicas := replicas
export TF_VAR_num_partitions := partitions
# Sets the queue
export TF_VAR_queue_storage := if queue == "rabbitmq" {
'{ name = "rabbitmq", image = "rabbitmq:3-management" }'
} else if queue == "rabbitmq091" {
'{ name = "rabbitmq", image = "rabbitmq:3-management", protocol = "amqp0_9_1" }'
} else if queue == "artemis" {
'{ name = "artemis", image = "quay.io/artemiscloud/activemq-artemis-broker:artemis.2.28.0" }'
} else if queue == "activemq" {
'{ name = "activemq", image = "symptoma/activemq:5.16.3" }'
} else {
'{ name = "none" }'
}
# Sets the object storage
export TF_VAR_object_storage := if object == "redis" {
'{ name = "redis", image = "redis:bullseye" }'
} else if object == "minio" {
'{ name = "minio", image = "quay.io/minio/minio" }'
} else {
'{ name = "local", image = "" }'
}
# Defines worker and environment variables for deployment
image_worker := if worker == "stream" {
"dockerhubaneo/armonik_core_stream_test_worker"
} else if worker == "bench" {
"dockerhubaneo/armonik_core_bench_test_worker"
} else {
"dockerhubaneo/armonik_core_htcmock_test_worker"
}
# The path is given relative to ArmoniK.Core's root directory
dockerfile_worker := if worker == "stream" {
"./Tests/Stream/Server/"
} else if worker == "bench" {
"./Tests/Bench/Server/src/"
} else {
"./Tests/HtcMock/Server/src/"
}
export TF_VAR_worker_image := env_var_or_default('WORKER_IMAGE', image_worker)
export TF_VAR_worker_docker_file_path := env_var_or_default('WORKER_DOCKER_FILE_PATH', dockerfile_worker)
# Armonik docker image names
image_metrics := env_var_or_default('METRICS_IMAGE', "dockerhubaneo/armonik_control_metrics")
image_partition_metrics := env_var_or_default('PARTITION_METRICS_IMAGE', "dockerhubaneo/armonik_control_partition_metrics")
image_submitter := env_var_or_default('SUBMITTER_IMAGE', "dockerhubaneo/armonik_control")
image_polling_agent := env_var_or_default('POLLING_AGENT_IMAGE', "dockerhubaneo/armonik_pollingagent")
image_client_mock := env_var_or_default('MOCK_CLIENT_IMAGE', "dockerhubaneo/armonik_core_htcmock_test_client")
image_client_bench := env_var_or_default('BENCH_CLIENT_IMAGE', "dockerhubaneo/armonik_core_bench_test_client")
image_client_stream := env_var_or_default('STREAM_CLIENT_IMAGE', "dockerhubaneo/armonik_core_stream_test_client")
# Armonik docker images full name (image + tag)
export ARMONIK_METRICS := image_metrics + ":" + tag
export ARMONIK_PARTITIONMETRICS := image_partition_metrics + ":" + tag
export ARMONIK_SUBMITTER := image_submitter + ":" + tag
export ARMONIK_POLLINGAGENT := image_polling_agent + ":" + tag
export HTCMOCK_CLIENT_IMAGE := image_client_mock + ":" + tag
export STREAM_CLIENT_IMAGE := image_client_stream + ":" + tag
export BENCH_CLIENT_IMAGE := image_client_bench + ":" + tag
export TF_VAR_submitter := '{ image = "' + image_submitter + '" }'
export TF_VAR_compute_plane := '{ polling_agent = { image = "' + image_polling_agent + '" }, worker = {}}'
export TF_VAR_armonik_metrics_image := image_metrics
export TF_VAR_armonik_partition_metrics_image := image_partition_metrics
# List recipes and their usage
@default:
just --list
just _usage
_usage:
#!/usr/bin/env bash
set -euo pipefail
cat <<-EOF
The recipe deploy takes variables
usage: just tag=<tag> queue=<queue> worker=<worker> object=<object> replicas=<replicas> partitions=<number of partitions> local_images=<bool> deploy
if any of the variables is not set, its default value is used
tag: The core tag image to use, defaults to 0.0.0.0-local
queue: allowed values below
activemq : for activemq (1.0.0 protocol) (default)
rabbitmq : for rabbitmq (1.0.0 protocol)
rabbitmq091 : for rabbitmq (0.9.1 protocol)
artemis : for artemis (1.0.0 protocol)
worker: allowed values below
htcmock: for HtcMock V3 (default)
stream: for Stream worker
bench: for Benchmark worker
It is possible to use a custom worker, this is handled by
defining either of the following environment variables:
WORKER_IMAGE: to pull an already compiled image
WORKER_DOCKER_FILE_PATH: to compile the image locally
object: allowed values below
redis: to use redis for object storage (default)
minio: to use minio for object storage.
local: to mount a local volume for object storage
replicas: Number of polling agents / worker to be replicated (default = 3)
partitions: Number of partitions (default = 2)
local_images: Let terraform build the docker images locally (default = false)
IMPORTANT: In order to properly destroy the resources created you should call the recipe destroy with the
same parameters used for deploy
EOF
env:
env
# Call terraform init
init:
terraform -chdir=./terraform init -upgrade
# Validate deployment
validate:
terraform -chdir=./terraform validate
# Invoke terraform console
console:
terraform -chdir=./terraform console
# Plan ArmoniK Core deployment
plan: (init)
terraform -chdir=./terraform plan -out=/dev/null
# Deploy ArmoniK Core
deploy: (init)
terraform -chdir=./terraform apply -auto-approve
# Deploy target: object standalone
deployTargetObject: (init)
terraform -chdir=./terraform apply -target="module.object_{{object}}" -auto-approve
# Destroy target: queue standalone
destroyTargetObject:
terraform -chdir=./terraform destroy -target="module.object_{{object}}" -auto-approve
# Deploy target: queue standalone
deployTargetQueue: (init)
#!/usr/bin/env bash
which_module="module.queue_{{queue}}"
if [ {{queue}} = "rabbitmq091" ]; then
which_module="module.queue_rabbitmq"
fi
terraform -chdir=./terraform apply -target="${which_module}" -auto-approve
# Destroy target: queue standalone
destroyTargetQueue:
#!/usr/bin/env bash
which_module="module.queue_{{queue}}"
if [ {{queue}} = "rabbitmq091" ]; then
which_module="module.queue_rabbitmq"
fi
terraform -chdir=./terraform destroy -target="${which_module}" -auto-approve
# Destroy ArmoniK Core
destroy:
terraform -chdir=./terraform destroy -auto-approve
# Custom docker generic rule
container *args:
docker container "$@"
# Custom command to stop the given service
stop serviceName: (container "stop" serviceName)
# Custom command to start the given service
start serviceName: (container "start" serviceName)
# Custom command to restart the given service
restart serviceName: (container "restart" serviceName)
# Custom command to build a single image
build imageTag dockerFile target="":
#!/usr/bin/env bash
target_parameter=""
if [ "{{target}}" != "" ]; then
target_parameter="--target {{target}}"
fi
set -x
case "{{builder}}" in
regular)
docker build --build-arg VERSION={{tag}} $target_parameter -t "{{imageTag}}" -f "{{dockerFile}}" ./
;;
buildx)
docker buildx build --push --progress=plain --platform {{platform}} --build-arg VERSION={{tag}} $target_parameter -t "{{imageTag}}" -f "{{dockerFile}}" ./
;;
*)
echo wrong builder
exit 1
;;
esac
# Build Worker
buildWorker: (build TF_VAR_worker_image + ":" + tag TF_VAR_worker_docker_file_path + "Dockerfile")
# Build Metrics
buildMetrics: (build ARMONIK_METRICS "./Dockerfile" "metrics")
# Build Partition Metrics
buildPartitionMetrics: (build ARMONIK_PARTITIONMETRICS "./Dockerfile" "partition_metrics")
# Build Submitter
buildSubmitter: (build ARMONIK_SUBMITTER "./Dockerfile" "submitter")
# Build Polling Agent
buildPollingAgent: (build ARMONIK_POLLINGAGENT "./Dockerfile" "polling_agent")
# Build Htcmock Client
buildHtcmockClient: (build HTCMOCK_CLIENT_IMAGE "./Tests/HtcMock/Client/src/Dockerfile")
# Build Stream Client
buildStreamClient: (build STREAM_CLIENT_IMAGE "./Tests/Stream/Client/Dockerfile")
# Build Bench Client
buildBenchClient: (build BENCH_CLIENT_IMAGE "./Tests/Bench/Client/src/Dockerfile")
# Build all images necessary for the deployment
build-core: buildMetrics buildPartitionMetrics buildSubmitter buildPollingAgent
# Build all images necessary for the deployment and the worker
build-all: buildWorker build-core
# Build and Deploy ArmoniK Core; this recipe should only be used with local_images=false
build-deploy: build-all deploy
# Custom command to restore a deployment after restarting a given service
restoreDeployment serviceName: (restart serviceName) (restart "armonik.control.submitter")
#!/usr/bin/env bash
set -euo pipefail
for (( i=0; i<{{replicas}}; i++ )); do
docker container restart "armonik.compute.pollingagent${i}"
done
# Remove dangling images
remove-dangling:
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi
# Run health checks
healthChecks:
#!/usr/bin/env bash
set -euo pipefail
for (( i=0; i<{{replicas}}; i++ )); do
echo -e "\nHealth Checking PollingAggent${i}"
echo -n " startup: " && curl -sSL localhost:998${i}/startup
echo -n " liveness: " && curl -sSL localhost:998${i}/liveness
echo -n " readiness: " && curl -sSL localhost:998${i}/readiness
done
echo -e "\nHealth Checking Submitter"
echo -n " startup: " && curl -sSL localhost:5011/startup
echo -n " liveness: " && curl -sSL localhost:5011/liveness