From 07b7d470962467257cfcd4bf5dbdd83def4d01a1 Mon Sep 17 00:00:00 2001 From: patrick-5546 Date: Sun, 26 May 2024 11:51:35 -0700 Subject: [PATCH 01/30] Build images workflows pushes to latest tag as well --- .github/workflows/build-images.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 9c90e01ab..9305d777f 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -40,7 +40,9 @@ jobs: context: "{{defaultContext}}:.devcontainer/base-dev" file: base-dev.Dockerfile push: true - tags: ghcr.io/ubcsailbot/sailbot_workspace/base:${{ inputs.tag }} + tags: | + ghcr.io/ubcsailbot/sailbot_workspace/base:${{ inputs.tag }} + ghcr.io/ubcsailbot/sailbot_workspace/base:latest platforms: linux/arm64,linux/amd64 cache-from: type=gha cache-to: type=gha,mode=max @@ -52,7 +54,9 @@ jobs: context: "{{defaultContext}}:.devcontainer/base-dev" file: base-dev.Dockerfile push: true - tags: ghcr.io/ubcsailbot/sailbot_workspace/local-base:${{ inputs.tag }} + tags: | + ghcr.io/ubcsailbot/sailbot_workspace/local-base:${{ inputs.tag }} + ghcr.io/ubcsailbot/sailbot_workspace/local-base:latest platforms: linux/arm64,linux/amd64 cache-from: type=gha cache-to: type=gha,mode=max @@ -64,7 +68,9 @@ jobs: context: "{{defaultContext}}:.devcontainer/base-dev" file: base-dev.Dockerfile push: true - tags: ghcr.io/ubcsailbot/sailbot_workspace/dev:${{ inputs.tag }} + tags: | + ghcr.io/ubcsailbot/sailbot_workspace/dev:${{ inputs.tag }} + ghcr.io/ubcsailbot/sailbot_workspace/dev:latest platforms: linux/arm64,linux/amd64 cache-from: type=gha cache-to: type=gha,mode=max From 7f6aded302c90163646dba2ff3762012f8a8affa Mon Sep 17 00:00:00 2001 From: patrick-5546 Date: Sun, 26 May 2024 11:52:45 -0700 Subject: [PATCH 02/30] Make specifying tag required --- .github/workflows/build-images.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 9305d777f..851aa2992 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -5,9 +5,8 @@ on: inputs: tag: description: 'Tag of the base, local-base, and dev images' - required: false + required: true type: string - default: 'main' concurrency: group: ${{ github.workflow }}-${{ github.ref }} From f3029481ed25bd4dc4d441ba58361858b8c08a6e Mon Sep 17 00:00:00 2001 From: patrick-5546 Date: Sun, 26 May 2024 16:46:06 -0700 Subject: [PATCH 03/30] Remove unneeded parts of run-tests script --- scripts/run-tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index ec57da02e..17484fa6e 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -1,7 +1,6 @@ #!/bin/bash set -e -source /opt/ros/${ROS_DISTRO}/setup.bash ./scripts/setup.sh -./scripts/build.sh RelWithDebInfo OFF # Do not run static analysis or linting +./scripts/build.sh ./scripts/test.sh From a0773346065c45e43a25ee389c2cd434c24cd721 Mon Sep 17 00:00:00 2001 From: patrick-5546 Date: Sun, 26 May 2024 16:49:18 -0700 Subject: [PATCH 04/30] Start revamping start container script to use docker compose --- scripts/deployment/start_container.sh | 51 ---------------- scripts/deployment/start_containers.sh | 81 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 51 deletions(-) delete mode 100755 scripts/deployment/start_container.sh create mode 100755 scripts/deployment/start_containers.sh diff --git a/scripts/deployment/start_container.sh b/scripts/deployment/start_container.sh deleted file mode 100755 index 069b890b2..000000000 --- a/scripts/deployment/start_container.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -# Run the base image without VSCode for deployment -# Runs the base image used by the Dev Container by default -# (Optional) run this script with an image ID as the first argument to run a specific version of the image - -IMAGE_ID=${1:-""} - -BASE_IMAGE="ghcr.io/ubcsailbot/sailbot_workspace/base" -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" -HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.." -DOCKERFILE_DIR="$HOST_WORKSPACE_ROOT/.devcontainer" -DOCKERFILE_PATH="$DOCKERFILE_DIR/Dockerfile" -DEVCONTAINER_PATH="$DOCKERFILE_DIR/devcontainer.json" -CONTAINER_WORKSPACE_PATH="/workspaces/sailbot_workspace" -# run interactive terminal and name it sailbot -CONTAINER_NAME="sailbot_deployment_container" -DOCKER_RUN_CMD="docker run -it --name $CONTAINER_NAME" -# args to mount the repo inside the container -DOCKER_MNT_VOL_ARGS="-v $HOST_WORKSPACE_ROOT:$CONTAINER_WORKSPACE_PATH -w $CONTAINER_WORKSPACE_PATH" -DOCKER_TEMPATE_REPO_ARGS="--cap-add=SYS_PTRACE --security-opt=seccomp:unconfined --security-opt=apparmor:unconfined" -# args to support can/vcan -DOCKER_CAN_ARGS="--cap-add=NET_ADMIN --network=host" -DOCKER_RUN_CMD="$DOCKER_RUN_CMD $DOCKER_MNT_VOL_ARGS $DOCKER_TEMPATE_REPO_ARGS $DOCKER_CAN_ARGS" - -# Parse the Dockerfile to get the base/dev image tag -get_dev_tag() -{ - TAG=$(head -n1 $DOCKERFILE_PATH) # Get first line with the image source and tag - IFS=':' read -ra TAG <<< "$TAG" # Turn the string into an array - TAG=${TAG[1]} # Get the tag from the second element in the array - - echo $TAG # return tag -} - -if [[ $(docker ps -a --filter "name=$CONTAINER_NAME" | grep -w $CONTAINER_NAME) != "" ]] -then - echo "Error: $CONTAINER_NAME is already running or suspended. Run the following command and then try again:" - echo "docker stop $CONTAINER_NAME; docker rm $CONTAINER_NAME" - exit 1 -fi - -if [[ $IMAGE_ID == "" ]] -then - TAG=$(get_dev_tag) - DOCKER_RUN_CMD="$DOCKER_RUN_CMD --pull always $BASE_IMAGE:$TAG /bin/bash" -else - DOCKER_RUN_CMD="$DOCKER_RUN_CMD $IMAGE_ID /bin/bash" -fi - -echo "Running: $DOCKER_RUN_CMD" -$DOCKER_RUN_CMD # Any commands placed after this will run AFTER the container is exited diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh new file mode 100755 index 000000000..3c5bd1601 --- /dev/null +++ b/scripts/deployment/start_containers.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# TODO: check if it works without internet once built +# TODO: argument for deleting containers +# TODO: argument for deleting volumes + +## CLI ARGUMENTS --- + +# default argument values +BASE_TAG="latest" +WEBSITE_ARG="" +INTERACTIVE="" + +# Function to display usage help +usage() { + echo "Usage: $0 [--tag tag] [--website]" + echo " --tag Specify the base Docker image tag (default: latest)" + echo " --website If set, runs the website container" + echo " --interactive If set, run commands inside the sailbot workspace container interactively" + exit 1 +} + +# parse command-line options +while getopts ":-:" opt; do + case "${opt}" in + -) + case "${OPTARG}" in + tag) + BASE_TAG="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) + ;; + website) + WEBSITE_ARG="-f .devcontainer/website/docker-compose.website.prod.yml" + ;; + interactive) + INTERACTIVE="interactive" + ;; + *) + usage # Show usage if argument is not recognized + ;; + esac + ;; + *) + usage # Show usage if option is unknown + ;; + esac +done + + +## HELPER VARIABLES --- + +# get absolute path to workspace root in host OS +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.." + +# common arguments for docker compose commmands +DOCKER_COMPOSE_ARGS="docker compose -f .devcontainer/docker-compose.yml $WEBSITE_ARG" + + +## RUN COMMANDS --- + +# run commands in the workspace's root directory +cd $HOST_WORKSPACE_ROOT + +# start containers +SW_TAG=$BASE_TAG $DOCKER_COMPOSE_ARGS up --detach + +# run commands inside sailbot workspace container +if [[ -n $INTERACTIVE ]]; then + $DOCKER_COMPOSE_ARGS exec -it sailbot-workspace /bin/bash +else + $DOCKER_COMPOSE_ARGS exec -T sailbot-workspace /bin/bash -c "\ + cd \$ROS_WORKSPACE && \ + pwd && \ + ./scripts/setup.sh && \ + ./scripts/build.sh && \ + ./scripts/test.sh && \ + ls" +fi + +# stop containers +$DOCKER_COMPOSE_ARGS stop From 259e7ed862efdada12311e3c0b1892cfe635aa0a Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 26 May 2024 19:02:52 -0700 Subject: [PATCH 05/30] Switch user and workdir --- .devcontainer/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d4d12c078..31718dd1f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -16,3 +16,7 @@ COPY --chown=${USERNAME}:${USERNAME} config ${HOME} # && apt-get autoremove -y \ # && apt-get clean -y \ # && rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/* + +# set user and working directory +USER ${USERNAME} +WORKDIR ${ROS_WORKSPACE} From 5925e3a0eae4b4470c45326be7b48e73f97b2b14 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 10:14:54 -0700 Subject: [PATCH 06/30] Use long argument names --- scripts/deployment/start_containers.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index 3c5bd1601..50b779258 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -11,7 +11,7 @@ BASE_TAG="latest" WEBSITE_ARG="" INTERACTIVE="" -# Function to display usage help +# function to display usage help usage() { echo "Usage: $0 [--tag tag] [--website]" echo " --tag Specify the base Docker image tag (default: latest)" @@ -49,11 +49,11 @@ done ## HELPER VARIABLES --- # get absolute path to workspace root in host OS -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +SCRIPT_DIR="$(dirname "$(readlink --canonicalize "$0")")" HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.." # common arguments for docker compose commmands -DOCKER_COMPOSE_ARGS="docker compose -f .devcontainer/docker-compose.yml $WEBSITE_ARG" +DOCKER_COMPOSE_ARGS="docker compose --project-name deployment --file .devcontainer/docker-compose.yml $WEBSITE_ARG" ## RUN COMMANDS --- @@ -66,7 +66,7 @@ SW_TAG=$BASE_TAG $DOCKER_COMPOSE_ARGS up --detach # run commands inside sailbot workspace container if [[ -n $INTERACTIVE ]]; then - $DOCKER_COMPOSE_ARGS exec -it sailbot-workspace /bin/bash + $DOCKER_COMPOSE_ARGS exec --interactive --tty sailbot-workspace /bin/bash else $DOCKER_COMPOSE_ARGS exec -T sailbot-workspace /bin/bash -c "\ cd \$ROS_WORKSPACE && \ From d196355ddae0eee6932e5688a03a6a9bbabb9c23 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 10:15:11 -0700 Subject: [PATCH 07/30] Use dev version of website --- scripts/deployment/start_containers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index 50b779258..08f636f75 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -29,7 +29,7 @@ while getopts ":-:" opt; do BASE_TAG="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) ;; website) - WEBSITE_ARG="-f .devcontainer/website/docker-compose.website.prod.yml" + WEBSITE_ARG="--file .devcontainer/website/docker-compose.website.yml" ;; interactive) INTERACTIVE="interactive" From 4d2d57e67353b0e37b34d5f794e84840aee30532 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 10:15:26 -0700 Subject: [PATCH 08/30] Rebuild on changes to dockerfiles --- scripts/deployment/start_containers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index 08f636f75..be164a7ec 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -62,7 +62,7 @@ DOCKER_COMPOSE_ARGS="docker compose --project-name deployment --file .devcontain cd $HOST_WORKSPACE_ROOT # start containers -SW_TAG=$BASE_TAG $DOCKER_COMPOSE_ARGS up --detach +SW_TAG=$BASE_TAG $DOCKER_COMPOSE_ARGS up --build --detach # run commands inside sailbot workspace container if [[ -n $INTERACTIVE ]]; then From c4819e6fdbfa7b3c7f68f0abe657134adb662636 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 10:28:00 -0700 Subject: [PATCH 09/30] Run software --- scripts/deployment/start_containers.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index be164a7ec..5b30be624 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -68,13 +68,12 @@ SW_TAG=$BASE_TAG $DOCKER_COMPOSE_ARGS up --build --detach if [[ -n $INTERACTIVE ]]; then $DOCKER_COMPOSE_ARGS exec --interactive --tty sailbot-workspace /bin/bash else - $DOCKER_COMPOSE_ARGS exec -T sailbot-workspace /bin/bash -c "\ - cd \$ROS_WORKSPACE && \ - pwd && \ + $DOCKER_COMPOSE_ARGS exec --no-TTY sailbot-workspace /bin/bash -c "\ + source /opt/ros/\$ROS_DISTRO/setup.bash && \ ./scripts/setup.sh && \ ./scripts/build.sh && \ - ./scripts/test.sh && \ - ls" + source ./install/local_setup.bash && \ + ros2 launch src/global_launch/main_launch.py" fi # stop containers From f163c82b1044089b077c6a15882dc0bc2caf6b28 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 10:29:38 -0700 Subject: [PATCH 10/30] Update argument usage --- scripts/deployment/start_containers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index 5b30be624..e8a430184 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -13,7 +13,7 @@ INTERACTIVE="" # function to display usage help usage() { - echo "Usage: $0 [--tag tag] [--website]" + echo "Usage: $0 [--tag tag] [--website] [--interactive]" echo " --tag Specify the base Docker image tag (default: latest)" echo " --website If set, runs the website container" echo " --interactive If set, run commands inside the sailbot workspace container interactively" From a882ab126c3fcac1ebb8a94b0c9526cfae77f0dd Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 10:36:59 -0700 Subject: [PATCH 11/30] Do not publish base and local-base images --- .devcontainer/base-dev/README.md | 16 +--------------- .github/workflows/build-images.yml | 30 +----------------------------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/.devcontainer/base-dev/README.md b/.devcontainer/base-dev/README.md index 7bda9e9c0..154f51121 100644 --- a/.devcontainer/base-dev/README.md +++ b/.devcontainer/base-dev/README.md @@ -62,23 +62,9 @@ If you want to push this to GitHub (instead of using the slow Build Images workf 1. Login to the GitHub container registry: [Authenticating with a personal access token (classic)](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic) -2. Push each image, replacing `` with the desired tag in the commands below +2. Push the image, replacing `` with the desired tag in the command below ``` - docker buildx build . \ - --file base-dev.Dockerfile \ - --tag ghcr.io/ubcsailbot/sailbot_workspace/base: \ - --platform linux/arm64,linux/amd64 \ - --builder sailbot \ - --target base \ - --push - docker buildx build . \ - --file base-dev.Dockerfile \ - --tag ghcr.io/ubcsailbot/sailbot_workspace/local-base: \ - --platform linux/arm64,linux/amd64 \ - --builder sailbot \ - --target local-base \ - --push docker buildx build . \ --file base-dev.Dockerfile \ --tag ghcr.io/ubcsailbot/sailbot_workspace/dev: \ diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 851aa2992..651f2bdd8 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: tag: - description: 'Tag of the base, local-base, and dev images' + description: 'Tag of the Docker image' required: true type: string @@ -33,34 +33,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.PAT_TOKEN }} - - name: Build and push base - uses: docker/build-push-action@v5 - with: - context: "{{defaultContext}}:.devcontainer/base-dev" - file: base-dev.Dockerfile - push: true - tags: | - ghcr.io/ubcsailbot/sailbot_workspace/base:${{ inputs.tag }} - ghcr.io/ubcsailbot/sailbot_workspace/base:latest - platforms: linux/arm64,linux/amd64 - cache-from: type=gha - cache-to: type=gha,mode=max - target: base - - - name: Build and push local-base - uses: docker/build-push-action@v5 - with: - context: "{{defaultContext}}:.devcontainer/base-dev" - file: base-dev.Dockerfile - push: true - tags: | - ghcr.io/ubcsailbot/sailbot_workspace/local-base:${{ inputs.tag }} - ghcr.io/ubcsailbot/sailbot_workspace/local-base:latest - platforms: linux/arm64,linux/amd64 - cache-from: type=gha - cache-to: type=gha,mode=max - target: local-base - - name: Build and push dev uses: docker/build-push-action@v5 with: From 5391eafbca90bbd6db1459e0344395dfb1f43aea Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 10:42:08 -0700 Subject: [PATCH 12/30] Improve argument parsing --- scripts/deployment/start_containers.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index e8a430184..e8f85c125 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -45,6 +45,10 @@ while getopts ":-:" opt; do esac done +# check for any remaining arguments after option parsing +if [ "$OPTIND" -le "$#" ]; then + usage +fi ## HELPER VARIABLES --- From 71bc4b6e4c6623c412413290f74e3c0562c57470 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 11:02:38 -0700 Subject: [PATCH 13/30] Add clean and reset arguments --- scripts/deployment/start_containers.sh | 33 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index e8f85c125..ed13066da 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -1,22 +1,24 @@ #!/bin/bash # TODO: check if it works without internet once built -# TODO: argument for deleting containers -# TODO: argument for deleting volumes ## CLI ARGUMENTS --- # default argument values BASE_TAG="latest" WEBSITE_ARG="" -INTERACTIVE="" +INTERACTIVE=false +CLEAN=false +RESET=false # function to display usage help usage() { - echo "Usage: $0 [--tag tag] [--website] [--interactive]" + echo "Usage: $0 [--tag tag] [--website] [--interactive] [--clean] [--reset]" echo " --tag Specify the base Docker image tag (default: latest)" echo " --website If set, runs the website container" echo " --interactive If set, run commands inside the sailbot workspace container interactively" + echo " --clean If set, removes containers after running" + echo " --reset If set, removes containers and volumes after running" exit 1 } @@ -32,7 +34,13 @@ while getopts ":-:" opt; do WEBSITE_ARG="--file .devcontainer/website/docker-compose.website.yml" ;; interactive) - INTERACTIVE="interactive" + INTERACTIVE=true + ;; + clean) + CLEAN=true + ;; + reset) + RESET=true ;; *) usage # Show usage if argument is not recognized @@ -57,7 +65,8 @@ SCRIPT_DIR="$(dirname "$(readlink --canonicalize "$0")")" HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.." # common arguments for docker compose commmands -DOCKER_COMPOSE_ARGS="docker compose --project-name deployment --file .devcontainer/docker-compose.yml $WEBSITE_ARG" +PROJECT_NAME="deployment" +DOCKER_COMPOSE_ARGS="docker compose --project-name $PROJECT_NAME --file .devcontainer/docker-compose.yml $WEBSITE_ARG" ## RUN COMMANDS --- @@ -69,7 +78,7 @@ cd $HOST_WORKSPACE_ROOT SW_TAG=$BASE_TAG $DOCKER_COMPOSE_ARGS up --build --detach # run commands inside sailbot workspace container -if [[ -n $INTERACTIVE ]]; then +if [[ "$INTERACTIVE" = true ]]; then $DOCKER_COMPOSE_ARGS exec --interactive --tty sailbot-workspace /bin/bash else $DOCKER_COMPOSE_ARGS exec --no-TTY sailbot-workspace /bin/bash -c "\ @@ -82,3 +91,13 @@ fi # stop containers $DOCKER_COMPOSE_ARGS stop + +# remove containers +if [[ "$CLEAN" == "true" ]] || [[ "$RESET" == "true" ]]; then + $DOCKER_COMPOSE_ARGS down +fi + +# remove volumes +if [[ "$RESET" = true ]]; then + docker volume ls -q | grep "^${PROJECT_NAME}_" | xargs -r docker volume rm +fi From 779249ca1f607280225132832ef9ab032b3f23c6 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 11:18:59 -0700 Subject: [PATCH 14/30] Update the deployment readme --- scripts/deployment/README.md | 40 ++++++++---------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/scripts/deployment/README.md b/scripts/deployment/README.md index 30e617e58..497fe4ddb 100644 --- a/scripts/deployment/README.md +++ b/scripts/deployment/README.md @@ -4,18 +4,6 @@ Deploying our software to our autonomous sailboat's main computer. ## Scripts -### `start_container.sh` - -Runs the [`base`](https://github.com/UBCSailbot/sailbot_workspace/blob/main/.devcontainer/base-dev/base-dev.Dockerfile) -image. A new container is created every time this is run. The default container name is `sailbot_deployment_container`. -Container names are unique, so if you want to use multiple deployment containers (e.g., from different branches) -you will have to update the variable `CONTAINER_NAME` in the script. - -Usage: - -- Runs the base image used by the Dev Container by default: `./start_container.sh` -- Run a specific version of the base image by specifying its ID: `./start_container.sh ` - ### `setup_boot.sh` Configures programs and scripts that need to run when the main computer boots. Only needs to be run once unless the @@ -24,27 +12,15 @@ renaming or moving the file. Usage: -- Must be run as root -- `sudo ./setup_boot.sh` +- Must be run as root: `sudo ./setup_boot.sh` -## Deployment container commands +### `start_containers.sh` -- Exit out of a container: `exit` -- Start an existing container: `docker start -ia ` -- Delete an existing container: `docker rm ` -- Find the container ID of a container: `docker ps -a` +Runs our Docker Compose files. -## Deploy software - -> These commands are run in the in the root directory of this repository - -1. Run the setup script: `./scripts/setup.sh` -2. Run the build script with the quick build flag: `./scripts/build.sh -q` - -## Develop software - -The deployment container isn't intended for development, but if you discover a bug and want to quickly push a fix: +Usage: -1. Fix the issue in a terminal ***outside*** the deployment container -2. Run the software to verify your fix in a terminal ***inside*** the deployment container -3. Commit and push your fix in a terminal ***outside*** the deployment container +- Runs the global launch file by default: `./start_containers.sh` +- Add the `--website` argument to additionally run the website container +- Add the `--interactive` argument to manually run commands in the sailbot workspace container +- Add the `--help` argument to see all available arguments From bbd23d4563f69ac4dd33116c923ac59dc00b9910 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 12:35:41 -0700 Subject: [PATCH 15/30] Can run without internet --- .devcontainer/docker-compose.yml | 2 +- scripts/deployment/start_containers.sh | 45 ++++++++++++++++++++------ scripts/setup.sh | 5 ++- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index c2d0beca1..bce9c9a73 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -27,7 +27,7 @@ services: # URL: mongodb://localhost:27017 mongodb: - image: mongo:7 + image: mongo:${MONGO_TAG:-7} restart: unless-stopped volumes: - mongodb-data:/data/db:delegated diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index ed13066da..4f9bdc462 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -1,11 +1,8 @@ #!/bin/bash -# TODO: check if it works without internet once built - ## CLI ARGUMENTS --- # default argument values -BASE_TAG="latest" WEBSITE_ARG="" INTERACTIVE=false CLEAN=false @@ -13,8 +10,7 @@ RESET=false # function to display usage help usage() { - echo "Usage: $0 [--tag tag] [--website] [--interactive] [--clean] [--reset]" - echo " --tag Specify the base Docker image tag (default: latest)" + echo "Usage: $0 [--website] [--interactive] [--clean] [--reset]" echo " --website If set, runs the website container" echo " --interactive If set, run commands inside the sailbot workspace container interactively" echo " --clean If set, removes containers after running" @@ -27,9 +23,6 @@ while getopts ":-:" opt; do case "${opt}" in -) case "${OPTARG}" in - tag) - BASE_TAG="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) - ;; website) WEBSITE_ARG="--file .devcontainer/website/docker-compose.website.yml" ;; @@ -58,24 +51,56 @@ if [ "$OPTIND" -le "$#" ]; then usage fi -## HELPER VARIABLES --- +## HELPER VARIABLES AND FUNCTIONS --- # get absolute path to workspace root in host OS SCRIPT_DIR="$(dirname "$(readlink --canonicalize "$0")")" HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.." # common arguments for docker compose commmands +MONGO_TAG="7" PROJECT_NAME="deployment" DOCKER_COMPOSE_ARGS="docker compose --project-name $PROJECT_NAME --file .devcontainer/docker-compose.yml $WEBSITE_ARG" +# function to pull the first FROM image from a specified Dockerfile +pull_from_image() { + # Check if Dockerfile path was provided as an argument + if [[ -z "$1" ]]; then + echo "No Dockerfile path specified." + return 1 # Return with error status + fi + + # The path to the Dockerfile is the first argument to the function + local dockerfile_path="$1" + + # Extract the image from the Dockerfile + local image=$(grep '^FROM' "$dockerfile_path" | head -n 1 | awk '{print $2}') + + # Check if the image variable is not empty + if [[ -n "$image" ]]; then + echo "Pulling Docker image: $image" + docker pull "$image" + else + echo "No image found in Dockerfile at $dockerfile_path." + return 1 # Return with error status + fi +} + ## RUN COMMANDS --- # run commands in the workspace's root directory cd $HOST_WORKSPACE_ROOT +# pull images if connected to the internet +if wget -q --spider --timeout=1 http://google.com; then + pull_from_image .devcontainer/Dockerfile + pull_from_image .devcontainer/website/website.Dockerfile + docker pull mongo:$MONGO_TAG +fi + # start containers -SW_TAG=$BASE_TAG $DOCKER_COMPOSE_ARGS up --build --detach +MONGO_TAG=$MONGO_TAG $DOCKER_COMPOSE_ARGS up --build --detach --pull never # run commands inside sailbot workspace container if [[ "$INTERACTIVE" = true ]]; then diff --git a/scripts/setup.sh b/scripts/setup.sh index b65ac1040..79e693c66 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -16,5 +16,8 @@ for DIR in $ROS_WORKSPACE/src/*; do done sudo apt-get update -rosdep update --rosdistro $ROS_DISTRO +if wget -q --spider --timeout=1 http://google.com; then + # only run if connected to the internet + rosdep update --rosdistro $ROS_DISTRO +fi rosdep install --from-paths src --ignore-src -y --rosdistro $ROS_DISTRO From b2078ad9a5cf6259d315e30076aa05f53f9f1b88 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 13:49:59 -0700 Subject: [PATCH 16/30] Ignore all node modules in web gitignore --- .gitignore | 3 --- src/website/.gitignore | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4f31605ba..66bd9526a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,3 @@ venv/ .cache/ # Build site/ - -# web -/src/website/tests/node_modules/* diff --git a/src/website/.gitignore b/src/website/.gitignore index 4efce6dbe..ffba29b02 100644 --- a/src/website/.gitignore +++ b/src/website/.gitignore @@ -1,7 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies -/node_modules +node_modules /.pnp .pnp.js From ab4276bfab807053f29a979353c990db74fe48c6 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 14:07:04 -0700 Subject: [PATCH 17/30] Add volume for web tests node modules --- .devcontainer/website/docker-compose.website.prod.yml | 2 ++ .devcontainer/website/docker-compose.website.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.devcontainer/website/docker-compose.website.prod.yml b/.devcontainer/website/docker-compose.website.prod.yml index 4b393765b..86655cc33 100644 --- a/.devcontainer/website/docker-compose.website.prod.yml +++ b/.devcontainer/website/docker-compose.website.prod.yml @@ -8,9 +8,11 @@ services: volumes: - ../src/website:/website:cached - website-node-modules:/website/node_modules:delegated + - website-tests-node-modules:/website/tests/node_modules:delegated # Runs on the same network as the workspace container, allows "forwardPorts" in devcontainer.json function. network_mode: service:sailbot-workspace volumes: website-node-modules: + website-tests-node-modules: diff --git a/.devcontainer/website/docker-compose.website.yml b/.devcontainer/website/docker-compose.website.yml index dd62aa603..02a3263b6 100644 --- a/.devcontainer/website/docker-compose.website.yml +++ b/.devcontainer/website/docker-compose.website.yml @@ -8,9 +8,11 @@ services: volumes: - ../src/website:/website:cached - website-node-modules:/website/node_modules:delegated + - website-tests-node-modules:/website/tests/node_modules:delegated # Runs on the same network as the workspace container, allows "forwardPorts" in devcontainer.json function. network_mode: service:sailbot-workspace volumes: website-node-modules: + website-tests-node-modules: From 287841ce679c32d55195d8f018b51b1c2a40bf12 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 14:12:06 -0700 Subject: [PATCH 18/30] clean and reset before running commands not after --- scripts/deployment/start_containers.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index 4f9bdc462..b18eb7ddb 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -13,8 +13,8 @@ usage() { echo "Usage: $0 [--website] [--interactive] [--clean] [--reset]" echo " --website If set, runs the website container" echo " --interactive If set, run commands inside the sailbot workspace container interactively" - echo " --clean If set, removes containers after running" - echo " --reset If set, removes containers and volumes after running" + echo " --clean If set, removes containers before running" + echo " --reset If set, removes containers and volumes before running" exit 1 } @@ -99,6 +99,16 @@ if wget -q --spider --timeout=1 http://google.com; then docker pull mongo:$MONGO_TAG fi +# remove containers +if [[ "$CLEAN" == "true" ]] || [[ "$RESET" == "true" ]]; then + $DOCKER_COMPOSE_ARGS down +fi + +# remove volumes +if [[ "$RESET" = true ]]; then + docker volume ls -q | grep "^${PROJECT_NAME}_" | xargs -r docker volume rm +fi + # start containers MONGO_TAG=$MONGO_TAG $DOCKER_COMPOSE_ARGS up --build --detach --pull never @@ -116,13 +126,3 @@ fi # stop containers $DOCKER_COMPOSE_ARGS stop - -# remove containers -if [[ "$CLEAN" == "true" ]] || [[ "$RESET" == "true" ]]; then - $DOCKER_COMPOSE_ARGS down -fi - -# remove volumes -if [[ "$RESET" = true ]]; then - docker volume ls -q | grep "^${PROJECT_NAME}_" | xargs -r docker volume rm -fi From 0aad7c93463765ead9c95c8d838a5e76cb425390 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 14:13:33 -0700 Subject: [PATCH 19/30] Downgrade mongodb to be compatible with rpi --- .devcontainer/docker-compose.yml | 2 +- scripts/deployment/start_containers.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index bce9c9a73..efec41acf 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -27,7 +27,7 @@ services: # URL: mongodb://localhost:27017 mongodb: - image: mongo:${MONGO_TAG:-7} + image: mongo:${MONGO_TAG:-4.4.18} restart: unless-stopped volumes: - mongodb-data:/data/db:delegated diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index b18eb7ddb..e2ed63096 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -58,7 +58,7 @@ SCRIPT_DIR="$(dirname "$(readlink --canonicalize "$0")")" HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.." # common arguments for docker compose commmands -MONGO_TAG="7" +MONGO_TAG="4.4.18" PROJECT_NAME="deployment" DOCKER_COMPOSE_ARGS="docker compose --project-name $PROJECT_NAME --file .devcontainer/docker-compose.yml $WEBSITE_ARG" From 225cd62e0a6a32066138a98f8fabf9e6eda60e43 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 14:23:07 -0700 Subject: [PATCH 20/30] Remove deprecated build option --- scripts/clang-tidy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/clang-tidy.sh b/scripts/clang-tidy.sh index d4f77e4e6..cb138a494 100755 --- a/scripts/clang-tidy.sh +++ b/scripts/clang-tidy.sh @@ -4,7 +4,7 @@ set -e if [[ $LOCAL_RUN != "true" ]]; then source /opt/ros/${ROS_DISTRO}/setup.bash ./scripts/setup.sh - ./scripts/build.sh RelWithDebInfo OFF + ./scripts/build.sh fi python3 scripts/ament_clang_tidy.py build/compile_commands.json --jobs 8 From c3a2c2dfe718cb29b0d849c8ed1910b74ffeddd7 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 14:23:21 -0700 Subject: [PATCH 21/30] Debugging failing CI --- scripts/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/build.sh b/scripts/build.sh index 6dac9b36d..01fb1060e 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e +ls -la + # Display a help message for using this script function helpMessage() { echo -e "Build ROS package(s) in the Sailbot Workspace." From 2f91e09fea5eea9e2b15fab5ad70e8261718691b Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 14:38:14 -0700 Subject: [PATCH 22/30] Give user ownership of ros workspace --- .devcontainer/Dockerfile | 2 ++ scripts/build.sh | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 31718dd1f..aefa5695f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -18,5 +18,7 @@ COPY --chown=${USERNAME}:${USERNAME} config ${HOME} # && rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/* # set user and working directory +RUN mkdir -p "${ROS_WORKSPACE}" \ + && chown "${USERNAME}" "${ROS_WORKSPACE}" USER ${USERNAME} WORKDIR ${ROS_WORKSPACE} diff --git a/scripts/build.sh b/scripts/build.sh index 01fb1060e..6dac9b36d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,8 +1,6 @@ #!/bin/bash set -e -ls -la - # Display a help message for using this script function helpMessage() { echo -e "Build ROS package(s) in the Sailbot Workspace." From 5d3a2afdcf62ee75fdbac570190eff85707da298 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 14:38:22 -0700 Subject: [PATCH 23/30] Add sudo to purge command --- sailbot.code-workspace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sailbot.code-workspace b/sailbot.code-workspace index 395cf4205..4b2a88f30 100644 --- a/sailbot.code-workspace +++ b/sailbot.code-workspace @@ -420,7 +420,7 @@ "label": "purge", "detail": "Purge workspace by deleting all generated files.", "type": "shell", - "command": "rm -fr build install log; py3clean .", + "command": "sudo rm -rf build install log; py3clean .", "problemMatcher": [] }, // Linting and static code analysis tasks From f8f05bdab0ed020afadfd8bf447af7eab74d7568 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Sun, 2 Jun 2024 18:45:55 -0700 Subject: [PATCH 24/30] Fiddle around with user permissions --- .devcontainer/Dockerfile | 2 +- scripts/clang-tidy.sh | 5 +++++ scripts/run-tests.sh | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index aefa5695f..b2d8dab83 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -19,6 +19,6 @@ COPY --chown=${USERNAME}:${USERNAME} config ${HOME} # set user and working directory RUN mkdir -p "${ROS_WORKSPACE}" \ - && chown "${USERNAME}" "${ROS_WORKSPACE}" + && chown ${USERNAME}:${USERNAME} ${ROS_WORKSPACE} USER ${USERNAME} WORKDIR ${ROS_WORKSPACE} diff --git a/scripts/clang-tidy.sh b/scripts/clang-tidy.sh index cb138a494..a967cb8df 100755 --- a/scripts/clang-tidy.sh +++ b/scripts/clang-tidy.sh @@ -2,6 +2,11 @@ set -e if [[ $LOCAL_RUN != "true" ]]; then + # give user permissions + ls -la $ROS_WORKSPACE + sudo chown -R $(whoami):$(whoami) $ROS_WORKSPACE + ls -la $ROS_WORKSPACE + source /opt/ros/${ROS_DISTRO}/setup.bash ./scripts/setup.sh ./scripts/build.sh diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 17484fa6e..092a51e76 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +# give user permissions +ls -la $ROS_WORKSPACE +sudo chown -R $(whoami):$(whoami) $ROS_WORKSPACE +ls -la $ROS_WORKSPACE + ./scripts/setup.sh ./scripts/build.sh ./scripts/test.sh From 79b6736e6e1be8369a4bf0b16aca7ac59f62b229 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Tue, 4 Jun 2024 14:42:16 -0700 Subject: [PATCH 25/30] Source in run-tests --- .devcontainer/Dockerfile | 2 -- scripts/clang-tidy.sh | 4 +--- scripts/run-tests.sh | 3 +-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b2d8dab83..31718dd1f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -18,7 +18,5 @@ COPY --chown=${USERNAME}:${USERNAME} config ${HOME} # && rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/* # set user and working directory -RUN mkdir -p "${ROS_WORKSPACE}" \ - && chown ${USERNAME}:${USERNAME} ${ROS_WORKSPACE} USER ${USERNAME} WORKDIR ${ROS_WORKSPACE} diff --git a/scripts/clang-tidy.sh b/scripts/clang-tidy.sh index a967cb8df..b894e74de 100755 --- a/scripts/clang-tidy.sh +++ b/scripts/clang-tidy.sh @@ -3,9 +3,7 @@ set -e if [[ $LOCAL_RUN != "true" ]]; then # give user permissions - ls -la $ROS_WORKSPACE - sudo chown -R $(whoami):$(whoami) $ROS_WORKSPACE - ls -la $ROS_WORKSPACE + sudo chown $(whoami):$(whoami) $ROS_WORKSPACE source /opt/ros/${ROS_DISTRO}/setup.bash ./scripts/setup.sh diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 092a51e76..2ba0cb652 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -2,10 +2,9 @@ set -e # give user permissions -ls -la $ROS_WORKSPACE sudo chown -R $(whoami):$(whoami) $ROS_WORKSPACE -ls -la $ROS_WORKSPACE +source /opt/ros/${ROS_DISTRO}/setup.bash ./scripts/setup.sh ./scripts/build.sh ./scripts/test.sh From f40e5644c9cbecfd29f11db8fe60ee16eb826b5d Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Tue, 4 Jun 2024 14:47:15 -0700 Subject: [PATCH 26/30] Cleanup --- scripts/clang-tidy.sh | 4 ++-- scripts/run-tests.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/clang-tidy.sh b/scripts/clang-tidy.sh index b894e74de..1ab4163b8 100755 --- a/scripts/clang-tidy.sh +++ b/scripts/clang-tidy.sh @@ -2,8 +2,8 @@ set -e if [[ $LOCAL_RUN != "true" ]]; then - # give user permissions - sudo chown $(whoami):$(whoami) $ROS_WORKSPACE + # give user permissions, required for GitHub Actions + sudo chown -R $(whoami):$(whoami) $ROS_WORKSPACE source /opt/ros/${ROS_DISTRO}/setup.bash ./scripts/setup.sh diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 2ba0cb652..be402a743 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -# give user permissions +# give user permissions, required for GitHub Actions sudo chown -R $(whoami):$(whoami) $ROS_WORKSPACE source /opt/ros/${ROS_DISTRO}/setup.bash From 77e15d51eddeb07bf02afa3a1cb418749830fd09 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Tue, 4 Jun 2024 14:58:22 -0700 Subject: [PATCH 27/30] Switch to prod version of website --- scripts/deployment/start_containers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index e2ed63096..321ee1ceb 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -24,7 +24,7 @@ while getopts ":-:" opt; do -) case "${OPTARG}" in website) - WEBSITE_ARG="--file .devcontainer/website/docker-compose.website.yml" + WEBSITE_ARG="--file .devcontainer/website/docker-compose.website.prod.yml" ;; interactive) INTERACTIVE=true From 47aed7cbdebc483d541107cd7c56c623c19c5db9 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Wed, 5 Jun 2024 09:18:58 -0700 Subject: [PATCH 28/30] Create run_software.sh and cleanup start_containers.sh --- scripts/README.md | 4 ++++ scripts/deployment/start_containers.sh | 22 +++++++++------------- scripts/run_software.sh | 9 +++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100755 scripts/run_software.sh diff --git a/scripts/README.md b/scripts/README.md index ca4a1311a..32f82bc25 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -61,6 +61,10 @@ Other relevant commands include (but are not limited to): Script to setup, build, and test all ROS packages. +## `run_software.sh` + +Script to setup, build, and run all ROS packages. + ## `setup.sh` Script to handle ROS setup. diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index 321ee1ceb..9cb09f958 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -51,6 +51,7 @@ if [ "$OPTIND" -le "$#" ]; then usage fi + ## HELPER VARIABLES AND FUNCTIONS --- # get absolute path to workspace root in host OS @@ -64,25 +65,25 @@ DOCKER_COMPOSE_ARGS="docker compose --project-name $PROJECT_NAME --file .devcont # function to pull the first FROM image from a specified Dockerfile pull_from_image() { - # Check if Dockerfile path was provided as an argument + # check if Dockerfile path was provided as an argument if [[ -z "$1" ]]; then echo "No Dockerfile path specified." return 1 # Return with error status fi - # The path to the Dockerfile is the first argument to the function + # path to the Dockerfile is the first argument to the function local dockerfile_path="$1" - # Extract the image from the Dockerfile + # extract the image from the Dockerfile local image=$(grep '^FROM' "$dockerfile_path" | head -n 1 | awk '{print $2}') - # Check if the image variable is not empty + # check if the image variable is not empty if [[ -n "$image" ]]; then echo "Pulling Docker image: $image" docker pull "$image" else echo "No image found in Dockerfile at $dockerfile_path." - return 1 # Return with error status + return 1 # return with error status fi } @@ -93,7 +94,7 @@ pull_from_image() { cd $HOST_WORKSPACE_ROOT # pull images if connected to the internet -if wget -q --spider --timeout=1 http://google.com; then +if wget --quiet --spider --timeout=1 http://google.com; then pull_from_image .devcontainer/Dockerfile pull_from_image .devcontainer/website/website.Dockerfile docker pull mongo:$MONGO_TAG @@ -106,7 +107,7 @@ fi # remove volumes if [[ "$RESET" = true ]]; then - docker volume ls -q | grep "^${PROJECT_NAME}_" | xargs -r docker volume rm + docker volume ls --quiet | grep "^${PROJECT_NAME}_" | xargs --no-run-if-empty docker volume rm fi # start containers @@ -116,12 +117,7 @@ MONGO_TAG=$MONGO_TAG $DOCKER_COMPOSE_ARGS up --build --detach --pull never if [[ "$INTERACTIVE" = true ]]; then $DOCKER_COMPOSE_ARGS exec --interactive --tty sailbot-workspace /bin/bash else - $DOCKER_COMPOSE_ARGS exec --no-TTY sailbot-workspace /bin/bash -c "\ - source /opt/ros/\$ROS_DISTRO/setup.bash && \ - ./scripts/setup.sh && \ - ./scripts/build.sh && \ - source ./install/local_setup.bash && \ - ros2 launch src/global_launch/main_launch.py" + $DOCKER_COMPOSE_ARGS exec --no-TTY sailbot-workspace /bin/bash -c "./scripts/run_software.sh" fi # stop containers diff --git a/scripts/run_software.sh b/scripts/run_software.sh new file mode 100755 index 000000000..eadfd08f5 --- /dev/null +++ b/scripts/run_software.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +cd $ROS_WORKSPACE +source /opt/ros/$ROS_DISTRO/setup.bash +./scripts/setup.sh +./scripts/build.sh +source ./install/local_setup.bash +ros2 launch src/global_launch/main_launch.py From 589479eaec4de0587e9b2dbd792335cb83c919a1 Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Wed, 5 Jun 2024 10:42:20 -0700 Subject: [PATCH 29/30] Make start_containers.sh compatible with mac --- scripts/deployment/README.md | 3 ++- scripts/deployment/start_containers.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/deployment/README.md b/scripts/deployment/README.md index 497fe4ddb..809a1449d 100644 --- a/scripts/deployment/README.md +++ b/scripts/deployment/README.md @@ -16,7 +16,8 @@ Usage: ### `start_containers.sh` -Runs our Docker Compose files. +Runs our Docker Compose files. You may have to install commands like `wget`. +Would recommend running this script in its own clone of sailbot_workspace (not the one you open in VS Code). Usage: diff --git a/scripts/deployment/start_containers.sh b/scripts/deployment/start_containers.sh index 9cb09f958..57febbaf4 100755 --- a/scripts/deployment/start_containers.sh +++ b/scripts/deployment/start_containers.sh @@ -55,7 +55,7 @@ fi ## HELPER VARIABLES AND FUNCTIONS --- # get absolute path to workspace root in host OS -SCRIPT_DIR="$(dirname "$(readlink --canonicalize "$0")")" +SCRIPT_DIR="$(dirname "$(realpath "$0")")" HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.." # common arguments for docker compose commmands From 339489ee4977c8b441706912f67cd5fb2128487a Mon Sep 17 00:00:00 2001 From: Patrick Creighton Date: Thu, 6 Jun 2024 11:10:53 -0700 Subject: [PATCH 30/30] Try specifying user in docker compose file --- .devcontainer/docker-compose.yml | 1 + scripts/run-tests.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index efec41acf..822e5b858 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -5,6 +5,7 @@ services: build: context: . dockerfile: Dockerfile + user: ros ports: # website - "3005:3005" diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index be402a743..3d692a9b2 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -2,6 +2,7 @@ set -e # give user permissions, required for GitHub Actions +ls -la sudo chown -R $(whoami):$(whoami) $ROS_WORKSPACE source /opt/ros/${ROS_DISTRO}/setup.bash