Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"carma" shell script update to support dual compute system #2189

Draft
wants to merge 32 commits into
base: develop
Choose a base branch
from
Draft
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
31dde3a
Initial support for swarm commands in carma bash script
willjohnsonk Nov 8, 2023
66a8100
Updated dual compute deploy commands and volume config based on testing
willjohnsonk Nov 13, 2023
2b9c1b6
Minor fixes to token command, added fi
willjohnsonk Nov 13, 2023
a97e5ce
Double quotes and spaces, my enemy
willjohnsonk Nov 13, 2023
01a60e9
Added commands for log attachment, help, and initial registry setup
willjohnsonk Nov 16, 2023
09f343b
Changed swarm update-config to support config set arguments, fixed ar…
willjohnsonk Nov 17, 2023
93e637f
Added edit arg and minor updates to config management
willjohnsonk Nov 17, 2023
4564bc6
Minor fixes following dual compute test
willjohnsonk Nov 17, 2023
89ea7b4
Migrated swarm code to extensions and changed from ifs to functions. …
willjohnsonk Nov 21, 2023
99d1ff4
Swarm install/config status added. Minor improvments to image-based a…
willjohnsonk Nov 22, 2023
712d7af
Updated to support env variables
willjohnsonk Nov 22, 2023
0872174
Naming fixes and added clarity
willjohnsonk Nov 27, 2023
b71efdf
Registry updates for testing, minor fixes
willjohnsonk Nov 27, 2023
42c3a46
Test fix for env variable subshell usage
willjohnsonk Nov 27, 2023
6092f73
Added read only vars, PR changes, fixed stop and register
willjohnsonk Nov 28, 2023
35f7a27
Added dual compute params and updated LaunchDescription
willjohnsonk Nov 29, 2023
b2c0b40
Changed carma_src launch decription to better reflect conditionals
willjohnsonk Nov 30, 2023
36283b8
Fixes to configuration params and string syntax following testing on …
willjohnsonk Dec 1, 2023
0af1659
Fixed an issue that prevented setting a full image name in set config
willjohnsonk Dec 1, 2023
b001822
Removed unnecessary echo
willjohnsonk Dec 1, 2023
d15d4c8
Addressing PR comments related to variable naming and other issues in…
willjohnsonk Dec 5, 2023
0453dc8
Removed commented-out items, minor registry fix
willjohnsonk Dec 5, 2023
fc90a39
Fixed EOF on registry
willjohnsonk Dec 5, 2023
1bcfa09
Corrected EOF issue on register from tab, added domain environment va…
willjohnsonk Dec 5, 2023
70502e4
Added a check for carma-config-data volume existence on worker
willjohnsonk Dec 18, 2023
ec78263
Improved IP/USER fetching by removing carma-base dependency
willjohnsonk Dec 19, 2023
d6c3db2
Updated settings to reflect working config on the dual compute test s…
willjohnsonk Dec 19, 2023
37e56ae
Added rsync files to engineering_tools for tracking, may need to be m…
willjohnsonk Dec 26, 2023
e801637
Cleared shell check warnings
willjohnsonk Jan 2, 2024
ff69d8b
Merged develop into branch, resolved conflicts
willjohnsonk Jan 3, 2024
6a29f4c
Fixed swapped Manager/Worker variables
willjohnsonk Jan 4, 2024
623f636
Minor directory access change
willjohnsonk Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 214 additions & 1 deletion engineering_tools/carma
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ carma__attach() {
local CARMA_DOCKER_FILE="`docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c 'cat /opt/carma/vehicle/config/docker-compose.yml'`"
JonSmet marked this conversation as resolved.
Show resolved Hide resolved

echo "Attaching to CARMA container STDOUT..."
echo "$CARMA_DOCKER_FILE" | docker-compose -p carma -f - logs --follow --tail=10
echo "$CARMA_DOCKER_FILE" | docker-compose logs -f -t --tail=10
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
}

