From b21e268306570db0fe22b400317ad82065287854 Mon Sep 17 00:00:00 2001
From: Patrick Creighton <pcreighton429@gmail.com>
Date: Wed, 6 Mar 2024 12:10:31 -0800
Subject: [PATCH] Integrate website into tests (#235)

* Run website by default

* Run website by default in CI

* Pin mongodb major version

* Clean and populate sailbot_db before running tests

* Checkout net when running local pathfinding

* Print website logs

* Run setup script first

* Run container first

* Cleanup

* Run setup automatically after rebuild

* Forward website port in compose file

* Checkout website repo in local pathfinding CI

* Another missing repo for local pathfinding ci

* Revert local pathfinding branch

---------

Co-authored-by: Sean Donaghy <118148642+SPDonaghy@users.noreply.github.com>
---
 .devcontainer/devcontainer.json       |  5 ++---
 .devcontainer/docker-compose.db.yml   | 23 -----------------------
 .devcontainer/docker-compose.yml      | 19 +++++++++++++++++++
 .github/actions/ament-lint/action.yml |  6 +++---
 .github/actions/checkout/action.yml   | 16 +++++++++++++++-
 .github/actions/clang-tidy/action.yml |  6 +++---
 .github/actions/test/action.yml       | 11 +++++++----
 test.sh                               | 11 ++++++++++-
 8 files changed, 59 insertions(+), 38 deletions(-)
 delete mode 100644 .devcontainer/docker-compose.db.yml

diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 1dfcb3898..3887c2ad8 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -3,14 +3,12 @@
 	"name": "Sailbot Workspace",
 	"dockerComposeFile": [
 		// Uncomment the files containing the programs you need
-		"docker-compose.db.yml", // mongodb
 		// "docker-compose.docs.yml", // docs
-		// "docker-compose.website.yml", // website
+		"docker-compose.website.yml", // website
 
 		"docker-compose.yml"
 	],
 	"forwardPorts": [
-		3005, // website
 		8000  // docs
 	],
 	"service": "sailbot-workspace",
@@ -19,6 +17,7 @@
 	"containerEnv": {
 		"LIBGL_ALWAYS_SOFTWARE": "1" // Needed for software rendering of opengl
 	},
+	"postCreateCommand": "./setup.sh",
 	// Set *default* container specific settings.json values on container create.
 	"customizations": {
 		"codespaces": {
diff --git a/.devcontainer/docker-compose.db.yml b/.devcontainer/docker-compose.db.yml
deleted file mode 100644
index fc6638274..000000000
--- a/.devcontainer/docker-compose.db.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-# adapted from https://github.com/microsoft/vscode-dev-containers/blob/main/containers/javascript-node-mongo/.devcontainer/docker-compose.yml
-# Note: the "ports" property in this file will not forward from a codespace; add to "forwardPorts" in devcontainer.json instead
-version: '3.8'
-
-services:
-  # URL: mongodb://localhost:27017
-  mongodb:
-    image: mongo:latest
-    restart: unless-stopped
-    volumes:
-      - mongodb-data:/data/db:delegated
-
-    # Runs on the same network as the workspace container, allows "forwardPorts" in devcontainer.json function.
-    network_mode: service:sailbot-workspace
-
-    # Uncomment to change startup options
-    # environment:
-    #  MONGO_INITDB_ROOT_USERNAME: root
-    #  MONGO_INITDB_ROOT_PASSWORD: example
-    #  MONGO_INITDB_DATABASE: your-database-here
-
-volumes:
-  mongodb-data:
diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml
index da1dc0148..e46a00b96 100644
--- a/.devcontainer/docker-compose.yml
+++ b/.devcontainer/docker-compose.yml
@@ -7,6 +7,8 @@ services:
     build:
       context: .
       dockerfile: Dockerfile
+    ports:
+      - "3005:3005"
     volumes:
       - ..:/workspaces/sailbot_workspace:cached
       - sailbot-new-project-bashhistory:/home/ros/commandhistory:delegated
@@ -22,6 +24,23 @@ services:
     - seccomp:unconfined
     - apparmor:unconfined
 
+  # URL: mongodb://localhost:27017
+  mongodb:
+    image: mongo:7
+    restart: unless-stopped
+    volumes:
+      - mongodb-data:/data/db:delegated
+
+    # Runs on the same network as the workspace container, allows "forwardPorts" in devcontainer.json function.
+    network_mode: service:sailbot-workspace
+
+    # Uncomment to change startup options
+    # environment:
+    #  MONGO_INITDB_ROOT_USERNAME: root
+    #  MONGO_INITDB_ROOT_PASSWORD: example
+    #  MONGO_INITDB_DATABASE: your-database-here
+
 volumes:
+  mongodb-data:
   sailbot-new-project-bashhistory:
   sailbot-new-project-roslog:
diff --git a/.github/actions/ament-lint/action.yml b/.github/actions/ament-lint/action.yml
index e18805155..79da9f142 100644
--- a/.github/actions/ament-lint/action.yml
+++ b/.github/actions/ament-lint/action.yml
@@ -14,12 +14,12 @@ runs:
   steps:
     - name: Build Containers
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml build
+      run: docker compose -f .devcontainer/docker-compose.yml build
 
     - name: Run Containers
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml up -d
+      run: docker compose -f .devcontainer/docker-compose.yml up -d
 
     - name: Run Tests
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml exec -T sailbot-workspace /bin/bash -c "export LINTER=${{ inputs.linter}} && export DISABLE_VCS=${{ inputs.disable_vcs }} && cd /workspaces/sailbot_workspace && .github/actions/ament-lint/run.sh"
+      run: docker compose -f .devcontainer/docker-compose.yml exec -T sailbot-workspace /bin/bash -c "export LINTER=${{ inputs.linter}} && export DISABLE_VCS=${{ inputs.disable_vcs }} && cd /workspaces/sailbot_workspace && .github/actions/ament-lint/run.sh"
diff --git a/.github/actions/checkout/action.yml b/.github/actions/checkout/action.yml
index ad0e28fe2..ffae33a44 100644
--- a/.github/actions/checkout/action.yml
+++ b/.github/actions/checkout/action.yml
@@ -23,8 +23,22 @@ runs:
           repository: UBCSailbot/custom_interfaces
           path: src/custom_interfaces
 
+    - name: Checkout network_systems ROS package
+      if: ${{ inputs.repository != 'sailbot_workspace' && inputs.repository == 'local_pathfinding' }}
+      uses: actions/checkout@v4
+      with:
+          repository: UBCSailbot/network_systems
+          path: src/network_systems
+
+    - name: Checkout website ROS package
+      if: ${{ inputs.repository != 'sailbot_workspace' && inputs.repository == 'local_pathfinding' }}
+      uses: actions/checkout@v4
+      with:
+          repository: UBCSailbot/website
+          path: src/website
+
     - name: Checkout virtual_iridium repository
-      if: ${{ inputs.repository != 'sailbot_workspace' && inputs.repository == 'network_systems' }}
+      if: ${{ inputs.repository != 'sailbot_workspace' && (inputs.repository == 'network_systems' || inputs.repository == 'local_pathfinding') }}
       uses: actions/checkout@v4
       with:
           repository: UBCSailbot/virtual_iridium
diff --git a/.github/actions/clang-tidy/action.yml b/.github/actions/clang-tidy/action.yml
index d8b5a9039..e8dc13e15 100644
--- a/.github/actions/clang-tidy/action.yml
+++ b/.github/actions/clang-tidy/action.yml
@@ -11,12 +11,12 @@ runs:
   steps:
     - name: Build Containers
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml build
+      run: docker compose -f .devcontainer/docker-compose.yml build
 
     - name: Run Containers
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml up -d
+      run: docker compose -f .devcontainer/docker-compose.yml up -d
 
     - name: Run Tests
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml exec -T sailbot-workspace /bin/bash -c "export DISABLE_VCS=${{ inputs.disable_vcs }} && cd /workspaces/sailbot_workspace && .github/actions/clang-tidy/run.sh"
+      run: docker compose -f .devcontainer/docker-compose.yml exec -T sailbot-workspace /bin/bash -c "export DISABLE_VCS=${{ inputs.disable_vcs }} && cd /workspaces/sailbot_workspace && .github/actions/clang-tidy/run.sh"
diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml
index 46da4d182..68241e1c7 100644
--- a/.github/actions/test/action.yml
+++ b/.github/actions/test/action.yml
@@ -9,14 +9,17 @@ inputs:
 runs:
   using: "composite"
   steps:
-    - name: Build Containers
+    # TODO: remove once monorepo and combine website docker compose into main one
+    - name: Setup Code
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml -f .devcontainer/docker-compose.db.yml build
+      run: |
+        docker compose -f .devcontainer/docker-compose.yml up -d
+        docker compose -f .devcontainer/docker-compose.yml exec -T sailbot-workspace /bin/bash -c "export DISABLE_VCS=${{ inputs.disable_vcs }} && cd /workspaces/sailbot_workspace && ./setup.sh"
 
     - name: Run Containers
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml -f .devcontainer/docker-compose.db.yml up -d
+      run: docker compose -f .devcontainer/docker-compose.yml -f .devcontainer/docker-compose.website.yml up -d
 
     - name: Run Tests
       shell: bash
-      run: docker-compose -f .devcontainer/docker-compose.yml -f .devcontainer/docker-compose.db.yml exec -T sailbot-workspace /bin/bash -c "export DISABLE_VCS=${{ inputs.disable_vcs }} && cd /workspaces/sailbot_workspace && .github/actions/test/run.sh"
+      run: docker compose -f .devcontainer/docker-compose.yml -f .devcontainer/docker-compose.website.yml exec -T sailbot-workspace /bin/bash -c "export DISABLE_VCS=${{ inputs.disable_vcs }} && cd /workspaces/sailbot_workspace && .github/actions/test/run.sh"
diff --git a/test.sh b/test.sh
index b9d234f90..b1d9cd032 100755
--- a/test.sh
+++ b/test.sh
@@ -13,7 +13,16 @@ trap 'exit' INT TERM
 trap 'signal_handler' EXIT
 
 if [ -f install/local_setup.bash ]; then source install/local_setup.bash; fi
-if [ -d src/network_systems ]; then ./run_virtual_iridium.sh &> /dev/null & fi
+
+NET_DIR=src/network_systems
+if [ -d $NET_DIR ]; then
+    ./run_virtual_iridium.sh &> /dev/null &
+    pushd $NET_DIR
+    ./scripts/sailbot_db sailbot_db --clear
+    ./scripts/sailbot_db sailbot_db --populate
+    popd
+fi
+
 colcon test --packages-ignore virtual_iridium --merge-install --event-handlers console_cohesion+
 colcon test-result
 exit 0