-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstage_spacefx.sh
executable file
·648 lines (501 loc) · 29.5 KB
/
stage_spacefx.sh
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
#!/bin/bash
#
# Main entry point to download all dependencies and artifacts to use the Microsoft Azure Orbital Space SDK in an airgapped, non-internet connected environment.
#
# Example Usage:
#
# "bash ./scripts/stage_spacefx.sh [--architecture arm64 | amd64] [--dev-environment]"
# Load the modules and pass all the same parameters that we're passing here
# shellcheck disable=SC1091
# shellcheck disable=SC2068
source "$(dirname "$(realpath "$0")")/../modules/load_modules.sh" $@
############################################################
# Script variables
############################################################
NVIDIA_GPU_PLUGIN=false
SMB_ENABLED=false
CONTAINERS=()
BUILD_ARTIFACTS=()
DEV_ENVIRONMENT=false
SPACEFX_REGISTRY=""
SPACEFX_REPO_PREFIX=""
SPACEFX_VERSION_TAG=""
SPACEFX_VERSION_BASE_TAG=""
VTH_ENABLED=false
############################################################
# Help #
############################################################
function show_help() {
# Display Help
echo "Main entry point to download all dependencies and artifacts to use the Microsoft Azure Orbital Space SDK in an airgapped, non-internet connected environment."
echo
echo "Syntax: bash ./scripts/stage_spacefx.sh [--architecture arm64 | amd64]"
echo "options:"
echo "--architecture | -a [OPTIONAL] Change the target architecture for download (defaults to current architecture)"
echo "--dev-environment | -d [OPTIONAL] Setup the environment to support development. This will enable VTH and downloads full size service container images."
echo "--vth | -v [OPTIONAL] Enable Virtual Test Harness (VTH)."
echo "--artifact [OPTIONAL] Add a build artifact to download and stage. Must have match in buildartifacts.json. Can be passed multiple times"
echo "--smb [OPTIONAL] Enable SMB support in the FileServer component for multi-node clusters."
echo "--container | -c [OPTIONAL] name of the container to pull. Can be passed multiple times"
echo "--nvidia-gpu-plugin | -n [OPTIONAL] Include the nvidia gpu plugin (+325 MB)"
echo "--help | -h [OPTIONAL] Help script (this screen)"
echo
exit 1
}
############################################################
# Process the input options.
############################################################
while [[ "$#" -gt 0 ]]; do
case $1 in
-e|--env) echo "[WARNING] DEPRECATED: this parameter has been deprecated and no longer used. Please update your scripts accordingly." ;;
-a | --architecture)
shift
ARCHITECTURE=$1
ARCHITECTURE=${ARCHITECTURE,,} # Force to lowercase
if [[ ! "${ARCHITECTURE}" == "amd64" ]] && [[ ! "${ARCHITECTURE}" == "arm64" ]]; then
echo "--architecture must be 'amd64' or 'arm64'. '${ARCHITECTURE}' is not valid."
show_help
exit 1
fi
;;
--nvidia-gpu-plugin)
NVIDIA_GPU_PLUGIN=true
;;
--smb)
SMB_ENABLED=true
;;
-d | --dev-environment)
DEV_ENVIRONMENT=true
VTH_ENABLED=true
;;
-v | --vth)
VTH_ENABLED=true
;;
-c|--container)
shift
CONTAINERS+=("$1")
;;
--artifact)
shift
BUILD_ARTIFACTS+=("$1")
;;
-h|--help) show_help ;;
*) echo "Unknown parameter '$1'"; show_help ;;
esac
shift
done
if [[ -z "${ARCHITECTURE}" ]]; then
case $(uname -m) in
x86_64) ARCHITECTURE="amd64" ;;
aarch64) ARCHITECTURE="arm64" ;;
esac
fi
############################################################
# All the Azure Orbital Space SDK containers are in the same registry. This speeds up the calculation by eliminating the need to recalculate the registry for each container
############################################################
function calculate_spacefx_registry(){
info_log "START: ${FUNCNAME[0]}"
debug_log "Locating parent registry and calculating tags for '${REGISTRY_REPO}'..."
calculate_tag_from_channel --tag "${SPACEFX_VERSION}" --result SPACEFX_VERSION_TAG
calculate_tag_from_channel --tag "${SPACEFX_VERSION}_base" --result SPACEFX_VERSION_BASE_TAG
info_log "SPACEFX_VERSION_TAG calculated as '${SPACEFX_VERSION_TAG}'"
info_log "SPACEFX_VERSION_BASE_TAG calculated as '${SPACEFX_VERSION_BASE_TAG}'"
find_registry_for_image "spacesdk-base:${SPACEFX_VERSION_TAG}" SPACEFX_REGISTRY
info_log "SPACEFX_REGISTRY calculated as '${SPACEFX_REGISTRY}'"
if [[ -z "${SPACEFX_REGISTRY}" ]]; then
exit_with_error "Unable to find a registry for 'spacesdk-base:${SPACEFX_VERSION_TAG}'. Please check that you have the right channel, that you have access to all the container registries in ${SPACEFX_DIR}/config/*.yaml, login to all container registries in ${SPACEFX_DIR}/config/*.yaml (if applicable), and/or update your ${SPACEFX_DIR}/config/*.yaml to include a container registry with spacesdk-base:${SPACEFX_VERSION_TAG}."
fi
check_for_repo_prefix_for_registry --registry "${SPACEFX_REGISTRY}" --result SPACEFX_REPO_PREFIX
info_log "SPACEFX_REPO_PREFIX calculated as '${SPACEFX_REPO_PREFIX}'"
info_log "SPACEFX_REGISTRY calculated as '${SPACEFX_REGISTRY}'"
info_log "SPACEFX_VERSION_TAG calculated as '${SPACEFX_VERSION_TAG}'"
info_log "SPACEFX_REPO_PREFIX calculated as '${SPACEFX_REPO_PREFIX}'"
write_parameter_to_log SPACEFX_REPO_PREFIX
write_parameter_to_log SPACEFX_REGISTRY
write_parameter_to_log SPACEFX_VERSION_TAG
write_parameter_to_log SPACEFX_VERSION_BASE_TAG
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Loop through any extra containers in config and add them to the pull
############################################################
function add_extra_containers_from_config(){
info_log "START: ${FUNCNAME[0]}"
run_a_script "jq -r '.config.extraContainers[] | @base64' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" extra_containers --disable_log
info_log "Checking for extra containers from config..."
for row in $extra_containers; do
parse_json_line --json "${row}" --property ".repository" --result container_repository
parse_json_line --json "${row}" --property ".tag" --result container_tag
parse_json_line --json "${row}" --property ".appendChannel" --result container_appendChannel
if [[ "${container_appendChannel}" == "true" ]]; then
calculate_tag_from_channel --tag "${container_tag}" --result container_tag
fi
info_log "...adding '${container_repository}:${container_tag}'..."
CONTAINERS+=("${container_repository}:${container_tag}")
done
info_log "...successfully added config extra containers to queue."
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Enable FileServer components if user has requested it
############################################################
function enable_fileserver(){
info_log "START: ${FUNCNAME[0]}"
info_log "Setting SMB to ${SMB_ENABLED}..."
local _environments=("prod" "dev")
for i in "${!_environments[@]}"; do
_environment=${_environments[i]}
run_a_script "yq eval '.services.core.fileserver.${_environment}.enabled = ${SMB_ENABLED}' -i \"${SPACEFX_DIR}/chart/values.yaml\""
run_a_script "yq eval '.services.core.fileserver.${_environment}.pull = ${SMB_ENABLED}' -i \"${SPACEFX_DIR}/chart/values.yaml\""
done
run_a_script "yq eval '(.config.charts[] | select(.group == \"smb\") .enabled) = ${SMB_ENABLED}' -i \"${SPACEFX_DIR}/config/0_spacesdk-base.yaml\""
run_a_script "yq eval '.global.fileserverSMB = ${SMB_ENABLED}' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "...successfully set SMB to ${SMB_ENABLED}."
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Toggle devEnvironment setting if requested
############################################################
function toggle_dev_environment(){
info_log "START: ${FUNCNAME[0]}"
info_log "Setting DevEnvironment to ${DEV_ENVIRONMENT}..."
run_a_script "yq eval '.global.devEnvironment = ${DEV_ENVIRONMENT}' -i \"${SPACEFX_DIR}/chart/values.yaml\""
if [[ "${DEV_ENVIRONMENT}" == true ]]; then
run_a_script "yq eval '.global.dapr.logLevel = \"debug\"' -i \"${SPACEFX_DIR}/chart/values.yaml\""
else
run_a_script "yq eval '.global.dapr.logLevel = \"warn\"' -i \"${SPACEFX_DIR}/chart/values.yaml\""
fi
info_log "...successfully set DevEnvironment to ${DEV_ENVIRONMENT}..."
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Toggle the nvidia GPU setting if requested
############################################################
function toggle_nvidia_gpu(){
info_log "START: ${FUNCNAME[0]}"
if [[ "${NVIDIA_GPU_PLUGIN}" == true ]]; then
info_log "'NVIDIA_GPU_PLUGIN' = true. Enabling nVidia GPU in config..."
run_a_script "yq eval '(.config.charts[] | select(.group == \"nvidia_gpu\") .enabled) = true' -i \"${SPACEFX_DIR}/config/0_spacesdk-base.yaml\""
info_log "...nVidia GPU successfully enabled."
else
info_log "'NVIDIA_GPU_PLUGIN' = false. Disabling nVidia GPU in config..."
run_a_script "yq eval '(.config.charts[] | select(.group == \"nvidia_gpu\") .enabled) = false' -i \"${SPACEFX_DIR}/config/0_spacesdk-base.yaml\""
info_log "...nVidia GPU successfully disabled."
fi
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Toggle the security restrictions between dev versus prod
############################################################
function toggle_security_restrictions(){
info_log "START: ${FUNCNAME[0]}"
if [[ "${DEV_ENVIRONMENT}" == true ]]; then
info_log "'DEV_ENVIRONMENT' = true. Disabling Network Restrictions..."
run_a_script "yq eval '.global.security.payloadAppNetworkRestrictionsEnabled = false' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "'DEV_ENVIRONMENT' = true. Disabling Topic Restrictions..."
run_a_script "yq eval '.global.security.topicRestrictionEnabled = false' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "'DEV_ENVIRONMENT' = true. Allowing Links to Platform-Deployment..."
run_a_script "yq eval '(.services.host.link.appConfig[] | select(.name == \"allowLinksToDeploymentSvc\") .value) = true' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "'DEV_ENVIRONMENT' = true. Enabling run as root..."
run_a_script "yq eval '.global.security.forceNonRoot = false' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "...security restrictions configured for development"
else
info_log "'DEV_ENVIRONMENT' = false. Enabling Network Restrictions..."
run_a_script "yq eval '.global.security.payloadAppNetworkRestrictionsEnabled = true' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "'DEV_ENVIRONMENT' = true. Enabling Topic Restrictions..."
run_a_script "yq eval '.global.security.topicRestrictionEnabled = true' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "'DEV_ENVIRONMENT' = false. Disabling Links to Platform-Deployment..."
run_a_script "yq eval '(.services.host.link.appConfig[] | select(.name == \"allowLinksToDeploymentSvc\") .value) = false' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "...Network and Topic restrictions successfully enabled."
info_log "'DEV_ENVIRONMENT' = true. Enabling run as root..."
run_a_script "yq eval '.global.security.forceNonRoot = true' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "...security restrictions configured for production"
fi
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Enable VTH if it's not already enabled
############################################################
function enable_vth(){
info_log "START: ${FUNCNAME[0]}"
if [[ "${VTH_ENABLED}" == true ]]; then
info_log "'VTH_ENABLED' = true. Enabling VTH..."
run_a_script "yq eval '.services.platform.vth.prod.enabled = true' -i \"${SPACEFX_DIR}/chart/values.yaml\""
run_a_script "yq eval '.services.platform.vth.dev.enabled = true' -i \"${SPACEFX_DIR}/chart/values.yaml\""
info_log "...successfully enabled VTH."
else
info_log "'VTH_ENABLED' = false. Nothing to do"
fi
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Stage core-registry tarball so we can start it up on the k3s side
############################################################
function stage_coresvc_registry(){
info_log "START: ${FUNCNAME[0]}"
if [[ -f "${SPACEFX_DIR}/images/${ARCHITECTURE}/coresvc-registry_${SPACEFX_VERSION}.tar" ]]; then
info_log "Coresvc-registry already staged to '${SPACEFX_DIR}/images/${ARCHITECTURE}/coresvc-registry_${SPACEFX_VERSION}.tar'. Nothing to do."
info_log "FINISHED: ${FUNCNAME[0]}"
return
fi
create_directory "${SPACEFX_DIR}/images/${ARCHITECTURE}"
debug_log "Calculating registry repository name..."
run_a_script "yq '.services.core.registry.repository' ${SPACEFX_DIR}/chart/values.yaml" REGISTRY_REPO
debug_log "...registry repository name calculated as '${REGISTRY_REPO}'"
get_image_name --registry "${SPACEFX_REGISTRY}" --repo "${REGISTRY_REPO}" --result _stage_registry_image_name
# Check to see if the image is already in docker
run_a_script "docker images --format '{{json .}}' --no-trunc | jq -r '. | select(.Repository == \"${_stage_registry_image_name}\" and .Tag == \"${SPACEFX_VERSION_TAG}\") | any'" has_docker_image --ignore_error
if [[ "${has_docker_image}" == "true" ]]; then
info_log "...image ${_stage_registry_image_name}:${SPACEFX_VERSION_TAG} already exists in Docker. Nothing to do"
else
info_log "...image ${_stage_registry_image_name}:${SPACEFX_VERSION_TAG} not found in Docker. Pulling..."
run_a_script "docker pull ${_stage_registry_image_name}:${SPACEFX_VERSION_TAG} --platform 'linux/${ARCHITECTURE}'"
run_a_script "yq '.services.core.registry.repository' ${SPACEFX_DIR}/chart/values.yaml" _stage_REGISTRY_DEST_REPO
run_a_script "yq '.global.containerRegistry' ${SPACEFX_DIR}/chart/values.yaml" _stage_DEST_REGISTRY
run_a_script "docker tag ${_stage_registry_image_name}:${SPACEFX_VERSION_TAG} ${_stage_DEST_REGISTRY}/${_stage_REGISTRY_DEST_REPO}:${SPACEFX_VERSION}"
info_log "...successfully pulled ${_stage_registry_image_name}:${SPACEFX_VERSION_TAG} to Docker."
fi
create_directory "${SPACEFX_DIR}/images/${ARCHITECTURE}"
run_a_script "docker save ${_stage_registry_image_name}:${SPACEFX_VERSION_TAG} --output ${SPACEFX_DIR}/images/${ARCHITECTURE}/coresvc-registry_${SPACEFX_VERSION}.tar"
if [[ "${ARCHITECTURE}" != "${HOST_ARCHITECTURE}" ]]; then
info_log "Detected cross-architecture staging. Removing non-platform coresvc-registry image from Docker..."
run_a_script "docker rmi ${_stage_registry_image_name}:${SPACEFX_VERSION_TAG}" --ignore_error
run_a_script "docker rmi ${_stage_DEST_REGISTRY}/${_stage_REGISTRY_DEST_REPO}:${SPACEFX_VERSION}" --ignore_error
info_log "...successfully removed non-platform coresvc-registry image from Docker."
fi
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Stage all the service images for a given service group
############################################################
function stage_spacefx_service_images(){
info_log "START: ${FUNCNAME[0]}"
local service_group=""
local stage_container_img_cmd=""
local enabled_filter="prod.pull"
local hasBase_selection="prod.hasBase"
if [[ "${DEV_ENVIRONMENT}" == true ]]; then
enabled_filter="dev.pull"
hasBase_selection="dev.hasBase"
fi
while [[ "$#" -gt 0 ]]; do
case $1 in
--service_group)
shift
service_group=$1
;;
esac
shift
done
info_log "Staging '${service_group}' spacefx services..."
run_a_script "yq '.' ${SPACEFX_DIR}/chart/values.yaml --output-format=json | jq '.services.${service_group} | to_entries[] | select(.value.${enabled_filter} == true) | .key' -r" spacefx_services
for service in $spacefx_services; do
run_a_script "yq '.' ${SPACEFX_DIR}/chart/values.yaml --output-format=json | jq '.services.${service_group}.${service}.repository' -r" service_repository
run_a_script "yq '.' ${SPACEFX_DIR}/chart/values.yaml --output-format=json | jq '.services.${service_group}.${service}.${hasBase_selection}' -r" service_hasBase --ignore_error
get_image_name --registry "${SPACEFX_REGISTRY}" --repo "${service_repository}" --result _stage_svc_image_name
if [[ "${service_hasBase}" == true ]]; then
info_log "...staging '${service}:${SPACEFX_VERSION_BASE_TAG}'..."
stage_container_img_cmd="${stage_container_img_cmd} --image ${_stage_svc_image_name}:${SPACEFX_VERSION_BASE_TAG}"
else
info_log "...staging '${service}'..."
stage_container_img_cmd="${stage_container_img_cmd} --image ${_stage_svc_image_name}:${SPACEFX_VERSION_TAG}"
fi
done
run_a_script "${SPACEFX_DIR}/scripts/stage/stage_container_image.sh --architecture ${ARCHITECTURE} ${stage_container_img_cmd}"
# Update to remove the prefixes on the service images in the registry
if [[ -n "${SPACEFX_REPO_PREFIX}" ]]; then
for service in $spacefx_services; do
local source_repo_name=""
local dest_repo_name=""
run_a_script "yq '.' ${SPACEFX_DIR}/chart/values.yaml --output-format=json | jq '.services.${service_group}.${service}.repository' -r" service_repository
run_a_script "yq '.' ${SPACEFX_DIR}/chart/values.yaml --output-format=json | jq '.services.${service_group}.${service}.${hasBase_selection}' -r" service_hasBase --ignore_error
source_repo_name="registry.spacefx.local/${SPACEFX_REPO_PREFIX}/${service_repository}:${SPACEFX_VERSION_TAG}"
dest_repo_name="registry.spacefx.local/${service_repository}:${SPACEFX_VERSION}"
if [[ "${service_hasBase}" == true ]]; then
source_repo_name="registry.spacefx.local/${SPACEFX_REPO_PREFIX}/${service_repository}:${SPACEFX_VERSION_BASE_TAG}"
dest_repo_name="registry.spacefx.local/${service_repository}:${SPACEFX_VERSION}_base"
fi
debug_log "Removing prefix and channel suffix from service repository '${service_repository}' by retagging '${source_repo_name}' to '${dest_repo_name}'..."
run_a_script "regctl image copy ${source_repo_name} ${dest_repo_name}"
info_log "...successfully updated ${source_repo_name} to ${dest_repo_name}"
done
fi
info_log "...'${service_group}' spacefx services successfully staged."
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Stage container images requested by the user
############################################################
function stage_container_images(){
info_log "START: ${FUNCNAME[0]}"
local containers_to_stage=""
# Regex pattern to match a container registry and image format like "registry/image:tag"
container_registry_pattern='^[a-zA-Z0-9.-]+\/[a-zA-Z0-9._-]+:[a-zA-Z0-9._-]+$'
full_image_names=()
if [[ ${#CONTAINERS[@]} -eq 0 ]]; then
info_log "...no containers requested. Nothing to do"
info_log "END: ${FUNCNAME[0]}"
return
fi
for i in "${!CONTAINERS[@]}"; do
CONTAINER=${CONTAINERS[i]}
_stage_container_full_image_name=""
if [[ $CONTAINER =~ $container_registry_pattern ]]; then
info_log "...'$CONTAINER' is a fully qualified container registry and image string. Skipping container registry search."
_stage_container_full_image_name="${CONTAINER}"
else
info_log "...'$CONTAINER' is not a fully qualified container registry and image string. Searching for container registry..."
find_registry_for_image "${CONTAINER}" _container_registry
[[ -z "${_container_registry}" ]] && exit_with_error "Unable to find a container registry with container image '${CONTAINER}'. Please recheck image name, and configured container registries in your config yamls"
get_image_name --registry "${_container_registry}" --repo "${CONTAINER}" --result _stage_container_full_image_name
full_image_names+=("${_stage_container_full_image_name}")
fi
containers_to_stage="${containers_to_stage} --image ${_stage_container_full_image_name}"
done
run_a_script "${SPACEFX_DIR}/scripts/stage/stage_container_image.sh --architecture ${ARCHITECTURE} ${containers_to_stage}"
# Loop through the images and update the registry to remove the prefix
for i in "${!full_image_names[@]}"; do
_full_container_name=${full_image_names[i]}
_container_registry=${_full_container_name%%/*}
debug_log "Checking if a prefix exists for '${_container_registry}'..."
check_for_repo_prefix_for_registry --registry "${_container_registry}" --result _container_registry_repo_prefix
if [[ -n "${_container_registry_repo_prefix}" ]]; then
# Remove ${_container_registry}/$_container_registry_repo_prefix from the image name and just have the container name
_container_repo=${_full_container_name#"${_container_registry}/${_container_registry_repo_prefix}/"}
info_log "...updating registry.spacefx.local/${_container_registry_repo_prefix}/${_container_repo} to registry.spacefx.local/${_container_repo}..."
run_a_script "regctl image copy registry.spacefx.local/${_container_registry_repo_prefix}/${_container_repo} registry.spacefx.local/${_container_repo}"
info_log "...successfully updated registry.spacefx.local/${_container_registry_repo_prefix}/${_container_repo} to registry.spacefx.local/${_container_repo}"
fi
if [[ ! $CONTAINER =~ $container_registry_pattern ]]; then
info_log "...'$CONTAINER' is not a fully qualified container registry and image string. Searching for container registry..."
find_registry_for_image "${CONTAINER}" _container_registry
[[ -z "${_container_registry}" ]] && exit_with_error "Unable to find a container registry with container image '${CONTAINER}'. Please recheck image name, and configured container registries in your config yamls"
get_image_name --registry "${_container_registry}" --repo "${CONTAINER}" --result _stage_container_full_image_name
fi
containers_to_stage="${containers_to_stage} --image ${_stage_container_full_image_name}"
done
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Stage spacefx-base
############################################################
function stage_build_artifacts(){
info_log "START: ${FUNCNAME[0]}"
local artifacts_to_stage=""
if [[ ${#BUILD_ARTIFACTS[@]} -eq 0 ]]; then
info_log "...no build artifacts requested. Nothing to do"
info_log "END: ${FUNCNAME[0]}"
return
fi
for i in "${!BUILD_ARTIFACTS[@]}"; do
artifacts_to_stage="${artifacts_to_stage} --artifact ${BUILD_ARTIFACTS[i]}"
done
run_a_script "${SPACEFX_DIR}/scripts/stage/stage_build_artifact.sh --architecture ${ARCHITECTURE} ${artifacts_to_stage}"
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Stage python wheels
############################################################
function stage_python_wheels(){
info_log "START: ${FUNCNAME[0]}"
# Stage the microsoft-azure-orbital-sdk wheel to the wheel directory
run_a_script "${SPACEFX_DIR}/scripts/stage/stage_build_artifact.sh --architecture ${ARCHITECTURE} --artifact microsoftazurespacefx-${SPACEFX_VERSION}-py3-none-any.whl"
# Find all wheels in the ${SPACEFX_DIR}/wheel directory and move them to the ${SPACEFX_DIR}/registry/pypiserver/packages directory
# Move only the wheel itself to the root level of the ${SPACEFX_DIR}/registry/pypiserver/packages directory and not the entire directory structure
# The pypiserver will detect these wheels and serve the python packages when it boots up
run_a_script "mkdir -p ${SPACEFX_DIR}/registry/pypiserver/packages"
run_a_script "find ${SPACEFX_DIR}/wheel -type f -name '*.whl' -exec mv {} ${SPACEFX_DIR}/registry/pypiserver/packages \;"
# Remove the wheel directory
run_a_script "rm -rf ${SPACEFX_DIR}/wheel"
info_log "FINISHED: ${FUNCNAME[0]}"
}
############################################################
# Loop through all the extra containers and retag them to remove the prefix from coresvc-registry
############################################################
function remove_channels_from_extra_containers(){
info_log "START: ${FUNCNAME[0]}"
run_a_script "jq -r '.config.extraContainers[] | @base64' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" extra_containers --disable_log
info_log "Retagging any extra containers in config that have the channel suffix..."
for row in $extra_containers; do
parse_json_line --json "${row}" --property ".repository" --result container_repository
parse_json_line --json "${row}" --property ".tag" --result container_tag
parse_json_line --json "${row}" --property ".appendChannel" --result container_appendChannel
if [[ "${container_appendChannel}" == "true" ]]; then
debug_log "Checking for channel suffix for '${container_repository}:${container_tag}'..."
calculate_tag_from_channel --tag "${container_tag}" --result container_tagWithChannel
if [[ "${container_tag}" != "${container_tagWithChannel}" ]]; then
info_log "...retagging '${container_repository}:${container_tagWithChannel}' to '${container_repository}:${container_tag}'..."
run_a_script "regctl image copy registry.spacefx.local/${container_repository}:${container_tagWithChannel} registry.spacefx.local/${container_repository}:${container_tag}"
info_log "...successfully retagged ${container_repository}:${container_tagWithChannel} to ${container_repository}:${container_tag}"
else
info_log "...container tag matches calculated container tag with channel. ('${container_tagWithChannel}' = '${container_tag}'). Nothing to do."
fi
else
debug_log "...container does not have channel suffix. Nothing to do."
fi
done
info_log "...extra containers with channel suffixes successfully retagged."
info_log "FINISHED: ${FUNCNAME[0]}"
}
function main() {
write_parameter_to_log ARCHITECTURE
write_parameter_to_log DEV_ENVIRONMENT
write_parameter_to_log NVIDIA_GPU_PLUGIN
write_parameter_to_log VTH_ENABLED
write_parameter_to_log SMB_ENABLED
for i in "${!CONTAINERS[@]}"; do
CONTAINER=${CONTAINERS[i]}
write_parameter_to_log CONTAINER
done
for i in "${!BUILD_ARTIFACTS[@]}"; do
BUILD_ARTIFACT=${BUILD_ARTIFACTS[i]}
write_parameter_to_log BUILD_ARTIFACT
done
is_cmd_available "docker" _docker_available
# shellcheck disable=SC2154
if [[ "${_docker_available}" == false ]]; then
exit_with_error "Docker cli is not available and is required for stage_spacefx.sh. Please install docker and try again."
fi
toggle_dev_environment
calculate_spacefx_registry
add_extra_containers_from_config
toggle_security_restrictions
toggle_nvidia_gpu
enable_vth
enable_fileserver
_generate_spacefx_config_json
info_log "Staging python wheels..."
stage_python_wheels
info_log "...successfully staged python wheels"
info_log "Staging coresvc-registry..."
stage_coresvc_registry
info_log "...successfully staged coresvc-registry"
local extra_args=""
info_log "Staging third party apps..."
run_a_script "${SPACEFX_DIR}/scripts/stage/stage_3p_apps.sh --architecture ${ARCHITECTURE}"
info_log "...successfully staged third party apps"
info_log "Starting coresvc-registry..."
run_a_script "${SPACEFX_DIR}/scripts/coresvc_registry.sh --start"
info_log "...successfully started coresvc-registry"
info_log "Staging chart dependencies..."
run_a_script "${SPACEFX_DIR}/scripts/stage/stage_chart_dependencies.sh --architecture ${ARCHITECTURE}"
info_log "...successfully staged chart dependencies"
info_log "Staging extra container images..."
stage_container_images
info_log "...successfully staged extra container images"
info_log "Staging build artifacts..."
stage_build_artifacts
info_log "...successfully staged build artifacts"
info_log "Staging service images..."
stage_spacefx_service_images --service_group core
stage_spacefx_service_images --service_group platform
stage_spacefx_service_images --service_group host
info_log "...service images successfully staged."
remove_channels_from_extra_containers
info_log "Stopping coresvc-registry..."
run_a_script "${SPACEFX_DIR}/scripts/coresvc_registry.sh --stop"
info_log "...successfully stopped coresvc-registry"
info_log "------------------------------------------"
info_log "END: ${SCRIPT_NAME}"
}
main