From f71d079d1568ad87f2395be229ee7f0a76b44727 Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Fri, 2 Jun 2023 20:10:49 -0700 Subject: [PATCH 01/11] Add initial devcontainer config --- .devcontainer/Dockerfile | 17 +++++++++++++++++ .devcontainer/devcontainer.json | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..f86a7d4 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,17 @@ +FROM osrf/ros:noetic-desktop-full + +# Copy library scripts to execute +COPY library-scripts/*.sh /tmp/library-scripts/ + +# [Option] Install zsh +ARG INSTALL_ZSH="true" +# [Option] Upgrade OS packages to their latest versions +ARG UPGRADE_PACKAGES="true" +# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + + +# Remove library scripts for final image +RUN rm -rf /tmp/library-scripts \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..263ef80 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,15 @@ +{ + "image": "osrf/ros:noetic-desktop-full", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "username": "vscode", + "userUid": "1001", + "userGid": "1001" + }, + "ghcr.io/devcontainers/features/docker-in-docker:2": {} + }, + "remoteUser": "vscode", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/catkin_ws/src/mushr,type=bind", + "workspaceFolder": "/home/vscode/catkin_ws", + "postCreateCommand": "sudo chown -R vscode:vscode /home/vscode/catkin_ws" +} From 65602670d3096672ddf2db0d345fe59888cd7e8f Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Fri, 2 Jun 2023 22:24:33 -0700 Subject: [PATCH 02/11] Update mushr_noetic to support 'run' and use it --- .devcontainer/devcontainer.json | 2 +- mushr_utils/install/mushr_install.bash | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 263ef80..8966762 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,5 +11,5 @@ "remoteUser": "vscode", "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/catkin_ws/src/mushr,type=bind", "workspaceFolder": "/home/vscode/catkin_ws", - "postCreateCommand": "sudo chown -R vscode:vscode /home/vscode/catkin_ws" + "postCreateCommand": "cd /home/vscode/catkin_ws/src && ./mushr/mushr_utils/install/mushr_install.bash && sudo chown -R vscode:vscode /home/vscode/catkin_ws" } diff --git a/mushr_utils/install/mushr_install.bash b/mushr_utils/install/mushr_install.bash index c5e4f08..c408dc1 100755 --- a/mushr_utils/install/mushr_install.bash +++ b/mushr_utils/install/mushr_install.bash @@ -109,7 +109,12 @@ export MUSHR_COMPOSE_FILE=${MUSHR_COMPOSE_FILE} export MUSHR_OS_TYPE=${MUSHR_OS_TYPE} if [ \$# == 0 ] || [ \$1 == "run" ]; then - docker-compose -f \$MUSHR_INSTALL_PATH/\$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash + if [ $# == 2 ]; + then + docker-compose -f \$MUSHR_INSTALL_PATH/\$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash -ic "\${2}" + else + docker-compose -f \$MUSHR_INSTALL_PATH/\$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash + fi elif [ \$1 == "build" ]; then docker-compose -f $MUSHR_INSTALL_PATH/$MUSHR_COMPOSE_FILE build --no-cache mushr_noetic From 99c043c059507669de12375a5b032e1a31ea030c Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Fri, 2 Jun 2023 22:26:25 -0700 Subject: [PATCH 03/11] Add example vscode tasks config --- .vscode/tasks.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..3e0f4f0 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + "tasks": [ + { + "label": "Roslaunch teleop.launch", + "type": "shell", + "command": "mushr_noetic run 'source ~/.bashrc && roslaunch mushr_sim teleop.launch'", + "problemMatcher": [] + }, + { + "label": "Start Foxglove Studio server", + "type": "shell", + "command": "docker run --rm -p \"8080:8080\" ghcr.io/foxglove/studio:latest", + "problemMatcher": [] + } + ] +} \ No newline at end of file From c8de37007a79ddb14899e93fefcfb8554beda506 Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Sat, 3 Jun 2023 09:23:12 -0700 Subject: [PATCH 04/11] Support --trivial-only in mushr_install.bash --- .devcontainer/devcontainer.json | 2 +- mushr_utils/install/mushr_install.bash | 25 +++++++++++++++++++++---- mushr_utils/install/mushr_noetic | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 mushr_utils/install/mushr_noetic diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8966762..dd85ae8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,5 +11,5 @@ "remoteUser": "vscode", "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/catkin_ws/src/mushr,type=bind", "workspaceFolder": "/home/vscode/catkin_ws", - "postCreateCommand": "cd /home/vscode/catkin_ws/src && ./mushr/mushr_utils/install/mushr_install.bash && sudo chown -R vscode:vscode /home/vscode/catkin_ws" + "postCreateCommand": "sudo chown -R vscode:vscode /home/vscode/catkin_ws && ln -s /home/vscode/catkin_ws/src/mushr/.vscode /home/vscode/catkin_ws/ && cd /home/vscode/catkin_ws/src && ./mushr/mushr_utils/install/mushr_install.bash --trivial-only && mushr_noetic run 'cd catkin_ws && catkin build'" } diff --git a/mushr_utils/install/mushr_install.bash b/mushr_utils/install/mushr_install.bash index c408dc1..5f7fbbb 100755 --- a/mushr_utils/install/mushr_install.bash +++ b/mushr_utils/install/mushr_install.bash @@ -1,6 +1,15 @@ #!/bin/bash pushd `dirname $0` +# Parse args +TRIVIAL_ONLY=0 +for arg in "$@"; do + if [ "$arg" == "--trivial-only" ]; then + TRIVIAL_ONLY=1 + break + fi +done + # Detect OS export MUSHR_OS_TYPE="$(uname -s)" @@ -12,8 +21,12 @@ fi export MUSHR_INSTALL_PATH=$(pwd) # Real robot or on a laptop? -read -p "Are you installing on robot and need all the sensor drivers? (y/n) " -r -echo +if [[ $TRIVIAL_ONLY == 0 ]]; then + read -p "Are you installing on robot and need all the sensor drivers? (y/n) " -r + echo +else + REPLY="n" +fi if [[ $REPLY =~ ^[Yy]$ ]]; then export MUSHR_REAL_ROBOT=1 export MUSHR_COMPOSE_FILE=docker-compose-robot.yml @@ -23,8 +36,12 @@ else fi # Build from scratch -read -p "Build from scratch? (Not recommended, takes much longer than pulling ready-made image) (y/n) " -r -echo +if [[ $TRIVIAL_ONLY == 0 ]]; then + read -p "Build from scratch? (Not recommended, takes much longer than pulling ready-made image) (y/n) " -r + echo +else + REPLY="n" +fi export BUILD_FROM_SCRATCH=0 if [[ $REPLY =~ ^[Yy]$ ]]; then export BUILD_FROM_SCRATCH=1 diff --git a/mushr_utils/install/mushr_noetic b/mushr_utils/install/mushr_noetic new file mode 100755 index 0000000..2d5ccfb --- /dev/null +++ b/mushr_utils/install/mushr_noetic @@ -0,0 +1,19 @@ +export MUSHR_INSTALL_PATH=/home/vscode/catkin_ws/src/mushr/mushr_utils/install +export MUSHR_REAL_ROBOT=0 +export MUSHR_WS_PATH=/home/vscode +export MUSHR_COMPOSE_FILE=docker-compose-cpu.yml +export MUSHR_OS_TYPE=x86_64 +if [ $# == 0 ] || [ $1 == "run" ]; +then + if [ 1 == 2 ]; + then + docker-compose -f $MUSHR_INSTALL_PATH/$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash -ic "${2}" + else + docker-compose -f $MUSHR_INSTALL_PATH/$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash + fi +elif [ $1 == "build" ]; +then + docker-compose -f /home/vscode/catkin_ws/src/mushr/mushr_utils/install/docker-compose-cpu.yml build --no-cache mushr_noetic +else + echo "Invalid command supplied to mushr_noetic script; valid commands are 'run' or 'build'" +fi From a74409190c1826b6827cb860fc13f3b15921a694 Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Sat, 3 Jun 2023 10:25:09 -0700 Subject: [PATCH 05/11] Bug fix: set shebang line --- mushr_utils/install/mushr_install.bash | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mushr_utils/install/mushr_install.bash b/mushr_utils/install/mushr_install.bash index 5f7fbbb..7b8bf8d 100755 --- a/mushr_utils/install/mushr_install.bash +++ b/mushr_utils/install/mushr_install.bash @@ -119,20 +119,21 @@ cd $MUSHR_WS_PATH/catkin_ws/src/ && vcs import < mushr/base-repos.yaml && vcs im # Make custom mushr_noetic script cat <<- EOF > ${MUSHR_INSTALL_PATH}/mushr_noetic +#!/bin/bash export MUSHR_INSTALL_PATH=${MUSHR_INSTALL_PATH} export MUSHR_REAL_ROBOT=${MUSHR_REAL_ROBOT} export MUSHR_WS_PATH=${MUSHR_WS_PATH} export MUSHR_COMPOSE_FILE=${MUSHR_COMPOSE_FILE} export MUSHR_OS_TYPE=${MUSHR_OS_TYPE} -if [ \$# == 0 ] || [ \$1 == "run" ]; +if [[ \$# == 0 ]] || [[ \$1 == "run" ]]; then - if [ $# == 2 ]; + if [[ \$# == 2 ]]; then docker-compose -f \$MUSHR_INSTALL_PATH/\$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash -ic "\${2}" else docker-compose -f \$MUSHR_INSTALL_PATH/\$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash fi -elif [ \$1 == "build" ]; +elif [[ \$1 == "build" ]]; then docker-compose -f $MUSHR_INSTALL_PATH/$MUSHR_COMPOSE_FILE build --no-cache mushr_noetic else From e4e60410282e8afc3182e83ebb8780dc75a1402d Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Sat, 3 Jun 2023 10:29:06 -0700 Subject: [PATCH 06/11] Remove autogenerated mushr_noetic --- mushr_utils/install/mushr_noetic | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100755 mushr_utils/install/mushr_noetic diff --git a/mushr_utils/install/mushr_noetic b/mushr_utils/install/mushr_noetic deleted file mode 100755 index 2d5ccfb..0000000 --- a/mushr_utils/install/mushr_noetic +++ /dev/null @@ -1,19 +0,0 @@ -export MUSHR_INSTALL_PATH=/home/vscode/catkin_ws/src/mushr/mushr_utils/install -export MUSHR_REAL_ROBOT=0 -export MUSHR_WS_PATH=/home/vscode -export MUSHR_COMPOSE_FILE=docker-compose-cpu.yml -export MUSHR_OS_TYPE=x86_64 -if [ $# == 0 ] || [ $1 == "run" ]; -then - if [ 1 == 2 ]; - then - docker-compose -f $MUSHR_INSTALL_PATH/$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash -ic "${2}" - else - docker-compose -f $MUSHR_INSTALL_PATH/$MUSHR_COMPOSE_FILE run -p 9090:9090 mushr_noetic bash - fi -elif [ $1 == "build" ]; -then - docker-compose -f /home/vscode/catkin_ws/src/mushr/mushr_utils/install/docker-compose-cpu.yml build --no-cache mushr_noetic -else - echo "Invalid command supplied to mushr_noetic script; valid commands are 'run' or 'build'" -fi From 82dd152908ec6474f1bc2527a3e1acb35b62228a Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Mon, 5 Jun 2023 16:52:48 -0700 Subject: [PATCH 07/11] Remove unused dockerfile --- .devcontainer/Dockerfile | 17 ----------------- .devcontainer/devcontainer.json | 4 ++-- 2 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index f86a7d4..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM osrf/ros:noetic-desktop-full - -# Copy library scripts to execute -COPY library-scripts/*.sh /tmp/library-scripts/ - -# [Option] Install zsh -ARG INSTALL_ZSH="true" -# [Option] Upgrade OS packages to their latest versions -ARG UPGRADE_PACKAGES="true" -# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies. -ARG USERNAME=vscode -ARG USER_UID=1000 -ARG USER_GID=$USER_UID - - -# Remove library scripts for final image -RUN rm -rf /tmp/library-scripts \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index dd85ae8..987f214 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,8 +3,8 @@ "features": { "ghcr.io/devcontainers/features/common-utils:2": { "username": "vscode", - "userUid": "1001", - "userGid": "1001" + "userUid": "1000", + "userGid": "1000" }, "ghcr.io/devcontainers/features/docker-in-docker:2": {} }, From 160965269aa4349de21eb5b2c03288294efe23fb Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Mon, 5 Jun 2023 17:49:01 -0700 Subject: [PATCH 08/11] Refactor --- .devcontainer/build.sh | 5 +++++ .devcontainer/devcontainer.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100755 .devcontainer/build.sh diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh new file mode 100755 index 0000000..4d291bf --- /dev/null +++ b/.devcontainer/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd /home/vscode/catkin_ws/src; +./mushr/mushr_utils/install/mushr_install.bash --trivial-only; +mushr_noetic run 'cd catkin_ws && catkin build' diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 987f214..c231c5c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,5 +11,5 @@ "remoteUser": "vscode", "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/catkin_ws/src/mushr,type=bind", "workspaceFolder": "/home/vscode/catkin_ws", - "postCreateCommand": "sudo chown -R vscode:vscode /home/vscode/catkin_ws && ln -s /home/vscode/catkin_ws/src/mushr/.vscode /home/vscode/catkin_ws/ && cd /home/vscode/catkin_ws/src && ./mushr/mushr_utils/install/mushr_install.bash --trivial-only && mushr_noetic run 'cd catkin_ws && catkin build'" + "postCreateCommand": "sudo chown -R vscode:vscode . && ln -s ${containerWorkspaceFolder}/src/mushr/.vscode ${containerWorkspaceFolder} && ./src/mushr/.devcontainer/build.sh" } From 6ffc1ea2f3f4a951ff8dd4b3120c5c3779388922 Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Tue, 6 Jun 2023 11:47:58 -0700 Subject: [PATCH 09/11] Add initial workflow config & test --- .devcontainer/smoke_test.sh | 14 ++++++++++++++ .github/workflows/devcontainer-test.sh | 21 +++++++++++++++++++++ .github/workflows/test-pr.yaml | 16 ++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100755 .devcontainer/smoke_test.sh create mode 100755 .github/workflows/devcontainer-test.sh create mode 100644 .github/workflows/test-pr.yaml diff --git a/.devcontainer/smoke_test.sh b/.devcontainer/smoke_test.sh new file mode 100755 index 0000000..cd0291a --- /dev/null +++ b/.devcontainer/smoke_test.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +mushr_noetic run 'source ~/.bashrc && roslaunch mushr_sim teleop.launch' > /tmp/output & +sleep 5 +if tail -n 1 /tmp/output | grep -q "Rosbridge WebSocket server started at ws://0.0.0.0:9090"; then + echo "✅ smoke_test passed" + exit 0; +else + # Print output of `roslaunch mushr_sim teleop.launch` for debugging + cat /tmp/output + echo "❌ smoke_test failed" + exit 1; +fi \ No newline at end of file diff --git a/.github/workflows/devcontainer-test.sh b/.github/workflows/devcontainer-test.sh new file mode 100755 index 0000000..a04022c --- /dev/null +++ b/.github/workflows/devcontainer-test.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +SRC_DIR="$(pwd)" + +echo "Running Smoke Test" + +# Build +export DOCKER_BUILDKIT=1 +echo "(*) Installing @devcontainer/cli" +npm install -g @devcontainers/cli + +echo "Building Dev Container" +ID_LABEL="test-container=mushr" +devcontainer up --id-label ${ID_LABEL} --workspace-folder "${SRC_DIR}" + +# Test +devcontainer exec --workspace-folder "${SRC_DIR}" --id-label ${ID_LABEL} /bin/sh -c './src/mushr/.devcontainer/smoke_test.sh' + +# Clean up +docker rm -f $(docker container ls -f "label=${ID_LABEL}" -q) diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml new file mode 100644 index 0000000..2cb966d --- /dev/null +++ b/.github/workflows/test-pr.yaml @@ -0,0 +1,16 @@ +name: "CI" +on: + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout main + id: checkout_release + uses: actions/checkout@v3 + - name: Devcontainer container smoke test + id: test_devcontainer + shell: bash + run: ./.github/workflows/devcontainer-test.sh \ No newline at end of file From dd25d4c114f128d2b10d44521e6cee80810c7532 Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Tue, 6 Jun 2023 22:51:43 -0700 Subject: [PATCH 10/11] Add roslaunch-teleop-test and start-foxglove-studio tests to smoke_test.sh script. --- .devcontainer/smoke_test.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.devcontainer/smoke_test.sh b/.devcontainer/smoke_test.sh index cd0291a..1769ac5 100755 --- a/.devcontainer/smoke_test.sh +++ b/.devcontainer/smoke_test.sh @@ -1,14 +1,23 @@ #!/bin/bash set -e -mushr_noetic run 'source ~/.bashrc && roslaunch mushr_sim teleop.launch' > /tmp/output & +mushr_noetic run 'source ~/.bashrc && roslaunch mushr_sim teleop.launch' > /tmp/output_roslaunch & sleep 5 -if tail -n 1 /tmp/output | grep -q "Rosbridge WebSocket server started at ws://0.0.0.0:9090"; then - echo "✅ smoke_test passed" - exit 0; +if tail -n 1 /tmp/output_roslaunch | grep -q "Rosbridge WebSocket server started at ws://0.0.0.0:9090"; then + echo "✅ roslaunch-teleop-test passed" else - # Print output of `roslaunch mushr_sim teleop.launch` for debugging - cat /tmp/output - echo "❌ smoke_test failed" + cat /tmp/output_roslaunch # print output for debugging purposes + echo "❌ roslaunch-teleop-test failed" exit 1; -fi \ No newline at end of file +fi + +docker run --rm -p "8080:8080" ghcr.io/foxglove/studio:latest & +sleep 10; +if curl -sSf http://localhost:8080 >/dev/null; then + echo "✅ start-foxglove-studio passed" +else + echo "❌ start-foxglove-studio failed" + exit 1; +fi + +exit 0; \ No newline at end of file From b142ece277d022b8f07121446e71345aed0ec046 Mon Sep 17 00:00:00 2001 From: Michael Jae-Yoon Chung Date: Tue, 13 Jun 2023 21:00:33 -0700 Subject: [PATCH 11/11] Handle comment --- .devcontainer/build.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh index 4d291bf..ebdf864 100755 --- a/.devcontainer/build.sh +++ b/.devcontainer/build.sh @@ -1,5 +1,12 @@ #!/bin/bash -cd /home/vscode/catkin_ws/src; -./mushr/mushr_utils/install/mushr_install.bash --trivial-only; +# This script is meant to be executed within the "postCreateCommand" field in +# .devcontainer/devcontainer.json, i.e., it expects the devcontainer config to install +# necessary folders with source code beforehand. + +set -eo pipefail +set -x + +cd "${HOME}"/catkin_ws/src +./mushr/mushr_utils/install/mushr_install.bash --trivial-only mushr_noetic run 'cd catkin_ws && catkin build'