-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathopenc3.sh
More file actions
executable file
·808 lines (762 loc) · 31.8 KB
/
Copy pathopenc3.sh
File metadata and controls
executable file
·808 lines (762 loc) · 31.8 KB
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
#!/bin/bash
set +e
# Cached container runtime detection
CONTAINER_CMD=""
CONTAINER_COMPOSE_CMD=""
# Detect the container runtime (docker or podman). Result is cached.
detect_container_runtime() {
if [[ -n "$CONTAINER_CMD" ]]; then
return 0
fi
if command -v docker &> /dev/null; then
CONTAINER_CMD="docker"
elif command -v podman &> /dev/null; then
CONTAINER_CMD="podman"
else
echo "Neither docker nor podman found!" >&2
exit 1
fi
}
# Detect the compose command. Tries "<runtime> compose" first, then "docker-compose".
# Never falls back to "podman-compose" since COSMOS only supports docker-compose as the
# standalone compose tool, even when the container runtime is podman.
# Result is cached. Exports DOCKER_COMPOSE_COMMAND for backward compatibility with sub-scripts.
detect_compose_cmd() {
if [[ -n "$CONTAINER_COMPOSE_CMD" ]]; then
return 0
fi
detect_container_runtime
if $CONTAINER_CMD compose version &> /dev/null; then
CONTAINER_COMPOSE_CMD="$CONTAINER_CMD compose"
elif command -v "docker-compose" &> /dev/null; then
CONTAINER_COMPOSE_CMD="docker-compose"
else
echo "No compose command found! Install '$CONTAINER_CMD compose' or 'docker-compose'." >&2
exit 1
fi
export DOCKER_COMPOSE_COMMAND="$CONTAINER_COMPOSE_CMD"
}
# Print a hint suggesting registry login when an image pull is denied.
# We intentionally do NOT login automatically: forcing a login would require
# credentials for public registries (e.g. docker.io) and break air-gapped builds.
suggest_registry_login() {
local env_file="$(dirname -- "$0")/${ENV_FILE:-.env}"
if [[ -f "$env_file" ]]; then
set -a
. "$env_file"
set +a
fi
echo "" >&2
echo "A container image pull was denied (403 / authentication required)." >&2
echo "If the image lives in a private registry, login and retry the command:" >&2
if [[ -n "$OPENC3_REGISTRY" ]]; then
echo " $CONTAINER_CMD login $OPENC3_REGISTRY" >&2
fi
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]] && [[ -n "$OPENC3_ENTERPRISE_REGISTRY" ]]; then
echo " $CONTAINER_CMD login $OPENC3_ENTERPRISE_REGISTRY" >&2
fi
if [[ -z "$OPENC3_REGISTRY" ]]; then
echo " $CONTAINER_CMD login <registry>" >&2
fi
}
# Run a container/compose command, streaming its output live. If the command
# fails with a registry authentication error (e.g. 403), suggest logging in.
run_with_registry_check() {
local tmp status
tmp="$(mktemp)"
"$@" 2>&1 | tee "$tmp"
status=${PIPESTATUS[0]}
if [[ $status -ne 0 ]] && grep -qiE '403 Forbidden|pull access denied|requested access to the resource is denied|authentication required|unauthorized' "$tmp"; then
suggest_registry_login
fi
rm -f "$tmp"
return $status
}
# Helper function to find script - checks PATH first, then falls back to script location
find_script() {
local script_name="$1"
if command -v "$script_name" &> /dev/null; then
echo "$script_name"
else
echo "$(dirname -- "$0")/scripts/linux/$script_name"
fi
}
# Initialize container runtime and compose detection
detect_container_runtime
detect_compose_cmd
$CONTAINER_CMD info | grep -e "rootless$" -e "rootless: true"
if [[ "$?" -ne 0 ]]; then
export OPENC3_ROOTFUL=1
export OPENC3_USER_ID=`id -u`
export OPENC3_GROUP_ID=`id -g`
else
export OPENC3_ROOTLESS=1
export OPENC3_USER_ID=0
export OPENC3_GROUP_ID=0
fi
# Detect if this is a development (build) environment or runtime environment
# by checking for compose-build.yaml
if [[ -f "$(dirname -- "$0")/compose-build.yaml" ]]; then
export OPENC3_DEVEL=1
else
export OPENC3_DEVEL=0
fi
# Detect if this is enterprise by checking for enterprise-specific services
if [[ -f "$(dirname -- "$0")/compose-build.yaml" ]] && grep -q "openc3-enterprise-gem" "$(dirname -- "$0")/compose-build.yaml" 2>/dev/null; then
export OPENC3_ENTERPRISE=1
elif [[ -f "$(dirname -- "$0")/compose.yaml" ]] && grep -q "openc3-metrics" "$(dirname -- "$0")/compose.yaml" 2>/dev/null; then
export OPENC3_ENTERPRISE=1
else
export OPENC3_ENTERPRISE=0
fi
# Set display name based on enterprise flag
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
export COSMOS_NAME="COSMOS Enterprise"
else
export COSMOS_NAME="COSMOS Core"
fi
set -e
usage() {
if [[ "$OPENC3_DEVEL" -eq 1 ]] && [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
cat >&2 << EOF
OpenC3 $COSMOS_NAME - Command and Control System (Enterprise Development Installation)
Usage: $1 COMMAND [OPTIONS]
DESCRIPTION:
$COSMOS_NAME is a command and control system for embedded systems. This script
provides a convenient interface for building, running, testing, and managing
$COSMOS_NAME in Docker containers.
This is an ENTERPRISE DEVELOPMENT installation with source code and build capabilities.
COMMON COMMANDS:
EOF
elif [[ "$OPENC3_DEVEL" -eq 1 ]]; then
cat >&2 << EOF
OpenC3 $COSMOS_NAME - Command and Control System (Development Installation)
Usage: $1 COMMAND [OPTIONS]
DESCRIPTION:
$COSMOS_NAME is a command and control system for embedded systems. This script
provides a convenient interface for building, running, testing, and managing
$COSMOS_NAME in Docker containers.
This is a DEVELOPMENT installation with source code and build capabilities.
COMMON COMMANDS:
EOF
elif [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
cat >&2 << EOF
OpenC3 $COSMOS_NAME - Command and Control System (Enterprise Runtime-Only Installation)
Usage: $1 COMMAND [OPTIONS]
DESCRIPTION:
$COSMOS_NAME is a command and control system for embedded systems. This script
provides a convenient interface for running, testing, and managing
$COSMOS_NAME in Docker containers.
This is an ENTERPRISE RUNTIME-ONLY installation using pre-built images.
COMMON COMMANDS:
EOF
else
cat >&2 << EOF
OpenC3 $COSMOS_NAME - Command and Control System (Runtime-Only Installation)
Usage: $1 COMMAND [OPTIONS]
DESCRIPTION:
$COSMOS_NAME is a command and control system for embedded systems. This script
provides a convenient interface for running, testing, and managing
$COSMOS_NAME in Docker containers.
This is a RUNTIME-ONLY installation using pre-built images.
COMMON COMMANDS:
EOF
fi
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
cat >&2 << EOF
start Build and run $COSMOS_NAME (equivalent to: build + run)
This is the typical command to get $COSMOS_NAME running.
EOF
else
cat >&2 << EOF
run Start $COSMOS_NAME containers
Access at: http://localhost:2900
EOF
fi
cat >&2 << EOF
stop Stop all running $COSMOS_NAME containers gracefully
Allows containers to shutdown cleanly.
cli [COMMAND] Run $COSMOS_NAME CLI commands in a container
Use 'cli help' for available commands
Use 'cli --help' for Docker wrapper info
Examples:
$1 cli generate plugin MyPlugin
$1 cli validate myplugin.gem
cliroot [COMMAND] Run $COSMOS_NAME CLI commands as root user
Same as 'cli' but with root privileges
EOF
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
cat >&2 << EOF
DEVELOPMENT COMMANDS:
build Build all $COSMOS_NAME Docker containers from source
Required before first run or after code changes.
run Start $COSMOS_NAME containers in detached mode
Access at: http://localhost:2900
EOF
fi
cat >&2 << EOF
test [COMMAND] Run test suites (rspec, playwright, hash)
Use '$1 test' to see available test commands.
util [COMMAND] Utility commands (encode, hash, save, load, etc.)
Use '$1 util' to see available utilities.
EOF
if [[ "$OPENC3_DEVEL" -eq 0 ]]; then
cat >&2 << EOF
upgrade Upgrade $COSMOS_NAME to latest version
Downloads and installs latest release.
EOF
fi
cat >&2 << EOF
CLEANUP:
cleanup [OPTIONS] Remove Docker volumes and data
WARNING: This deletes all $COSMOS_NAME data!
Options:
local - Also remove local plugin files
force - Skip confirmation prompt
EOF
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
cat >&2 << EOF
REDHAT:
start-ubi Build and run with Red Hat UBI images
build-ubi Build containers using UBI base images
run-ubi Run containers with UBI images
For air-gapped or government environments.
EOF
fi
cat >&2 << EOF
GETTING STARTED:
1. First time setup: $1 start
2. Access COSMOS: http://localhost:2900
3. Stop when done: $1 stop
4. Remove everything: $1 cleanup
MORE INFORMATION:
Run '$1 COMMAND --help' for detailed help on any command.
Documentation: https://docs.openc3.com
OPTIONS:
-h, --help Show this help message
EOF
exit 1
}
if [[ "$#" -eq 0 ]]; then
usage $0
fi
# Check for help flag
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
usage $0
fi
check_root() {
if [[ "$(id -u)" -eq 0 ]]; then
echo "WARNING: $COSMOS_NAME should not be run as the root user, as permissions for Local Mode will be affected. Do not use sudo when running $COSMOS_NAME. See more: https://docs.openc3.com/docs/guides/local-mode"
fi
}
case $1 in
cli )
if [[ "$2" == "--wrapper-help" ]] || [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 cli [COMMAND] [OPTIONS]"
echo ""
echo "Run $COSMOS_NAME CLI commands inside a Docker container as the default user."
echo ""
echo "What this wrapper does:"
echo " - Starts a temporary Docker container (removed after use)"
echo " - Mounts your current directory as /openc3/local inside the container"
echo " - Runs the Ruby CLI tool (/openc3/bin/openc3cli) with your arguments"
echo " - Uses interactive terminal mode (-it) for commands that need input"
echo ""
echo "Prerequisites:"
echo " - Containers must be built first: $0 build"
echo " - .env file must exist in the $COSMOS_NAME directory"
echo ""
echo "Common commands:"
echo " $0 cli help Show CLI command help"
echo " $0 cli validate plugin.gem Validate a plugin"
echo " $0 cli load plugin.gem Load a plugin"
echo " $0 cli generate plugin MyPlugin --ruby"
echo " Generate a new plugin"
echo ""
echo "For detailed CLI command help, run: $0 cli help"
echo ""
echo "Note: Use 'cliroot' instead of 'cli' to run as root user."
echo ""
echo "Environment variables:"
echo " ENV_FILE Path to environment file (default: .env)"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " --wrapper-help (same as --help)"
exit 0
fi
# Source the environment file to setup environment variables
# Use ENV_FILE if set, otherwise default to .env
set -a
. "$(dirname -- "$0")/${ENV_FILE:-.env}"
# Start (and remove when done --rm) the cmd-tlm-api container with the current working directory
# mapped as volume (-v) /openc3/local and container working directory (-w) also set to /openc3/local.
# This allows tools running in the container to have a consistent path to the current working directory.
# Run the command "ruby /openc3/bin/openc3cli" with all parameters starting at 2 since the first is 'openc3'
# Shift off the first argument (script name) to get CLI args
shift
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" run -it --rm -v $(pwd):/openc3/local:z -w /openc3/local -e OPENC3_API_USER=$OPENC3_API_USER -e OPENC3_API_PASSWORD=$OPENC3_API_PASSWORD --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli "$@"
else
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" run -it --rm -v $(pwd):/openc3/local:z -w /openc3/local -e OPENC3_API_PASSWORD=$OPENC3_API_PASSWORD --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli "$@"
fi
set +a
;;
cliroot )
if [[ "$2" == "--wrapper-help" ]] || [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 cliroot [COMMAND] [OPTIONS]"
echo ""
echo "Run $COSMOS_NAME CLI commands inside a Docker container as root user."
echo ""
echo "This is the same as 'cli' but runs as root instead of the default user."
echo "Use this when you need elevated privileges inside the container."
echo ""
echo "What this wrapper does:"
echo " - Starts a temporary Docker container (removed after use)"
echo " - Mounts your current directory as /openc3/local inside the container"
echo " - Runs the Ruby CLI tool (/openc3/bin/openc3cli) with your arguments"
echo " - Uses interactive terminal mode (-it) for commands that need input"
echo " - Runs as root user (--user=root)"
echo ""
echo "Prerequisites:"
echo " - Containers must be built first: $0 build"
echo " - .env file must exist in the $COSMOS_NAME directory"
echo ""
echo "Common commands:"
echo " $0 cliroot help Show CLI command help"
echo " $0 cliroot validate plugin.gem Validate a plugin"
echo " $0 cliroot load plugin.gem Load a plugin"
echo ""
echo "For detailed CLI command help, run: $0 cliroot help"
echo ""
echo "Environment variables:"
echo " ENV_FILE Path to environment file (default: .env)"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " --wrapper-help (same as --help)"
exit 0
fi
# Source the environment file to setup environment variables
# Use ENV_FILE if set, otherwise default to .env
set -a
. "$(dirname -- "$0")/${ENV_FILE:-.env}"
# Same as cli but run as root user
# Note: The service name is always openc3-cosmos-cmd-tlm-api; compose.yaml pulls the correct image
# (enterprise or non-enterprise) based on environment variables.
# Shift off the first argument (script name) to get CLI args
shift
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" run -it --rm --user=root -v $(pwd):/openc3/local:z -w /openc3/local -e OPENC3_API_USER=$OPENC3_API_USER -e OPENC3_API_PASSWORD=$OPENC3_API_PASSWORD --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli "$@"
else
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" run -it --rm --user=root -v $(pwd):/openc3/local:z -w /openc3/local -e OPENC3_API_PASSWORD=$OPENC3_API_PASSWORD --no-deps openc3-cosmos-cmd-tlm-api ruby /openc3/bin/openc3cli "$@"
fi
set +a
;;
start )
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
echo "Usage: $0 start [BUILD_FLAGS...]"
echo ""
echo "Build and run $COSMOS_NAME containers."
echo ""
echo "This command:"
echo " 1. Builds all $COSMOS_NAME containers (equivalent to 'openc3.sh build')"
echo " 2. Starts all containers (equivalent to 'openc3.sh run')"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " BUILD_FLAGS Additional flags to pass to docker compose build"
echo " (e.g., --no-cache, --pull)"
else
echo "Usage: $0 start"
echo ""
echo "Start $COSMOS_NAME containers."
echo ""
echo "This is an alias for 'run' command in runtime-only installations."
echo ""
echo "Options:"
echo " -h, --help Show this help message"
fi
exit 0
fi
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
"$0" build "${@:2}"
"$0" run
else
"$0" run
fi
;;
start-ubi )
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
echo "Usage: $0 start-ubi [BUILD_FLAGS...]"
echo ""
echo "Build and run $COSMOS_NAME UBI containers."
echo ""
echo "This command:"
echo " 1. Builds all $COSMOS_NAME UBI containers (equivalent to 'openc3.sh build-ubi')"
echo " 2. Starts all UBI containers (equivalent to 'openc3.sh run-ubi')"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " BUILD_FLAGS Additional flags to pass to docker compose build"
echo " (e.g., --no-cache, --pull)"
else
echo "Usage: $0 start-ubi"
echo ""
echo "Run all $COSMOS_NAME UBI containers in detached mode."
echo ""
echo "This is an alias for 'run-ubi' command."
echo ""
echo "Options:"
echo " -h, --help Show this help message"
fi
exit 0
fi
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
"$0" build-ubi "${@:2}"
"$0" run-ubi
else
"$0" run-ubi
fi
;;
stop )
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 stop"
echo ""
echo "Stop all $COSMOS_NAME containers gracefully."
echo ""
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
echo "This command:"
echo " 1. Stops operator, script-runner-api, cmd-tlm-api, and metrics containers"
echo " 2. Waits 5 seconds"
echo " 3. Runs docker compose down with 30 second timeout"
else
echo "This command:"
echo " 1. Stops operator, script-runner-api, and cmd-tlm-api containers"
echo " 2. Waits 5 seconds"
echo " 3. Runs docker compose down with 30 second timeout"
fi
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
fi
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" stop openc3-operator
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" stop openc3-cosmos-script-runner-api
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" stop openc3-cosmos-cmd-tlm-api
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" stop openc3-metrics
fi
sleep 5
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" down -t 30
;;
cleanup )
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 cleanup [local] [force]"
echo ""
echo "Remove all $COSMOS_NAME docker volumes and data."
echo ""
echo "WARNING: This is a destructive operation that removes ALL $COSMOS_NAME data!"
echo ""
echo "Arguments:"
echo " local Also remove local plugin files in plugins/DEFAULT/"
echo " force Skip confirmation prompt"
echo ""
echo "Examples:"
echo " $0 cleanup # Remove volumes (with confirmation)"
echo " $0 cleanup force # Remove volumes (no confirmation)"
echo " $0 cleanup local # Remove volumes and local plugins"
echo " $0 cleanup local force # Remove volumes and local plugins (no confirmation)"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
fi
# They can specify 'cleanup force' or 'cleanup local force'
if [[ "$2" == "force" ]] || [[ "$3" == "force" ]]
then
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" down -t 30 -v
else
echo "Are you sure? Cleanup removes ALL docker volumes and all $COSMOS_NAME data! (1-Yes / 2-No)"
select yn in "Yes" "No"; do
case $yn in
Yes ) ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" down -t 30 -v; break;;
No ) exit;;
esac
done
fi
if [[ "$2" == "local" ]]
then
cd "$(dirname -- "$0")/plugins/DEFAULT"
ls | grep -xv "README.md" | xargs rm -r
cd ../..
fi
;;
build )
if [[ "$OPENC3_DEVEL" -eq 0 ]]; then
echo "Error: 'build' command is only available in development environments"
echo "This appears to be a runtime-only installation."
exit 1
fi
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 build [BUILD_FLAGS...]"
echo ""
echo "Build all $COSMOS_NAME docker containers."
echo ""
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
echo "This command:"
echo " 1. Runs setup to download certificates"
echo " 2. Builds openc3-enterprise-gem image"
echo " 3. Builds all remaining service containers"
else
echo "This command:"
echo " 1. Runs setup to download certificates"
echo " 2. Builds openc3-ruby base image"
echo " 3. Builds openc3-base image"
echo " 4. Builds openc3-node image"
echo " 5. Builds all remaining service containers"
fi
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " BUILD_FLAGS Additional flags to pass to docker compose build"
echo " (e.g., --no-cache, --pull, --progress=plain)"
echo ""
echo "Examples:"
echo " $0 build # Build with cache"
echo " $0 build --no-cache # Build without using cache"
echo " $0 build --pull # Always pull newer base images"
exit 0
fi
# Change to cosmos directory since openc3_setup.sh uses relative paths
cd "$(dirname -- "$0")"
"$(find_script openc3_setup.sh)"
# Handle restrictive umasks - Built files need to be world readable
umask 0022
chmod -R +r "$(dirname -- "$0")"
# Collect any additional build flags from arguments (skip first arg which is "build")
BUILD_FLAGS="${@:2}"
if [[ "$OPENC3_ENTERPRISE" -eq 1 ]]; then
run_with_registry_check ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" -f "$(dirname -- "$0")/compose-build.yaml" build $BUILD_FLAGS openc3-enterprise-gem
else
run_with_registry_check ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" -f "$(dirname -- "$0")/compose-build.yaml" build $BUILD_FLAGS openc3-ruby
run_with_registry_check ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" -f "$(dirname -- "$0")/compose-build.yaml" build $BUILD_FLAGS openc3-base
run_with_registry_check ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" -f "$(dirname -- "$0")/compose-build.yaml" build $BUILD_FLAGS openc3-node
fi
run_with_registry_check ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" -f "$(dirname -- "$0")/compose-build.yaml" build $BUILD_FLAGS
;;
build-ubi )
if [[ "$OPENC3_DEVEL" -eq 0 ]]; then
echo "Error: 'build-ubi' command is only available in development environments"
echo "This appears to be a runtime-only installation."
exit 1
fi
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 build-ubi [BUILD_FLAGS...] [IMAGE_NAME...]"
echo ""
echo "Build $COSMOS_NAME UBI (Universal Base Image) containers."
echo ""
echo "This is used for enterprise deployments requiring Red Hat UBI base images,"
echo "suitable for air-gapped and government environments."
echo ""
echo "Arguments:"
echo " BUILD_FLAGS Additional flags to pass to docker build (e.g., --no-cache, --pull)"
echo " IMAGE_NAME One or more image names to build (optional)"
echo " If no images are specified, all images will be built"
echo ""
echo "Required environment variables (set in env file):"
echo " OPENC3_UBI_REGISTRY UBI registry URL"
echo " OPENC3_UBI_IMAGE UBI image name"
echo " OPENC3_UBI_TAG UBI image tag"
echo " OPENC3_REGISTRY Target registry for built images"
echo " OPENC3_NAMESPACE Target namespace"
echo " OPENC3_TAG Tag for built images"
echo ""
echo "Optional environment variables:"
echo " ENV_FILE Path to environment file (default: .env)"
echo " RUBYGEMS_URL RubyGems mirror URL (for air-gapped)"
echo " PYPI_URL PyPI mirror URL (for air-gapped)"
echo " NPM_URL NPM registry URL (for air-gapped)"
echo ""
echo "This command:"
echo " 1. Sources environment file for configuration"
echo " 2. Copies CA certificates if available"
echo " 3. Runs openc3_setup.sh"
echo " 4. Builds UBI-based containers"
echo ""
echo "Examples:"
echo " $0 build-ubi # Build all images"
echo " $0 build-ubi --no-cache # Build all images without cache"
echo " $0 build-ubi openc3-ruby-ubi # Build one image"
echo " $0 build-ubi --no-cache openc3-ruby-ubi # Build one image without cache"
echo " ENV_FILE=.env.prod $0 build-ubi # Use different env file"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
fi
# Change to cosmos directory since scripts use relative paths
cd "$(dirname -- "$0")"
set -a
. "$(dirname -- "$0")/${ENV_FILE:-.env}"
if [[ -f /etc/ssl/certs/ca-bundle.crt ]]
then
cp /etc/ssl/certs/ca-bundle.crt "$(dirname -- "$0")/cacert.pem"
fi
"$(find_script openc3_setup.sh)"
# Pass through any additional arguments (image names) to openc3_build_ubi.sh
"$(find_script openc3_build_ubi.sh)" "${@:2}"
set +a
;;
run )
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 run"
echo ""
echo "Run all $COSMOS_NAME containers in detached mode."
echo ""
echo "Containers will start in the background using docker compose up -d."
echo ""
echo "After starting, check status with:"
echo " docker compose ps # Show running containers"
echo " docker compose logs -f # Follow all logs"
echo " docker compose logs -f SERVICE # Follow specific service logs"
echo ""
echo "Access $COSMOS_NAME:"
echo " http://localhost:2900 # $COSMOS_NAME web interface"
echo ""
echo "Common services:"
echo " openc3-operator Main orchestration service"
echo " openc3-cosmos-cmd-tlm-api Command/Telemetry API"
echo " openc3-cosmos-script-runner-api Script execution service"
echo " openc3-redis Redis database"
echo " openc3-buckets Object storage"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
fi
check_root
run_with_registry_check ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" up -d
;;
run-ubi )
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]]; then
echo "Usage: $0 run-ubi"
echo ""
echo "Run all $COSMOS_NAME UBI (Universal Base Image) containers in detached mode."
echo ""
echo "This uses UBI-based container images and sets UBI-specific configurations:"
echo " - Image suffix: -ubi"
echo " - Redis volume: /data"
echo ""
echo "Containers will start in the background using docker compose up -d."
echo ""
echo "After starting, check status with:"
echo " docker compose ps # Show running containers"
echo " docker compose logs -f # Follow all logs"
echo " docker compose logs -f SERVICE # Follow specific service logs"
echo ""
echo "Access $COSMOS_NAME:"
echo " http://localhost:2900 # $COSMOS_NAME web interface"
echo ""
echo "Common services:"
echo " openc3-operator Main orchestration service"
echo " openc3-cosmos-cmd-tlm-api Command/Telemetry API"
echo " openc3-cosmos-script-runner-api Script execution service"
echo " openc3-redis Redis database"
echo " openc3-buckets Object storage"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
fi
check_root
# QuestDB RHEL images have a native arm64 variant; run tsdb natively on ARM
# to avoid the x86-64-v3 QEMU emulation failure. All other services run as amd64.
if [[ "$(uname -m)" == "arm64" ]]; then
OPENC3_TSDB_PLATFORM=linux/arm64
else
OPENC3_TSDB_PLATFORM=linux/amd64
fi
run_with_registry_check env DOCKER_DEFAULT_PLATFORM=linux/amd64 OPENC3_IMAGE_SUFFIX=-ubi OPENC3_TSDB_PLATFORM=$OPENC3_TSDB_PLATFORM ${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" up -d
;;
test )
# Check for help at any position
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]] || [[ "$#" -eq 1 ]]; then
echo "Usage: $0 test COMMAND [OPTIONS]"
echo ""
echo "Test $COSMOS_NAME. This builds $COSMOS_NAME and runs the specified test suite."
echo ""
echo "Available commands:"
echo " rspec Run RSpec tests against Ruby code"
echo " playwright [SUBCOMMAND] Run Playwright end-to-end tests"
echo " install-playwright Install playwright and dependencies"
echo " build-plugin Build the plugin for tests"
echo " run-chromium Run tests using Chrome"
echo " reset-storage-state Clear cached data"
echo " hash Run comprehensive tests with coverage"
echo ""
echo "Run '$0 test COMMAND --help' for detailed help on each command."
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
fi
# If subcommand has --help or -h, skip setup/build and pass through directly
for arg in "$@"; do
if [[ "$arg" == "--help" ]] || [[ "$arg" == "-h" ]]; then
"$(find_script openc3_test.sh)" "${@:2}"
exit 0
fi
done
# Change to cosmos directory since openc3_setup.sh uses relative paths
cd "$(dirname -- "$0")"
"$(find_script openc3_setup.sh)"
${CONTAINER_COMPOSE_CMD} -f "$(dirname -- "$0")/compose.yaml" -f "$(dirname -- "$0")/compose-build.yaml" build
"$(find_script openc3_test.sh)" "${@:2}"
;;
upgrade )
if [[ "$OPENC3_DEVEL" -eq 1 ]]; then
echo "Error: 'upgrade' command is only available in runtime environments"
echo "This appears to be a development installation."
exit 1
fi
"$(find_script openc3_upgrade.sh)" "${@:2}"
;;
util )
if [[ "$2" == "--help" ]] || [[ "$2" == "-h" ]] || [[ "$#" -eq 1 ]]; then
echo "Usage: $0 util COMMAND [OPTIONS]"
echo ""
echo "Various $COSMOS_NAME utility commands."
echo ""
echo "Available commands:"
echo " encode STRING Encode a string to base64"
echo " hash STRING Hash a string using SHA-256"
echo " save REPO NS TAG [SUFFIX] Save docker images to tar files"
echo " load [TAG] [SUFFIX] Load docker images from tar files"
echo " tag REPO1 REPO2 NS1 TAG1 [NS2] [TAG2] [SUFFIX]"
echo " Tag images from one repo to another"
echo " push REPO NS TAG [SUFFIX] Push images to docker repository"
echo " clean Remove node_modules, coverage, etc"
echo " hostsetup REPO NS TAG Configure host for redis"
echo " hostenter Shell into VM host"
echo ""
echo "Run '$0 util COMMAND --help' for detailed help on each command."
echo ""
echo "Environment variables:"
echo " ENV_FILE Path to environment file (default: .env)"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
exit 0
fi
set -a
. "$(dirname -- "$0")/${ENV_FILE:-.env}"
"$(find_script openc3_util.sh)" "${@:2}"
set +a
;;
* )
usage $0
;;
esac