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

Add bats #26

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "test/bats"]
path = test/bats
url = https://github.com/bats-core/bats-core.git
[submodule "test/test_helper/bats-support"]
path = test/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
1 change: 1 addition & 0 deletions test/bats
Submodule bats added at 172580
35 changes: 35 additions & 0 deletions test/test_container_docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Docker Container for testing

## container
The container should support forwarding of the x11-session. If this is not working please make sure docker is granted access to the x-server by running `./start.sh`. Otherwise open an issue on github.
The container itself should clone your `user` inside the docker container. The _ros_team_workspace_ folder is then shared with the docker container and mounted under _~/workspace/ros_team_workspace/_ inside the container.

## Usage of the docker container
Short:
1. Install docker
2. run `./build.sh`
3. run `./create.sh`
4. You can then connect either as root or user by opening a new terminal and run `:/connect_<user|root>.sh`.
5. If you want to exit simply type `exit` in the console inside the container.
6. If you stop the container with `./stop.sh` or by exiting all instance restart with `./start.sh`.

### Install docker.
This step depends on the operatingsystem you are using. For instructions have a look [here](https://docs.docker.com/) on the official docs site or google it.
* [Windows](https://docs.docker.com/desktop/windows/install/)
* [Mac](https://docs.docker.com/desktop/mac/install/)
* Linux
- have to look it up. However make sure your user is in the docker group. Check with: `groups`.
To add your user to the docker group run: `sudo usermod -aG docker <username>`.



## some useful docker commands
For complete list of commands have a look at [official docker cli reference](https://docs.docker.com/engine/reference/commandline/cli/).

+ `docker container <command>`
+ `ls` lists all current active containers
+ `ls -a` lists all containers
+ `rm <container>` removes container
+ `docker image <command>`
+ `ls` lists all images
+ `rm <image>` removes image
9 changes: 9 additions & 0 deletions test/test_container_docker/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TODO
* Automatically add hostname of dockercontainer to /etc/hosts otherwise annoying `sudo: unable to resolve host <hostname>: Name or service not known`
127.0.0.1 <hostname>


## Currently **not** working properly
* [] Auto completion of commands in shell
- [] ros2 commands auto completion

58 changes: 58 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
FROM ubuntu:20.04

#Arguments maybe add defaults?
ARG user
ARG uid
ARG gid
ARG home

# make bash default
SHELL ["/bin/bash", "-c"]

# install locales
RUN apt-get update -y && apt-get install -y locales

# Configure user env
ENV TZ=Europe/Berlin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Set the locale to include UTF-8. UTF-8 compatible locales are needed for install
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Make sure UTF-8 is supported
RUN locale

# Install basic utilities
RUN apt-get -y update && apt-get -y install git nano sudo tmux tree vim

# install ROS2:foxy dependencies
RUN apt-get install -y curl gnupg2 lsb-release
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

# install ROS2:foxy and things needed for ros development, DEBIAN_FRONTEND is needed to ignore interactive keyboard layout setting while install
RUN apt-get update -y && DEBIAN_FRONTEND=noniteractive apt-get install -y ros-foxy-desktop pip python3-colcon-common-extensions
RUN pip install -U rosdep && \
rosdep init

# clone user into docker image, add to sudo users needed for xsharing
# the passwd delet is needed to update /etc/shadow otherwise user cannot use sudo
RUN mkdir -p ${home} && \
echo "${user}:x:${uid}:${gid}:${user},,,:${home}:/bin/bash" >> /etc/passwd && \
echo "${user}:x:${uid}:" >> /etc/group && \
echo "${user} ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/${user}" && \
chmod 0440 "/etc/sudoers.d/${user}" && \
usermod -aG sudo ${user} && \
passwd -d ${user} && \
chown ${uid}:${gid} -R ${home}

# setup environment of ros for usage
COPY bashrc ${home}/.bashrc
RUN echo "source /opt/ros/foxy/setup.bash" >> ${home}/.bashrc

#switch to user
USER ${user}
6 changes: 6 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Docker Container ubuntu_20_04_ros2_foxy

Ubuntu 20.04 with ROS 2 [Foxy Fitzroy (codename ‘foxy’)](https://docs.ros.org/en/foxy/index.html) installed with x11 forwading.

## How to use
Have a look at README.md in `ros_team_workspace/test/test_container_docker` for a detailed description on how to use.
3 changes: 3 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TODO

## Currently **not** working properly
103 changes: 103 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
7 changes: 7 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
docker build \
--build-arg user=$USER \
--build-arg uid=$UID \
--build-arg gid=$GROUPS \
--build-arg home=$HOME \
-t ubuntu_20_04_ros2_foxy .
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
docker exec -u root -it ubuntu_20_04_ros2_foxy-instance /bin/bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
docker exec -u $USER -it ubuntu_20_04_ros2_foxy-instance /bin/bash
4 changes: 4 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
xhost +local:docker
docker run --net=host -h ubuntu_20_04_ros2_foxy-docker -e DISPLAY --tmpfs /tmp -v /tmp/.X11-unix/:/tmp/.X11-unix:rw -v $PWD/../../../../ros_team_workspace/:$HOME/workspace/ros_team_workspace:rw --name ubuntu_20_04_ros2_foxy-instance -it ubuntu_20_04_ros2_foxy /bin/bash

3 changes: 3 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
xhost +local:docker
docker start ubuntu_20_04_ros2_foxy-instance
3 changes: 3 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_foxy/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
xhost -local:docker
docker stop ubuntu_20_04_ros2_foxy-instance
57 changes: 57 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_multi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM ubuntu:20.04

#Arguments maybe add defaults?
ARG user
ARG uid
ARG gid
ARG home

# make bash default
SHELL ["/bin/bash", "-c"]

# install locales
RUN apt-get update -y && apt-get install -y locales

# Configure user env
ENV TZ=Europe/Berlin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Set the locale to include UTF-8. UTF-8 compatible locales are needed for install
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Make sure UTF-8 is supported
RUN locale

# Install basic utilities
RUN apt-get -y update && apt-get -y install git nano sudo tmux tree vim

# install ROS2:foxy dependencies
RUN apt-get install -y curl gnupg gnupg2 lsb-release software-properties-common && apt-add-repository universe
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

# install ROS2:foxy and things needed for ros development, DEBIAN_FRONTEND is needed to ignore interactive keyboard layout setting while install
RUN apt-get update -y && DEBIAN_FRONTEND=noniteractive apt-get install -y ros-foxy-desktop ros-galactic-desktop ros-rolling-desktop pip python3-colcon-common-extensions
RUN pip install -U rosdep && \
rosdep init

# clone user into docker image, add to sudo users needed for xsharing
# the passwd delet is needed to update /etc/shadow otherwise user cannot use sudo
RUN mkdir -p ${home} && \
echo "${user}:x:${uid}:${gid}:${user},,,:${home}:/bin/bash" >> /etc/passwd && \
echo "${user}:x:${uid}:" >> /etc/group && \
echo "${user} ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/${user}" && \
chmod 0440 "/etc/sudoers.d/${user}" && \
usermod -aG sudo ${user} && \
passwd -d ${user} && \
chown ${uid}:${gid} -R ${home}

# setup environment of ros for usage
COPY bashrc ${home}/.bashrc

#switch to user
USER ${user}
10 changes: 10 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_multi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Docker Container ubuntu_20_04_ros2_multi

Ubuntu 20.04 with ROS 2 and
* [Foxy Fitzroy (codename ‘foxy’)](https://docs.ros.org/en/foxy/index.html)
* [Galactic Geochelone (codename ‘galactic’)](https://docs.ros.org/en/galactic/index.html)
* [Rolling Ridley (codename ‘rolling’)](https://docs.ros.org/en/rolling/index.html)
installed with x11 forwading.

## How to use
Have a look at README.md in `ros_team_workspace/test/test_container_docker` for a detailed description on how to use.
4 changes: 4 additions & 0 deletions test/test_container_docker/ubuntu_20_04_ros2_multi/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO

## Currently **not** working properly

Loading