carma-config__edit() {
Expand Down Expand Up @@ -339,6 +339,174 @@ carma__stop() {
fi
}

carma__swarm() {

if [ "$1" = "deploy" ]; then

echo "Checking Docker Swarm status..."
if [ "$(docker info | grep Swarm | sed 's/Swarm: //g')" == " inactive" ]; then
echo "Initalizing Docker Swarm..."
docker swarm init --advertise-addr 192.168.88.100 # consider making a variable
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
else
echo "Docker Swarm active"
fi

# if carma-config-data volume doesn't exist exit and request update
if [ "$(docker volume ls | grep carma-config-data | sed 's/local //g')" ]; then
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
echo "Found carma-config-data volume"
else
echo "Missing carma-config-data volume, add with \"carma swarm update-config <image tag>\""
exit 1
fi

# carma-web-ui will always run as a background process regardless of deploy argument
docker run --rm -v carma-config-data:/opt/carma/vehicle/config --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-background-pc1.yml' | \
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
docker stack deploy --compose-file - carma-background


# Run part of the stack on a single host. Mostly for debugging purposes off of the dual PC setup
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
if [ "$2" = "single" ]; then
echo "Deploying CARMA to single host Swarm stack..."

docker run --rm -v carma-config-data:/opt/carma/vehicle/config --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-pc1.yml' | \
docker stack deploy --compose-file - carma-pc1


# For use with two connected PCs with known IPs
# Saves the generated swarm join token and ssh's into the worker to execute and deploy
elif [ "$2" = "dual" ]; then
echo "Deploying CARMA to dual compute Swarm stack..."

local TKN=$(docker swarm join-token -q worker)
ssh dev@192.168.88.101 "docker swarm join --token $TKN 192.168.88.100:2377"
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved

docker run --rm -v carma-config-data:/opt/carma/vehicle/config --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-pc1.yml' | \
docker stack deploy --compose-file - carma-pc1

docker run --rm -v carma-config-data:/opt/carma/vehicle/config --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-pc2.yml' | \
docker stack deploy --compose-file - carma-pc2


elif [ ! -z "$2" ]; then
echo "Unrecognized argument \"swarm deploy $2\""
fi


# Updates the carma-config-data volume based on a input tag string given by the user
elif [ "$1" = "update-config" ]; then
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
echo "Updating carma-config-data volume..."

if [ "$2" = "-d" ]; then
local USERNAME=usdotfhwastoldev
local TAG=$3
elif [ "$2" = "-c" ]; then
local USERNAME=usdotfhwastolcandidate
local TAG=$3
else
local USERNAME=usdotfhwastol
local TAG=$2
fi

if [[ -z $2 ]]; then
echo "Please specify a tag string to update carma-config-data volume."
echo "Done."
exit 1
fi

local IMAGE_NAME="$USERNAME/carma-config:$TAG"

if [ "$(docker images | grep $USERNAME/carma-config | grep $TAG )" ]; then
echo "Found image, applying to carma-config-volume"
docker run --rm --name carma-config-data -v carma-config-data:/opt/carma/vehicle/config -d $USERNAME/carma-config:$TAG
else
echo "Could not find $USERNAME/carma-config:$TAG in local images"
fi


elif [ "$1" = "edit-config" ]; then
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
echo "Opening carma-config-data volume shell with read/write privileges..."

if [ "$(docker volume ls | grep carma-config-data | sed 's/local //g')" ]; then
echo "Found carma-config-data volume"
else
echo "Missing carma-config-data volume, add with \"carma swarm update-config <image tag>\""
exit 1
fi

local carma_base=$(__get_image_from_config carma-base:)
if [[ -z $carma_base ]]; then
__pull_newest_carma_base
carma_base=$(__get_most_recent_carma_base)
fi

docker run -it --rm -v carma-config-data:/opt/carma/vehicle/config $carma_base bash


# Attaches each carma service's STDOUT logs to the current terminal
elif [ "$1" = "attach" ]; then
echo "Attaching STDOUT logs to terminal..."

SWARM_SERVICES=$(docker service ls --format "{{.Name}}")

# this seems to loop forever and cannot be escaped with ctrl+C
# performance will likely be poor due to combined log streams
for TASK in $SWARM_SERVICES; do
docker service logs --follow --details --tail=10 "$TASK" &
done

sleep infinity


# Takes n image tags that are saved locally and pushes them to the registry
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
elif [ "$1" = "set-image" ]; then
JonSmet marked this conversation as resolved.
Show resolved Hide resolved
shift
echo "Installing Docker images..."

if [ "$(docker volume ls | grep carma-registry | sed 's/local //g')" ]; then
echo "Found carma-registry volume"
else
echo "Missing carma-registry volume, adding now..."
docker volume create carma-registry
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
fi

docker service create --constraint 'node.role==manager' -d --volume "carma-registry:/var/lib/registry" -p 5000:5000 --name carma-registry-service registry:2

IMAGE_NAMES="$*"

for SOURCE_IMAGE_NAME in $IMAGE_NAMES
do

echo "Pushing $SOURCE_IMAGE_NAME to localhost:5000"
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved

docker tag "$SOURCE_IMAGE_NAME" "localhost:5000/$SOURCE_IMAGE_NAME"
docker push "localhost:5000/$SOURCE_IMAGE_NAME"
docker rmi "localhost:5000/$SOURCE_IMAGE_NAME"

done


elif [ "$1" = "down" ]; then
willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
echo "Shutting down swarm..."

if [ "$(docker node ls | grep worker )" ]; then
ssh dev@192.168.88.101 "docker swarm leave"
fi
docker swarm leave --force

willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved

willjohnsonk marked this conversation as resolved.
Show resolved Hide resolved
elif [ ! -z "$1" ]; then
echo "Unrecognized argument \"swarm $1\""


elif [ $# -eq 0 ]; then
carma__swarm-help
fi
}

carma__ps() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to report. Please set a config."
Expand Down Expand Up @@ -564,6 +732,51 @@ Please enter one of the following commands:
HELP
}

carma__swarm-help() {
cat <<SHELP
-------------------------------------------------------------------------------
| USDOT FHWA STOL CARMA Swarm |
-------------------------------------------------------------------------------

Please enter one of the following commands:
swarm:
deploy
[empty]
- Will always deploy carma-web-ui as a background service on PC1
single
- Deploys PC1 services as described in docker-compose-pc1.yml
to use for debugging on a single test system
dual
- Deploys PC1 services from docker-compose-pc1.yml and
PC2 services from docker-compose-pc2.yml to the PC1
manger node and PC2 worker node
update-config <tag/image>
- [empty]
- Defaults to a usdotfhwastol image
- d
- Defines a usdotfhwastoldev image
- c
- Defines a usdotfhwastolcandidate image
- Uses the local carma-config image defined in
<tag/image> to update the Docker named volume
"carma-config-data" which can be found at
/var/lib/docker/volumes/carma-config-data/_data
edit-config
- Requires sudo privilege. Opens a bash shell
in a carma-base image with carma-config-data
mounted so that files can be modified
set-image <tag/image>
- Pushes the images defined by <tag/image> to the
the registry service and associated volume
attach
- View STDOUT from all running CARMA processes
down
- Shuts down the worker node and manager node
and ends Swarm along with all services

SHELP
}

carma__config() {
local cmdname=$1; shift
if type "carma-config__$cmdname" >/dev/null 2>&1; then
Expand Down