Skip to content

Commit b2a2143

Browse files
authored
Adding Dockerfile and entrypoint script and updating README to suppor… (#153)
* Adding Dockerfile and entrypoint script and updating README to support this sample app with Robomaker after recent changes * Update README.md
1 parent 7f847da commit b2a2143

File tree

3 files changed

+165
-15
lines changed

3 files changed

+165
-15
lines changed

Dockerfile

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# ======== ROS/Colcon Dockerfile ========
2+
# This sample Dockerfile will build a Docker image for AWS RoboMaker
3+
# in any ROS workspace where all of the dependencies are managed by rosdep.
4+
#
5+
# Adapt the file below to include your additional dependencies/configuration outside of rosdep.
6+
# =======================================
7+
8+
# ==== Arguments ====
9+
# Override the below arguments to match your application configuration.
10+
# ===================
11+
12+
# ROS Distribution (ex: melodic, foxy, etc.)
13+
ARG ROS_DISTRO=melodic
14+
# Application Name (ex: helloworld)
15+
ARG APP_NAME=robomaker_app
16+
# Path to workspace directory on the host (ex: ./robot_ws)
17+
ARG LOCAL_WS_DIR=workspace
18+
# User to create and use (default: robomaker)
19+
ARG USERNAME=robomaker
20+
# The gazebo version to use if applicable (ex: gazebo-9, gazebo-11)
21+
ARG GAZEBO_VERSION=gazebo-9
22+
# Where to store the built application in the runtime image.
23+
ARG IMAGE_WS_DIR=/home/$USERNAME/workspace
24+
25+
# ======== ROS Build Stages ========
26+
# ${ROS_DISTRO}-ros-base
27+
# -> ros-robomaker-base
28+
# -> ros-robomaker-application-base
29+
# -> ros-robomaker-build-stage
30+
# -> ros-robomaker-app-runtime-image
31+
# ==================================
32+
33+
# ==== ROS Base Image ============
34+
# If running in production, you may choose to build the ROS base image
35+
# from the source instruction-set to prevent impact from upstream changes.
36+
# ARG UBUNTU_DISTRO=focal
37+
# FROM public.ecr.aws/lts/ubuntu:${UBUNTU_DISTRO} as ros-base
38+
# Instruction for each ROS release maintained by OSRF can be found here: https://github.com/osrf/docker_images
39+
# ==================================
40+
41+
# ==== Build Stage with AWS RoboMaker Dependencies ====
42+
# This stage creates the robomaker user and installs dependencies required to run applications in RoboMaker.
43+
# ==================================
44+
45+
FROM public.ecr.aws/docker/library/ros:${ROS_DISTRO}-ros-base AS ros-robomaker-base
46+
ARG USERNAME
47+
ARG IMAGE_WS_DIR
48+
49+
RUN apt-get clean
50+
RUN apt-get update && apt-get install -y \
51+
lsb \
52+
unzip \
53+
wget \
54+
curl \
55+
xterm \
56+
python3-colcon-common-extensions \
57+
devilspie \
58+
xfce4-terminal
59+
60+
RUN groupadd $USERNAME && \
61+
useradd -ms /bin/bash -g $USERNAME $USERNAME && \
62+
sh -c 'echo "$USERNAME ALL=(root) NOPASSWD:ALL" >> /etc/sudoers'
63+
64+
USER $USERNAME
65+
WORKDIR /home/$USERNAME
66+
67+
RUN mkdir -p $IMAGE_WS_DIR
68+
69+
# ==== ROS Application Base ====
70+
# This section installs exec dependencies for your ROS application.
71+
# Note: Make sure you have defined 'exec' and 'build' dependencies correctly in your package.xml files.
72+
# ========================================
73+
FROM ros-robomaker-base as ros-robomaker-application-base
74+
ARG LOCAL_WS_DIR
75+
ARG IMAGE_WS_DIR
76+
ARG ROS_DISTRO
77+
ARG USERNAME
78+
79+
WORKDIR $IMAGE_WS_DIR
80+
COPY --chown=$USERNAME:$USERNAME $LOCAL_WS_DIR/src $IMAGE_WS_DIR/src
81+
82+
RUN sudo apt update && \
83+
rosdep update && \
84+
rosdep fix-permissions
85+
86+
# Note: This will install all dependencies.
87+
# You could further optimize this by only defining the exec dependencies.
88+
# Then, install the build dependencies in the build image.
89+
RUN rosdep install --from-paths src --ignore-src -r -y
90+
91+
# ==== ROS Workspace Build Stage ====
92+
# In this stage, we will install copy source files, install build dependencies and run a build.
93+
# ===================================
94+
FROM ros-robomaker-application-base AS ros-robomaker-build-stage
95+
LABEL build_step="${APP_NAME}Workspace_Build"
96+
ARG APP_NAME
97+
ARG LOCAL_WS_DIR
98+
ARG IMAGE_WS_DIR
99+
100+
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
101+
colcon build \
102+
--install-base $IMAGE_WS_DIR/$APP_NAME
103+
104+
# ==== ROS Robot Runtime Image ====
105+
# In the final stage, we will copy the staged install directory to the runtime image.
106+
# =================================
107+
FROM ros-robomaker-application-base AS ros-robomaker-app-runtime-image
108+
ARG APP_NAME
109+
ARG USERNAME
110+
ARG GAZEBO_VERSION
111+
112+
ENV USERNAME=$USERNAME
113+
ENV APP_NAME=$APP_NAME
114+
ENV GAZEBO_VERSION=$GAZEBO_VERSION
115+
116+
RUN rm -rf $IMAGE_WS_DIR/src
117+
118+
COPY --from=ros-robomaker-build-stage $IMAGE_WS_DIR/$APP_NAME $IMAGE_WS_DIR/$APP_NAME
119+
120+
# Add the application source file to the entrypoint.
121+
WORKDIR /
122+
COPY entrypoint.sh /entrypoint.sh
123+
RUN sudo chmod +x /entrypoint.sh && \
124+
sudo chown -R $USERNAME /entrypoint.sh && \
125+
sudo chown -R $USERNAME $IMAGE_WS_DIR/$APP_NAME
126+
127+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,46 @@ export WORLD_ID=<worldId>
9494

9595
## Using this sample with RoboMaker
9696

97-
You first need to install colcon-ros-bundle. Python 3.5 or above is required.
97+
You first need to install [Docker](https://docs.docker.com/get-docker/) and [VCS Import Tool](http://wiki.ros.org/vcstool) (if you use VCS Import Tool). Python 3.5 or above is required.
9898

9999
```bash
100-
pip3 install -U setuptools
101-
pip3 install colcon-ros-bundle
100+
pip3 install vcstool
102101
```
103102

104-
After colcon-ros-bundle is installed you need to build your robot or simulation, then you can bundle with:
103+
After Docker and VCS Import Tool is installed you need to build your robot or simulation docker images:
105104

106105
```bash
107-
# Bundling Robot Application
108-
cd robot_ws
109-
source install/local_setup.sh
110-
colcon bundle
106+
# Import dependencies defined in .rosinstall to each source directory using vcs import
107+
vcs import robot_ws < robot_ws/.rosinstall
108+
vcs import simulation_ws < simulation_ws/.rosinstall
109+
110+
# Building Robot Application Docker Image
111+
DOCKER_BUILDKIT=1 docker build . \
112+
--build-arg ROS_DISTRO=melodic \
113+
--build-arg LOCAL_WS_DIR=./robot_ws \
114+
--build-arg APP_NAME=helloworld-robot-app \
115+
-t robomaker-helloworld-robot-app
116+
117+
# Building Simulation Application Docker Image
118+
DOCKER_BUILDKIT=1 docker build . \
119+
--build-arg GAZEBO_VERSION=gazebo-9 \
120+
--build-arg ROS_DISTRO=melodic \
121+
--build-arg LOCAL_WS_DIR=./simulation_ws \
122+
--build-arg APP_NAME=helloworld-sim-app \
123+
-t robomaker-helloworld-sim-app
124+
```
111125

112-
# Bundling Simulation Application
113-
cd simulation_ws
114-
source install/local_setup.sh
115-
colcon bundle
126+
This produces the Docker Images `robomaker-helloworld-robot-app` and `robomaker-helloworld-sim-app` respectively which you can view by running:
127+
128+
```bash
129+
# Listing your Docker Images
130+
docker images
116131
```
117132

118-
This produces the artifacts `robot_ws/bundle/output.tar` and `simulation_ws/bundle/output.tar` respectively.
119-
You'll need to upload these to an s3 bucket, then you can use these files to
133+
You'll need to [upload these images to Amazon ECR](https://docs.aws.amazon.com/robomaker/latest/dg/development-publish-app-containers.html), then you can use these files to
120134
[create a robot application](https://docs.aws.amazon.com/robomaker/latest/dg/create-robot-application.html),
121135
[create a simulation application](https://docs.aws.amazon.com/robomaker/latest/dg/create-simulation-application.html),
122-
and [create a simulation job](https://docs.aws.amazon.com/robomaker/latest/dg/create-simulation-job.html) in RoboMaker.
136+
and [create a simulation job](https://docs.aws.amazon.com/robomaker/latest/dg/create-simulation-job.html) in RoboMaker. Visit the [preparing-ros-application-and-simulation-containers-for-aws-robomaker](https://aws.amazon.com/blogs/robotics/preparing-ros-application-and-simulation-containers-for-aws-robomaker/#:~:text=Bash-,Publish%20docker%20images%20to%20Amazon%20ECR,-Containers%20used%20by) blog post to find the steps to upload these docker images to Amazon ECR.
123137
124138
## ROS Nodes launched by this Sample
125139

entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -e
3+
source "/home/$USERNAME/workspace/$APP_NAME/setup.bash"
4+
if [[ -f "/usr/share/$GAZEBO_VERSION/setup.sh" ]]
5+
then
6+
source /usr/share/$GAZEBO_VERSION/setup.sh
7+
fi
8+
printenv
9+
exec "${@:1}"

0 commit comments

Comments
 (0)