diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 22ea3da..9dab235 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,17 +1,49 @@ -name: docker image build +name: Build and Push Docker Image to GHCR on: push: - branches: [ "**" ] - + branches: + - main # 你可以根据需要更改为你的主分支 + - master + tags: + - '*' + pull_request: + branches: + - main # 你可以根据需要更改为你的主分支x + - master +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: - build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index faed60d..83cf9ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ # Use the official ROS image as the base image -FROM ros:humble-ros-core-jammy +# FROM ros:humble-ros-core-jammy -# Set shell for running commands +FROM ros:noetic-ros-core-focal + +# Set shell for running commandsx SHELL ["/bin/bash", "-c"] # install bootstrap tools @@ -27,8 +29,9 @@ RUN colcon mixin add default \ colcon metadata update RUN apt-get update && apt-get install -y --no-install-recommends \ - ros-humble-desktop=0.10.0-1* \ + ros-noetic-desktop\ && rm -rf /var/lib/apt/lists/* +ENTRYPOINT ["/ros_entrypoint.sh"] # Set the entrypoint to source ROS setup.bash and run a bash shell -CMD ["/bin/bash"] +CMD ["roscore"] diff --git a/README.md b/README.md index 0fd93de..a17da15 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,53 @@ nvidia-docker2 jazz. You can use rocker. You can also use Intel Integrated Graph This is under active development, so please feel free to contribute to the project. If you have any questions, please open an issue on the GitHub repo. Thanks! + + + + +首先,需要加载您的Zsh配置文件。 +将以下内容添加到zshrc的尾部 +``` +ros_dev() { + # Check if the correct number of arguments were provided + if (( $# % 2 != 0 )); then + echo "Usage: ros_dev [ ...]" + return 1 + fi + + while (( $# >= 2 )); do + # Set environment variables + ROS_DEV_CONTAINER_NAME=$1 + ROS_PROJECT_PATH=$2 + shift 2 + + # Run docker-compose from the correct directory + cd "$SCRIPT_DIR" && docker-compose up -d + done +} +``` +然后加载配置文件 +```sh +source ~/.zshrc +``` + +接下来,运行ROS2 Docker开发环境。 + + +``` +# ros_dev <容器名> <代码目录> +export ROS_DEV_CONTAINER_NAME=ros +export ROS_PROJECT_PATH=$(pwd) +ros_dev ros $(pwd) +``` + +进入容器,加载ROS入口点脚本,运行RViz2可视化工具 + +``` +docker exec -it ros bash +source ros_entrypoint.sh rviz +``` + +最后打开本地浏览器查看 + +http://localhost:8080/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 56ff9db..77e03cc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ version: '3.8' services: ros_dev_env: container_name: ${ROS_DEV_CONTAINER_NAME} - image: ${ROS_DEV_CONTAINER_NAME} ## For now, the names are the same. Can change if ever a need arises. + image: ghcr.io/imdingtalk/ros2-docker-dev:ros-noetic build: ./ volumes: - ${ROS_PROJECT_PATH}:/ros2_ws/src/ diff --git a/setup.sh b/setup.sh index 929d09f..7c979c1 100644 --- a/setup.sh +++ b/setup.sh @@ -22,7 +22,7 @@ echo 'ros_dev() { shift 2 # Run docker-compose from the correct directory - cd "$SCRIPT_DIR" && docker-compose up -d --build + cd "$SCRIPT_DIR" && docker-compose up -d done } ' >> "$HOME/.bashrc"