Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker script #20

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions doc/setup.md
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just take out all instructions for running the old way to avoid confusion. It will help us avoid having to maintain 2 different ways to run things. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree. This docker can be used as a alternative or for someone interests to dive in. It would be better to separate it with the main thread.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,34 @@ chmod +x /workspace/src/panda_benchmark/scripts/move_to_position.py

```

### 3B. Seting Up Container with bash scripts
If you want to use bash script to set up your container, try the module [ros-docker-dev](../ros-docker-dev/README.md).
Features TLDR;
* Volumed
* User spoofing
* SSH forwarding
* Oh-my-zsh

Use the following command to build your image and container. If you want to build with no-cache or to rebuilt the image, please see [ros-docker-dev](../ros-docker-dev/README.md) for more details about this script and launching the containers.
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
```bash
cd ros-docker-dev
./enterpoint.sh
```

Now your container should be running and you should be in it's command line. Now setup the dependencies:
```bash
source /opt/ros/noetic/setup.zsh
cd src/relaxed_ik_ros1/relaxed_ik_core
cargo build

cd ~/workspace
catkin build
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
source devel/setup.zsh

chmod +x ~/workspace/src/panda_benchmark/scripts/
```

In this way, you should run `roslaunch panda_benchmark interface_b.launch` in [run_robot.md](../doc/run_robot.md) instead of `interface.launch`
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved

### 4. Set Up Franka Desktop
Before you can run anything with the FCI, make sure joints are unlocked and FCI Control is enabled in the Franka desktop (our Desktops is at [192.168.1.2](https://192.168.1.2/desk/)). Directions for doing that are [here](https://youtu.be/91wFDNHVXI4?si=4-ZArdrxOMAiCc5H&t=484). WARNING: we could not get Firefox to access the desk because of security reasons. However we could access through chrome once we clicked "Advanced" > "Proceed to 192.168.1.2 (unsafe)".
Expand Down
51 changes: 51 additions & 0 deletions ros-docker-dev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
devel/
logs/
build/
bin/
lib/
msg_gen/
srv_gen/
msg/*Action.msg
msg/*ActionFeedback.msg
msg/*ActionGoal.msg
msg/*ActionResult.msg
msg/*Feedback.msg
msg/*Goal.msg
msg/*Result.msg
msg/_*.py
build_isolated/
devel_isolated/

# Generated by dynamic reconfigure
*.cfgc
/cfg/cpp/
/cfg/*.py

# Ignore generated docs
*.dox
*.wikidoc

# eclipse stuff
.project
.cproject

# qcreator stuff
CMakeLists.txt.user

srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user

/planning/cfg
/planning/docs
/planning/src

*~

# Emacs
.#*

# Catkin custom files
CATKIN_IGNORE
65 changes: 65 additions & 0 deletions ros-docker-dev/README.md
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Editable ROS Docker Development

You could also check the latest [github repo README.md](https://github.com/AlfredMoore/ros-docker-dev/blob/volumed/README.md)

## Prerequisites
You should firstly install [Docker Engine](https://docs.docker.com/engine/install/ubuntu/) on your Ubuntu. Then [manage docker as a non-root user](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user), to enable `docker` instead of `sudo docker`.

* NOTE: Do not install Docker Desktop. It is different from the Docker Engine and not so friendly to docker development.

## Panda Noetic
### Build with cache
To Create an Image, Run the Container or Open another section in Container, please `cd ros-docker-dev` to enter the dir then run the scripts.
```bash
./enterpoint.sh
```

### Rebuild or Build with no cache
If you want to rebuild the image with changed dockerfile or to build with no-cache for the latest dependencies, you could build with no cache by running the following scirpts. In this way, you could rebuild the image from scratch but spend much longer time.
```bash
export NOCACHE=true
./enterpoint.sh
```

If you want to use cache again in the same terminal section, remember to reset the variable `NOCACHE` by using
```bash
unset NOCACHE
```

## Features:
* Volumed: Container volumed the parent folder(../ros-docker-dev) as the workspace in container. If you don't need it, please comment in the [enterpoint.sh](./enterpoint.sh)
```bash
--volume="$(dirname ${ENTERPOINT_DIR}):${WORKSPACE_PATH}" # Volume the parent of this docker repo to workspace
```
* User spoofing: Container has the same username and password as the host.
* SSH forwarding: Container fetches the same ssh agent as the host (if you have set the ssh-agent in host). No need to add any additional SSH key pair. In the container you could directly use `git` via SSH.

## Notes:
* Oh-my-zsh: Container has an configured oh-my-zsh. It is editable in the [configs/oh-my-zsh.zshrc](./configs/oh-my-zsh.zshrc).
* Editable and Readable: [Dockerfile](./panda-noetic.Dockerfile), [Building Config](./panda-bake.hcl) and [Running Config](./enterpoint.sh). You can also build from the [raw dockerfile](./raw.Dockerfile).

## Contribution
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
### [NIST_Benchmark](https://github.com/Wisc-HCI/NIST_Benchmark)
:warning: **Note: In the container, you will use zsh intead of bash. `zsh` is pretty and more powerful with oh-my-zsh theme and auto-completion. But remember to `source /devel/setup.zsh` instead of `source /devel/setup.bash`**

* Some computers support directly `sudo apt install libfranka`, but some do not. So comment `RUN apt-get ...` in [panda-noetic.Dockerfile](./panda-noetic.Dockerfile) if it does not work, and you should build from source following [this](https://frankaemika.github.io/docs/installation_linux.html#building-from-source).
```Dockerfile
# Install libfranka and franka-ros
USER root
## comment the following lines if does work
RUN apt-get update && apt-get install --yes \
ros-noetic-libfranka ros-noetic-franka-ros
```
* Change your docker image name and container name in [env.sh](./env.sh)
```bash
# Image Tag and Container Name
export IMAGE_TAG="WiscHCI/panda-ros:${GIT_LABEL}"
export CONTAINER_NAME="ros-panda-noetic"
```

## e.g.
![example](./example.jpg)


## TODO ~~(TBD: lazy man)~~
Update to docker compose run and build (docker compose documents are unclear).
124 changes: 124 additions & 0 deletions ros-docker-dev/configs/oh-my-zsh.zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH

# Path to your Oh My Zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time Oh My Zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="agnoster"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git docker docker-compose)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='nvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch $(uname -m)"

# Set personal aliases, overriding those provided by Oh My Zsh libs,
# plugins, and themes. Aliases can be placed here, though Oh My Zsh
# users are encouraged to define aliases within a top-level file in
# the $ZSH_CUSTOM folder, with .zsh extension. Examples:
# - $ZSH_CUSTOM/aliases.zsh
# - $ZSH_CUSTOM/macos.zsh
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# Whether inside the container
if [ ! -f /.dockerenv ]; then
echo -e "\n\e[33mNOTE:\e[0m Not RUNING inside a container"
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
# echo "Add your scripts here..."

else
echo -e "\n\e[33mNOTE:\e[0m RUNNING inside a container"
echo -e "\nTesting \e[33mSSH\e[0m forwarding" && ssh -T [email protected]
echo -e "\nWORKSPACE \e[92m${WORKSPACE_PATH}\e[0m branch: \e[92m$(git -C ${WORKSPACE_PATH} branch --show-current )\e[0m commit: \e[92m$(git -C ${WORKSPACE_PATH} rev-parse --short HEAD)\e[0m"
# ROS version detection
if [ -d "/opt/ros/noetic" ]; then
echo -e "\nSource \e[92mROS Noetic\e[0m configuration" && source /opt/ros/noetic/setup.zsh
elif [ -d "/opt/ros/humble" ]; then
echo -e "\nSource \e[92mROS Humble\e[0m configuration" && source /opt/ros/humble/setup.zsh
else
echo -e "\n\e[33mNeither ROS Noetic Nor Humble detected\e[0m"
fi
fi

90 changes: 90 additions & 0 deletions ros-docker-dev/enterpoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /usr/bin/env bash

set -o errexit
set -o nounset

source ./env.sh

# build image if not
if ! docker inspect "${IMAGE_TAG}" --type=image &> /dev/null; then
echo -e "\e[33mIMAGE ${IMAGE_TAG} not existing, start building IMAGE ${IMAGE_TAG}...\e[0m"
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
docker buildx bake -f panda-bake.hcl
echo -e "\e[33mImage Built Sucessfully\e[0m"
else
echo -e "\e[33mIMAGE ${IMAGE_TAG} already existing...\e[0m"
fi

# GUI applications
xhost +local:docker > /dev/null

# Arguments to run container
args=(
--rm # autoremove the container
--name "${CONTAINER_NAME}"

# Interactivity
--interactive
--tty

# host network
--network=host

# hostname and localhost
--hostname="${CONTAINER_NAME}"
--add-host="${CONTAINER_NAME}":"127.0.0.1" # Add localhost address manually

# GUI applications
--ipc=host
--volume="/tmp/.X11-unix:/tmp/.X11-unix:ro"
--volume="/dev/dri:/dev/dri:ro"

# User spoofing
--group-add="sudo"
--user="${USER_ID}:${GROUP_ID}" # Align with Dockerfile
--volume="/etc/group:/etc/group:ro"
--volume="/etc/passwd:/etc/passwd:ro"
--volume="/etc/shadow:/etc/shadow:ro"
## SSH forwarding based on user spoofing, test ssh with
## ssh -T [email protected]
--volume="$(dirname ${SSH_AUTH_SOCK}):$(dirname ${SSH_AUTH_SOCK}):ro"
--env "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}"
--volume="$HOME/.gitconfig:/home/${USERNAME}/.gitconfig:ro"

# PID exposure

# Realtime Kernel, if you are in RTkernel, uncomment the followings
AlfredMoore marked this conversation as resolved.
Show resolved Hide resolved
--privileged
--cap-add=SYS_NICE

# Workspace
--volume="$(dirname ${ENTERPOINT_DIR}):${WORKSPACE_PATH}" # Volume the parent of this docker repo to workspace
--workdir "${WORKSPACE_PATH}" # cd the volumed workspace
--env "WORKSPACE_PATH=${WORKSPACE_PATH}"

# start image
"${IMAGE_TAG}"
"/usr/bin/zsh"
)

# Create container if not
if [ -z "$(docker ps -a -q -f name=${CONTAINER_NAME})" ]; then
echo -e "\e[32mCONTAINER ${CONTAINER_NAME} not existing. Create and run the container\e[0m"
docker run "${args[@]}"
else
# Start the stopped container
if [ -z "$(docker ps -q -f name=${CONTAINER_NAME})" ]; then
echo -e "\e[32mCONTAINER ${CONTAINER_NAME} existing but stopped. Start and run the container\e[0m"
docker start ${CONTAINER_NAME}
docker exec --interactive --tty \
--user="${USER_ID}:${GROUP_ID}" \
--workdir "/home/${USERNAME}/" \
"${CONTAINER_NAME}" "${SHELL}"
# Enter to a runnning container
else
echo -e "\e[32mCONTAINER ${CONTAINER_NAME} existing and running. Enter the container with a new section\e[0m"
docker exec --interactive --tty \
--user="${USER_ID}:${GROUP_ID}" \
--workdir "/home/${USERNAME}/" \
"${CONTAINER_NAME}" "${SHELL}"
fi
fi
25 changes: 25 additions & 0 deletions ros-docker-dev/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env bash

# Create a label from git branch or commit hash of the parent directory or latest
GIT_LABEL="$(git -C .. branch --show-current | tr / -)"
if [[ -z "$GIT_LABEL" ]]; then
GIT_LABEL="$(git -C .. rev-parse --short HEAD)"
if [[ -z "$GIT_LABEL" ]]; then
GIT_LABEL="latest"
fi
fi

# Image Tag and Container Name
export IMAGE_TAG="WiscHCI/panda-ros:${GIT_LABEL}"
export CONTAINER_NAME="ros-panda-noetic"

# User configs
export USERNAME=$(whoami)
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
# export DISPLAY=${DISPLAY}

# Volume Settings
ENTERPOINT_DIR="$(dirname $(realpath "$0"))" # Get enterpoints's absolute directory path
export HOME_PATH="/home/${USERNAME}"
export WORKSPACE_PATH="${HOME_PATH}/workspace"
Binary file added ros-docker-dev/example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading