-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dockerfileを追加。Dockerイメージを作成するGitHub workflowを追加。 (#32)
* Dockerfile追加 * Add worflow file * 動作確認のためworkflowの設定変更 * workflowを修正 * gazeboが動作するように予めモデルをダウンロードする * typo修正 * README更新 * イメージの動作確認ができたので、workflowからPRトリガーを取り除く * Update .github/workflows/build_docker_image.yml Co-authored-by: Daisuke Sato <tiryoh@gmail.com> * Update .github/workflows/build_docker_image.yml Co-authored-by: Daisuke Sato <tiryoh@gmail.com> * rockerの実行コマンドを修正。USB通信ポート設定の案内を追加 Co-authored-by: Daisuke Sato <tiryoh@gmail.com>
- Loading branch information
Showing
6 changed files
with
180 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Dockerを使用する | ||
|
||
## Dockerイメージを使用する | ||
|
||
https://github.com/rt-net/crane_plus/pkgs/container/crane_plus | ||
にDockerイメージ`ghcr.io/rt-net/crane_plus:$ROS_DISTRO` | ||
をアップロードしています。 | ||
tagにはROSのディストリビューションを指定してください。 | ||
|
||
foxyディストリビューションのイメージをダウンロードする場合は次のコマンドを実行します。 | ||
|
||
```sh | ||
$ docker pull ghcr.io/rt-net/crane_plus:foxy | ||
``` | ||
|
||
### ノードの起動 | ||
|
||
GUIアプリケーションを起動するため | ||
[osrf/rocker](https://github.com/osrf/rocker) | ||
を使用します | ||
|
||
rockerのオプションには、 | ||
ホストのネットワーク環境を使用するための`--net=host`と | ||
[ネットワーク使用時のエラー](https://github.com/osrf/rocker/issues/13) | ||
を回避するための`--privileged`を与えます | ||
|
||
またCRANE+V2実機を動かす場合は、[crane_plus_control/README.md](../crane_plus_control/README.md) | ||
を参考に、USB通信ポートのアクセス権限を変更してください。 | ||
|
||
```sh | ||
# rockerのインストール | ||
$ sudo apt install python3-rocker | ||
|
||
$ rocker --x11 --net=host --privileged \ | ||
-- ghcr.io/rt-net/crane_plus:$ROS_DISTRO \ | ||
ros2 launch crane_plus_examples demo.launch.py | ||
``` | ||
|
||
### パッケージの再ビルド | ||
|
||
ホストに作成したワークスペースをDockerコンテナにマウントすることで、 | ||
ホスト環境でのファイル編集内容をコンテナ内に反映できます | ||
|
||
```sh | ||
# ワークスペース作成 | ||
$ mkdir -p ~/crane_ws/src | ||
# パッケージをクローン | ||
$ git clone https://github.com/rt-net/crane_plus.git ~/crane_ws/src/crane_plus | ||
|
||
# パッケージをビルド | ||
$ rocker --x11 --net=host --privileged \ | ||
--volume ~/crane_ws:/root/overlay_ws \ | ||
-- ghcr.io/rt-net/crane_plus:$ROS_DISTRO \ | ||
colcon build --symlink-install | ||
|
||
# ノードを起動 | ||
$ rocker --x11 --net=host --privileged \ | ||
--volume ~/crane_ws:/root/overlay_ws \ | ||
-- ghcr.io/rt-net/crane_plus:$ROS_DISTRO \ | ||
ros2 launch crane_plus_examples demo.launch.py | ||
``` | ||
|
||
## Dockerイメージをビルドする | ||
|
||
`./build_source.sh $ROS_DISTRO`を実行してイメージを作成します。 | ||
|
||
```sh | ||
# foxyディストリビューションのイメージを作成する | ||
$ cd crane_plus/.docker | ||
$ ./build_source.sh foxy | ||
... | ||
Successfully tagged crane_plus:foxy | ||
``` |
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,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "Please set ROS_DISTRO to the argument." | ||
echo "e.g. ./build_source.sh foxy" | ||
fi | ||
ROS_DISTRO=$1 | ||
|
||
DOCKER_OPTION="" | ||
if [ $# -ge 2 ]; then | ||
DOCKER_OPTION=$2 | ||
fi | ||
|
||
COLCON_OPTION="" | ||
if [ $# -ge 3 ]; then | ||
COLCON_OPTION=$3 | ||
fi | ||
|
||
# Move to the package route directory | ||
cd $(dirname $0)/../ | ||
docker build $DOCKER_OPTION -t crane_plus:$ROS_DISTRO -f .docker/source/Dockerfile . \ | ||
--build-arg ROS_DISTRO=$ROS_DISTRO \ | ||
--build-arg COLCON_OPTION=$COLCON_OPTION |
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,36 @@ | ||
ARG ROS_DISTRO="foxy" | ||
FROM osrf/ros:${ROS_DISTRO}-desktop | ||
ENV OVERLAY_WS /root/overlay_ws | ||
WORKDIR $OVERLAY_WS/src | ||
|
||
# Copy source files | ||
COPY . crane_plus | ||
|
||
# Install depnedencies | ||
RUN apt-get update && rosdep update && \ | ||
rosdep install -iy --from-paths . && \ | ||
rm -rf /var/lib/apt/lists/ | ||
|
||
# Build packages | ||
ARG COLCON_OPTION="" | ||
RUN cd $OVERLAY_WS && \ | ||
. /opt/ros/${ROS_DISTRO}/setup.sh && \ | ||
colcon build --symlink-install $COLCON_OPTION | ||
|
||
# Download gazebo models by sparse checkout | ||
RUN mkdir -p /root/.gazebo/models && \ | ||
cd /root/.gazebo/models && \ | ||
git init . && \ | ||
git config core.sparsecheckout true && \ | ||
echo "ground_plane" >> .git/info/sparse-checkout && \ | ||
echo "sun" >> .git/info/sparse-checkout && \ | ||
echo "table" >> .git/info/sparse-checkout && \ | ||
git remote add origin https://github.com/osrf/gazebo_models && \ | ||
git pull origin master && \ | ||
rm -rf .git | ||
|
||
# Edit entrypoint to source overlay setup file | ||
WORKDIR $OVERLAY_WS | ||
RUN sed --in-place --expression \ | ||
'$i if [ -e $OVERLAY_WS/install/setup.bash ]; then\n\tsource "$OVERLAY_WS/install/setup.bash" \nfi' \ | ||
/ros_entrypoint.sh |
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 @@ | ||
.docker | ||
.github | ||
.git | ||
*.md |
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,37 @@ | ||
name: Create and publish a Docker image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
env: | ||
ROS_DISTRO: foxy | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
file: .docker/source/Dockerfile | ||
build-args: ROS_DISTRO=${{ env.ROS_DISTRO }} | ||
push: true | ||
tags: ${{ env.REGISTRY }}/${{ github.repository }}:${{ env.ROS_DISTRO }} |
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