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

build images online #7

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
48 changes: 40 additions & 8 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +23 to +24
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update checkout action to the latest version.

While using a specific version is good for stability, the current version (v2) of the actions/checkout action is outdated.

Update to the latest version to ensure you have the most recent features and bug fixes:

- uses: actions/checkout@v2
+ uses: actions/checkout@v3

This will resolve the warning from the static analysis tool and potentially provide performance improvements.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v3
🧰 Tools
🪛 actionlint

22-22: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


- 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 }}
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Use the official ROS image as the base image
FROM ros:humble-ros-core-jammy
# FROM ros:humble-ros-core-jammy

FROM ros:noetic-ros-core-focal

# Set shell for running commands
SHELL ["/bin/bash", "-c"]
Expand Down Expand Up @@ -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\
adeeb10abbas marked this conversation as resolved.
Show resolved Hide resolved
&& 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"]
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <container_name1> <project_path1> [<container_name2> <project_path2> ...]"
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/
adeeb10abbas marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Reinstate the --build flag in the docker-compose command

The removal of the --build flag from the docker-compose up command can lead to the use of outdated Docker images. Since both Dockerfile and docker-compose.yml are present in the repository, it's essential to ensure that any changes to the Docker configurations are reflected in the running containers.

Recommended Actions:

  1. Reinstate the --build flag to ensure that images are rebuilt with the latest changes:

    cd "$SCRIPT_DIR" && docker-compose up -d --build
  2. Alternatively, modify the ros_dev function to accept an optional rebuild parameter, allowing flexibility:

    ros_dev() {
      local rebuild=false
      if [[ "$1" == "--rebuild" ]]; then
        rebuild=true
        shift
      fi
      # ... (rest of the function)
      if $rebuild; then
        cd "$SCRIPT_DIR" && docker-compose up -d --build
      else
        cd "$SCRIPT_DIR" && docker-compose up -d
      fi
      # ...
    }

    This approach allows developers to choose when to rebuild images, balancing speed and consistency.

🔗 Analysis chain

Reconsider removing the --build flag from docker-compose command

The removal of the --build flag from the docker-compose up command has several implications:

  1. It will speed up the container startup process as images won't be rebuilt every time.
  2. However, it introduces a risk of running outdated environments if there have been changes to the Dockerfile or build context.
  3. This change may lead to inconsistencies between different developers' environments if they don't manually rebuild at the same time.

Consider the following options:

  1. Revert the change to keep the --build flag for consistency and to ensure up-to-date environments.
  2. Add a new parameter to the ros_dev function to optionally trigger a rebuild, e.g.:
    ros_dev() {
      local rebuild=false
      if [[ "$1" == "--rebuild" ]]; then
        rebuild=true
        shift
      fi
      # ... (rest of the function)
      if $rebuild; then
        cd "$SCRIPT_DIR" && docker-compose up -d --build
      else
        cd "$SCRIPT_DIR" && docker-compose up -d
      fi
      # ...
    }
  3. Add a comment in the function to remind users to manually rebuild when necessary:
    # Note: Images are not automatically rebuilt. Run 'docker-compose build' manually when needed.

To understand the impact of this change, let's check if there are any Dockerfiles or docker-compose.yml files in the repository:

This will help us understand the Docker setup and potential implications of not rebuilding images.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for Dockerfile and docker-compose.yml
echo "Searching for Dockerfile:"
fd Dockerfile
echo "Searching for docker-compose.yml:"
fd docker-compose.yml

Length of output: 207

done
}
' >> "$HOME/.bashrc"
Expand Down