forked from osrf/car_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
71,434 additions
and
47,462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ Ogre.log | |
*.swp | ||
*.gch | ||
*.pch | ||
*.pem | ||
*.pem.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# PriusCup Docker Image | ||
|
||
## Building | ||
These steps will walk through creating a docker image for PriusCup. | ||
|
||
### Step 0 - Prerequisites | ||
1. [Install docker](https://docs.docker.com/engine/installation/) | ||
2. [Install nvidia-docker](https://github.com/NVIDIA/nvidia-docker/wiki/Installation) | ||
|
||
### Step 1 - Build simulation-base | ||
|
||
``` | ||
cd priuscup/docker/simulation-base | ||
./build.bash | ||
``` | ||
|
||
### Step 2 - Build cloudsim-sim-base | ||
``` | ||
cd priuscup/docker/cloudsim-sim-base | ||
./build.bash | ||
``` | ||
|
||
### Step 3 - Build precious | ||
``` | ||
cd priuscup/docker/precious | ||
./build.bash | ||
``` | ||
1. This script will output a public ssh key. Add this key to your bitbucket account. | ||
2. Tag the output image to `precious:latest` | ||
``` | ||
sudo docker tag precious:2017_Jan_12_1914 precious:latest | ||
``` | ||
|
||
## S3 bucket file upload | ||
|
||
1. To enable uploading prius data to s3 bucket, create an `aws_s3_keys.bash` | ||
file in `priuscup/aws` and export `AWS_ACCESS_KEY_ID` and | ||
`AWS_SECRET_ACCESS_KEY` variables. | ||
|
||
|
||
## Testing Locally | ||
### option 1: cloudsim_deploy.bash | ||
1. Start the docker image | ||
``` | ||
cd priuscup/aws | ||
echo "CLOUDSIM_ADMIN=\"abc\"" > $dir/cloudsim-env.bash | ||
echo "{}" > cloudsim-options.bash | ||
./cloudsim_deploy.bash --no-shutdown | ||
``` | ||
2. Open a browser to `http://127.0.0.1/` | ||
|
||
### option 2: run-local.bash | ||
``` | ||
cd priuscup/aws | ||
./run-local.bash | ||
``` | ||
After a few seconds a firefox window will open to `127.0.0.1` | ||
|
||
## Deploying to AWS | ||
1. Start a g2.2xlarge instance with the AMI *ubuntu-nvidia-docker-16GiB* *ami-b71142d7* | ||
2. Use the following script to copy the image to the instance | ||
``` | ||
cd priuscup/aws | ||
./deploy-ec2.bash | ||
``` | ||
3. SSH into the instance and create the file `/home/ubuntu/code/aws_s3_keys.bash` | ||
modifying the contents below appropriately | ||
``` | ||
export AWS_ACCESS_KEY_ID=idOfBucketWriterUser | ||
export AWS_SECRET_ACCESS_KEY=secretKeyOfBucketWriterUser | ||
``` | ||
4. Save the AMI | ||
|
||
## Setting up a local demo | ||
1. Build a docker image (see instructions above) | ||
2. Save the image to a tar archive | ||
`sudo docker save --output=/tmp/precious.tar precious:latest` | ||
3. Copy the tar archive to the demo machine and load it into docker | ||
`sudo docker load --input=/tmp/precious.tar` | ||
4. Copy the `aws` folder to the demo machine | ||
5. To start a demo on the local machine, call `./run-local.bash` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env bash | ||
# launch docker container, providing env and options | ||
|
||
|
||
extra_opts="" | ||
cmd="" | ||
do_shutdown=1 | ||
container_name=aws_priuscup_$(date +%Y_%b_%d_%H%M) | ||
|
||
|
||
if [ $# -eq 1 ] | ||
then | ||
if [ "--debug" = $1 ] | ||
then | ||
# make it easy to run gdb inside the container | ||
extra_opts="-it --security-opt seccomp=unconfined" | ||
cmd=bash | ||
do_shutdown=0 | ||
elif [ "--no-shutdown" = $1 ] | ||
then | ||
do_shutdown=0 | ||
fi | ||
fi | ||
|
||
|
||
{ | ||
# Stop the container after 50 minutes | ||
sleep 3000 | ||
echo "TIMEOUT TIMEOUT TIMEOUT" | ||
sudo docker stop $container_name | ||
} & | ||
timer_pid=$! | ||
|
||
|
||
until sudo nvidia-docker ps | ||
do | ||
echo "Waiting for docker server" | ||
sleep 1 | ||
done | ||
|
||
# cloudsim_deploy lives in the same folder as cloudsim_env.bash and cloudsim_options.json | ||
code_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
# Make sure processes in the container can connect to the x server | ||
# Necessary so gazebo can create a context for OpenGL rendering (even headless) | ||
XAUTH=/tmp/.docker.xauth | ||
if [ ! -f $XAUTH ] | ||
then | ||
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/') | ||
if [ ! -z "$xauth_list" ] | ||
then | ||
echo $xauth_list | xauth -f $XAUTH nmerge - | ||
else | ||
touch $XAUTH | ||
fi | ||
chmod a+r $XAUTH | ||
fi | ||
|
||
# Display is hard-coded to :0 because that's what the startup scripts on AWS will generate | ||
eval sudo nvidia-docker run \ | ||
-e DISPLAY=unix:0 \ | ||
-e XAUTHORITY=$XAUTH \ | ||
-v "$XAUTH:$XAUTH" \ | ||
-v "/tmp/.X11-unix:/tmp/.X11-unix" \ | ||
-v "/etc/localtime:/etc/localtime:ro" \ | ||
-v "$code_dir:/code:ro" \ | ||
-p 4000:4000 \ | ||
-p 80:8080 \ | ||
--rm=true \ | ||
--name $container_name \ | ||
$extra_opts precious:latest $cmd | ||
|
||
|
||
# Stop the timeout timer | ||
kill -SIGKILL $timer_pid | ||
|
||
|
||
if [ $do_shutdown -eq 1 ] | ||
then | ||
# Stop the amazon instance (saves money) | ||
sudo shutdown -hP now | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash -e | ||
|
||
if [ $# -ne 3 ] | ||
then | ||
echo "Usage: $0 <docker image:tag> <path to ssh key> <user name>@<ec2host>" | ||
exit 1 | ||
fi | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
image_name=$1 | ||
path_to_key=$2 | ||
dest=$3 | ||
|
||
|
||
# Copy startup folder to instance | ||
scp -r -i $path_to_key $DIR/startup $dest: | ||
ssh -i $path_to_key $dest './startup/install.bash' | ||
|
||
# copy the cloudsim_deploy.bash script to the ec2 instance | ||
scp -i $path_to_key $DIR/cloudsim_deploy.bash $dest:code/cloudsim_deploy.bash | ||
|
||
# Get password before piping stuff | ||
sudo echo "Loading" | ||
|
||
# Copy the docker image to an ec2 instance running ubuntu-nvidia-docker AMI | ||
sudo docker save $image_name | bzip2 | pv | ssh -i $path_to_key $dest 'bunzip2 | docker load' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#/usr/bin/env bash | ||
|
||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
PROFILEDIR=$(mktemp -p /tmp -d tmp-fx-profile.XXXXXX.d) | ||
|
||
function cleanup { | ||
echo "Post run cleanup!" | ||
rm -rf $PROFILEDIR | ||
sudo docker stop $(sudo docker ps -aq --filter 'name=aws_priuscup_') | ||
} | ||
trap cleanup EXIT | ||
|
||
# start precious software in the background | ||
echo "{}" > $dir/cloudsim-options.json | ||
echo "CLOUDSIM_ADMIN=\"abc\"" > $dir/cloudsim-env.bash | ||
$dir/cloudsim_deploy.bash --no-shutdown & | ||
echo "Waiting for precious to start" | ||
sleep 10 | ||
|
||
# start a web browser | ||
firefox -profile $PROFILEDIR -no-remote -new-instance 127.0.0.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=X server with virtual screen | ||
|
||
[Service] | ||
ExecStart=/usr/bin/Xorg :0 -config /home/ubuntu/startup/xorg.conf | ||
|
||
|
||
[Install] | ||
WantedBy=docker.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Configures an EC2 instance running ubuntu-nvidia-docker-16GiB | ||
|
||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
# Need to start an Xorg server with some custom options on :0 | ||
# but lightdm already starts an Xserver on that display, so stop it first | ||
echo "stopping lightdm" | ||
sudo service lightdm stop | ||
echo "disapling lightdm" | ||
sudo systemctl disable lightdm | ||
echo "enabling custom Xorg service" | ||
sudo systemctl enable ${dir}/Xorg.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# nvidia-xconfig: X configuration file generated by nvidia-xconfig | ||
# nvidia-xconfig: version 367.57 (buildmeister@swio-display-x64-rhel04-13) Mon Oct 3 21:42:19 PDT 2016 | ||
|
||
|
||
Section "ServerLayout" | ||
Identifier "Layout0" | ||
Screen 0 "Screen0" | ||
InputDevice "Keyboard0" "CoreKeyboard" | ||
InputDevice "Mouse0" "CorePointer" | ||
EndSection | ||
|
||
Section "Files" | ||
EndSection | ||
|
||
Section "InputDevice" | ||
|
||
# generated from default | ||
Identifier "Mouse0" | ||
Driver "mouse" | ||
Option "Protocol" "auto" | ||
Option "Device" "/dev/psaux" | ||
Option "Emulate3Buttons" "no" | ||
Option "ZAxisMapping" "4 5" | ||
EndSection | ||
|
||
Section "InputDevice" | ||
|
||
# generated from default | ||
Identifier "Keyboard0" | ||
Driver "kbd" | ||
EndSection | ||
|
||
Section "Monitor" | ||
Identifier "Monitor0" | ||
VendorName "Unknown" | ||
ModelName "Unknown" | ||
HorizSync 28.0 - 33.0 | ||
VertRefresh 43.0 - 72.0 | ||
Option "DPMS" | ||
EndSection | ||
|
||
Section "Device" | ||
Identifier "Device0" | ||
Driver "nvidia" | ||
VendorName "NVIDIA Corporation" | ||
BoardName "GRID K520" | ||
BusID "PCI:0:3:0" | ||
EndSection | ||
|
||
Section "Screen" | ||
Identifier "Screen0" | ||
Device "Device0" | ||
Monitor "Monitor0" | ||
DefaultDepth 24 | ||
Option "UseDisplayDevice" "None" | ||
SubSection "Display" | ||
Virtual 1280 1024 | ||
Depth 24 | ||
EndSubSection | ||
EndSection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build-docker-image.bash | ||
deploy-ec2.bash | ||
run-to-build.bash | ||
build-pc.bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM simulation-base:xenial | ||
|
||
# Starting point for cloudsim simulation projects | ||
# 1) inherits dependencies for building gazebo + ignition + sdformat | ||
# 2) provides a cloudsim-sim install in /opt/cloudsim-sim | ||
|
||
# Cloudsim-sim dependencies | ||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
redis-server \ | ||
nodejs \ | ||
nodejs-legacy \ | ||
npm \ | ||
&& apt-get clean | ||
|
||
# Install cloudsim-sim (default branch) | ||
RUN cd /opt \ | ||
&& hg clone https://bitbucket.org/osrf/cloudsim-sim \ | ||
&& cd /opt/cloudsim-sim \ | ||
&& npm install \ | ||
&& touch /opt/cloudsim-sim/server/keys.zip | ||
|
||
# Cloudsim-portal provides files in a directory called ~code | ||
# These must get mounted as /code in the container using a docker volume | ||
VOLUME ["/code"] | ||
|
||
# Install an entrypoint script which launches cloudsim-sim | ||
# Projects should set their start points with CMD | ||
COPY cloudsim-sim-entry.bash /cloudsim-sim-entry.bash | ||
ENTRYPOINT ["/cloudsim-sim-entry.bash"] | ||
CMD ["echo", "Someone forgot to set the CMD!"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
sudo docker build -t cloudsim-sim-base:xenial $DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# http://redsymbol.net/articles/bash-exit-traps/ | ||
function cleanup { | ||
# Stop cloudsim-sim | ||
sudo service redis-server stop | ||
cd /opt/cloudsim-sim | ||
sudo npm stop | ||
} | ||
trap cleanup EXIT | ||
|
||
# Start cloudsim-sim | ||
sudo service redis-server start | ||
cd /opt/cloudsim-sim | ||
cp /code/cloudsim-env.bash .env | ||
cp /code/cloudsim-options.json options.json | ||
npm start & | ||
|
||
# Do the CMD | ||
eval "$@" |
Oops, something went wrong.