Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Run simulation in the CodeSpaces container (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcahoon authored Jul 2, 2024
1 parent aceb624 commit 44d4cc1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 49 deletions.
36 changes: 36 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/java
{
"name": "Java",
"image": "mcr.microsoft.com/devcontainers/java:1-17-bookworm",

"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "17"
},
"ghcr.io/devcontainers/features/python:1": {
"installTools": true,
"version": "3.12"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8000],

"portsAttributes": {
"5800": {
"label": "Robot code HTML dashboard",
"onAutoForward": "silent"
},
"7778": {
// This port is only used locally; the HTTP server exposes this to the client via a proxy.
"label": "Simulation WebSockets",
"onAutoForward": "silent"
},
"8000": {
// This port is only used locally; the HTTP server exposes this to the client via a proxy.
"label": "Simulation HTTP",
"onAutoForward": "openBrowser"
}
}
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,7 @@ bin/
/sim_robots.lst

# Don't commit logs written by the framework when running in sim
/sim_robot_logs
/sim_robot_logs

# Don't commit the cache of downloaded sim files
/buildSim/
63 changes: 16 additions & 47 deletions deploy_sim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,27 @@
set -euo pipefail

builtin cd "$(dirname -- "${BASH_SOURCE[0]}")"

if [ $# -gt 0 ]; then
server="$1"
elif [ -f sim_robots.lst ]; then
PS3="Which sim robot would you like to use? "
COLUMNS=1
cancel_option="Cancel Deployment"
select name in $(cat sim_robots.lst) "$cancel_option"
do
server="${name-"$REPLY"}"
break
done
if [ "$server" == "$cancel_option" ]; then
echo "Canceled"
exit
fi
fi

if [ -z "${server-}" ]; then
# Sleep here is necessary to allow Theia to finish opening the task terminal
# before displaying the error message.
sleep 1
echo "Please supply the URL of the sim robot"
exit 1
fi

echo -e "Deploying to $server\n"

set -x

user="root"
project_base="$(pwd)"

./gradlew jar

jar_file=( build/libs/*.jar )
jar_file=( $(readlink -f build/libs/*.jar) )
[ "${#jar_file[@]}" -eq 1 ] || (echo "Output jar file could not be determined"; exit 1)

version="$(md5sum < "$jar_file" | awk '{ print $1 }')"
deployed_code="/tmp/project-$(date +%s)-$version"

rm -rf "$deployed_code"
mkdir -p "$deployed_code"
mkdir -p buildSim
cd buildSim

cp "$jar_file" "$deployed_code/project.jar"
cp -R src/main/deploy "$deployed_code"
cp simConfig.txt "$deployed_code"
sim_package="sim.tar.gz"
t1="$(stat -c %y "$sim_package" || true)"
wget -N "https://github.com/Team766/2020Sim/releases/latest/download/$sim_package" || [ -f "$sim_package" ] || exit 1
t2="$(stat -c %y "$sim_package")"

deployed_package=${deployed_code}.tgz
tar cfz ${deployed_package} -C ${deployed_code} .

curl --fail -F "package=@${deployed_package}" ${server}:4000/uploadrobotcode
extracted_dir="files"
if [ "$t1" != "$t2" -o ! -d "$extracted_dir" ]; then
rm -rf "$extracted_dir"
mkdir -p "$extracted_dir"
tar --directory="$extracted_dir" -xf "$sim_package"
fi
cd "$extracted_dir"

set +x
echo -e "\nDeploy finished. Your code is running"
echo -e "\nOpen simulation viewer at http://$server"
exec ./run.sh "$project_base" "$jar_file"
1 change: 0 additions & 1 deletion simConfig.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"logFilePath": "sim_robot_logs",
"drive": {
"leftMotor": {
"deviceId": 6,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/team766/web/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void handle(final HttpExchange exchange) throws IOException {
throw ex;
}
response += "</body></html>";
exchange.getResponseHeaders().set("Content-Type", "text/html");
exchange.sendResponseHeaders(200, response.getBytes().length);
try (OutputStream os = exchange.getResponseBody()) {
os.write(response.getBytes());
Expand Down

0 comments on commit 44d4cc1

Please sign in to comment.