-
Notifications
You must be signed in to change notification settings - Fork 0
Dockerize repo #29
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
Open
MadsJJ
wants to merge
11
commits into
main
Choose a base branch
from
feat/docker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dockerize repo #29
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0050f29
create Dockerfile, and build and run script. Add install, build and l…
MadsJJ c477d59
add devcontainer file
MadsJJ f793a52
remove annoying pylint
MadsJJ 2e34410
add dockerignore
MadsJJ 4af58ba
improve python dependency caching in dockerfile
MadsJJ a5e218d
forgotten in previous commit
MadsJJ 83e4951
move bashrc sourcing to a script (wont need to rebuild image to modif…
MadsJJ 474992e
add: todo tree extension in devcontainer
MadsJJ a8eef5d
fix: update devcontainer terminal profile setting and clean up runArgs
MadsJJ 66f63a3
fix: copilot pr comment
MadsJJ e79a74a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| { | ||
| "name": "vortex-image-segmentation-devcontainer", | ||
| "image": "vortex-image-segmentation:latest", | ||
| "customizations": { | ||
| "vscode": { | ||
| "settings": { | ||
| "terminal.integrated.defaultProfile.linux": "bash" | ||
| }, | ||
| "extensions": [ | ||
| "ms-azuretools.vscode-docker", | ||
| "ms-vscode.cpptools", | ||
| "ranch-hand-robotics.rde-pack", | ||
| "ms-python.vscode-pylance", | ||
| "twxs.cmake", | ||
| "ms-vsliveshare.vsliveshare", | ||
| "eamodio.gitlens", | ||
| "njpwerner.autodocstring", | ||
| "cschlosser.doxdocgen", | ||
| "xaver.clang-format", | ||
| "visualstudioexptteam.vscodeintellicode", | ||
| "ms-vscode-remote.remote-ssh", | ||
| "gxl.git-graph-3", | ||
| "ms-vscode-remote.remote-containers", | ||
| "gruntfuggly.todo-tree" | ||
| ] | ||
| } | ||
| }, | ||
| "remoteUser": "devuser", | ||
| "workspaceFolder": "/ros2_ws", | ||
| "workspaceMount": "source=${localWorkspaceFolder},target=/ros2_ws,type=bind,consistency=cached", | ||
| "runArgs": [ | ||
| "--privileged", | ||
| "--network=host", | ||
| "--ipc=host" | ||
| ] | ||
| } |
This file contains hidden or 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,30 @@ | ||
| # Ignore build artifacts and large/runtime folders | ||
| build/ | ||
| install/ | ||
| log/ | ||
| *.log | ||
|
|
||
| # Docker and local config | ||
| docker/ | ||
| .dockerignore | ||
|
|
||
| # VCS | ||
| .git | ||
| .gitignore | ||
|
|
||
| # VS Code | ||
| .vscode/ | ||
|
|
||
| # Python | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| venv/ | ||
| .env | ||
|
|
||
| # Misc | ||
| *.swp | ||
| *.swo | ||
| node_modules/ | ||
| bags/ |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -163,5 +163,10 @@ runs/ | |
| *.pt | ||
| *jpg | ||
|
|
||
| # ROS 2 build artifacts | ||
| install/ | ||
| build/ | ||
| log/ | ||
|
|
||
| # data | ||
| data/ | ||
This file contains hidden or 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,75 @@ | ||
| # ---------------------------------------------------------------------------- | ||
| # Base Image | ||
| # ---------------------------------------------------------------------------- | ||
| ARG BASE_IMAGE=ros:humble | ||
| FROM ${BASE_IMAGE} | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # Setup Arguments & Environment | ||
| # ---------------------------------------------------------------------------- | ||
| USER root | ||
| SHELL ["/bin/bash", "-c"] | ||
| ARG DEBIAN_FRONTEND=noninteractive | ||
| ARG ROS_DISTRO=humble | ||
|
|
||
| # Define User Args | ||
| ARG USER_ID=1000 | ||
| ARG GROUP_ID=1000 | ||
| ARG USERNAME=devuser | ||
|
|
||
| ENV WORKSPACE=/ros2_ws | ||
| WORKDIR ${WORKSPACE} | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # Create non-root user | ||
| # ---------------------------------------------------------------------------- | ||
| RUN groupadd --gid ${GROUP_ID} ${USERNAME} || true && \ | ||
| useradd --uid ${USER_ID} --gid ${GROUP_ID} -m -s /bin/bash ${USERNAME} || true && \ | ||
| apt-get update && apt-get install -y sudo && \ | ||
| echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \ | ||
| apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # Install System Dependencies | ||
| # ---------------------------------------------------------------------------- | ||
| RUN apt-get update && apt-get install -y \ | ||
| git \ | ||
| python3-vcstool \ | ||
| python3-pip \ | ||
| ros-${ROS_DISTRO}-cv-bridge \ | ||
| ros-${ROS_DISTRO}-vision-msgs \ | ||
| ros-${ROS_DISTRO}-pcl-conversions \ | ||
| libopencv-dev \ | ||
| libpcl-dev \ | ||
| python3-colcon-common-extensions \ | ||
| && apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN pip3 install cython | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # Copy & Install Requirements | ||
| # ---------------------------------------------------------------------------- | ||
| COPY requirements.txt ${WORKSPACE}/requirements.txt | ||
| RUN pip3 install -r ${WORKSPACE}/requirements.txt | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # Copy Workspace Files | ||
| # ---------------------------------------------------------------------------- | ||
| COPY . ${WORKSPACE} | ||
| RUN chown -R ${USER_ID}:${GROUP_ID} ${WORKSPACE} | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # Install ROS dependencies | ||
| # ---------------------------------------------------------------------------- | ||
| RUN rosdep update && rosdep install --from-paths . --ignore-src -r -y | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # User Configuration | ||
| # ---------------------------------------------------------------------------- | ||
| RUN echo "if [ -f /ros2_ws/scripts/bashrc_extra.sh ]; then source /ros2_ws/scripts/bashrc_extra.sh; fi" >> /home/${USERNAME}/.bashrc | ||
|
|
||
| # Switch to the user | ||
| USER ${USERNAME} | ||
| WORKDIR /home/${USERNAME} | ||
|
|
||
| CMD ["bash"] | ||
This file contains hidden or 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,57 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Environment Variables | ||
| # ------------------------------------------------------------------------------ | ||
| IMAGE="vortex-image-segmentation:latest" # Docker image name/tag | ||
| BASE_IMAGE="ros:humble" # Base image for Docker builds | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Platform Detection | ||
| # ------------------------------------------------------------------------------ | ||
| ARCHITECTURE="$(uname -m)" | ||
| if [[ "$ARCHITECTURE" == "arm64" || "$ARCHITECTURE" == "aarch64" ]]; then | ||
| PLATFORM="linux/arm64" | ||
| elif [[ "$ARCHITECTURE" == "x86_64" ]]; then | ||
| PLATFORM="linux/amd64" | ||
| else | ||
| echo "Unsupported architecture: $ARCHITECTURE" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Locate Script and Workspace Root | ||
| # ------------------------------------------------------------------------------ | ||
| SCRIPT_DIR="$(dirname "$(realpath "$0")")" | ||
| WORKSPACE="$(realpath "$SCRIPT_DIR/..")" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Build Start Info | ||
| # ------------------------------------------------------------------------------ | ||
| echo "======================================================================" | ||
| echo " Building Docker Image" | ||
| echo " • PLATFORM: $PLATFORM" | ||
| echo " • BASE_IMAGE: $BASE_IMAGE" | ||
| echo " • IMAGE: $IMAGE" | ||
| echo " • BUILD CONTEXT: $WORKSPACE" | ||
| echo "======================================================================" | ||
| echo "" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Build Docker Image with Buildx | ||
| # ------------------------------------------------------------------------------ | ||
| docker buildx build \ | ||
| --platform "$PLATFORM" \ | ||
| --build-arg BASE_IMAGE="$BASE_IMAGE" \ | ||
| --build-arg USER_ID="$(id -u)" \ | ||
| --build-arg GROUP_ID="$(id -g)" \ | ||
| --tag "$IMAGE" \ | ||
| --file "$SCRIPT_DIR/Dockerfile" \ | ||
| --load \ | ||
| "$WORKSPACE" | ||
|
|
||
| echo "" | ||
| echo "======================================================================" | ||
| echo " Successfully built image '$IMAGE' for platform '$PLATFORM'" | ||
| echo "======================================================================" |
This file contains hidden or 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,32 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Image Configuration | ||
| # ------------------------------------------------------------------------------ | ||
| IMAGE="vortex-image-segmentation:latest" # Default Docker image name/tag | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Locate Script Directory and Workspace Root | ||
| # ------------------------------------------------------------------------------ | ||
| SCRIPT_DIR="$(dirname "$(realpath "$0")")" | ||
| WORKSPACE="$(realpath "$SCRIPT_DIR/..")" | ||
|
|
||
| echo "======================================================================" | ||
| echo " Running Container" | ||
| echo " • IMAGE: $IMAGE" | ||
| echo " • Volume mount: $WORKSPACE -> /ros2_ws" | ||
| echo "======================================================================" | ||
| echo "" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Run Docker Container | ||
| # ------------------------------------------------------------------------------ | ||
| docker run -it --rm \ | ||
| --privileged \ | ||
| --network host \ | ||
| --ipc=host \ | ||
| -v "$WORKSPACE":/ros2_ws \ | ||
| -w /ros2_ws \ | ||
| "$IMAGE" \ | ||
| /bin/bash |
This file contains hidden or 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,19 @@ | ||
| #!/bin/bash | ||
| # /ros2_ws/scripts/bashrc_extra.sh for ROS 2 container | ||
|
|
||
| # Print actions for clarity | ||
| if [ -f /opt/ros/humble/setup.bash ]; then | ||
| echo "[bashrc_extra] Sourcing ROS 2 underlay: /opt/ros/humble/setup.bash" | ||
| source /opt/ros/humble/setup.bash | ||
| else | ||
| echo "[bashrc_extra] ROS 2 underlay not found: /opt/ros/humble/setup.bash" | ||
| fi | ||
|
|
||
| if [ -f /ros2_ws/install/setup.bash ]; then | ||
| echo "[bashrc_extra] Sourcing workspace overlay: /ros2_ws/install/setup.bash" | ||
| source /ros2_ws/install/setup.bash | ||
| else | ||
| echo "[bashrc_extra] Workspace overlay not found: /ros2_ws/install/setup.bash" | ||
| fi | ||
|
|
||
| # Add your custom shell commands, aliases, or environment variables below |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workspace is owned by root (COPY is executed as root user) but later switched to a non-root user. This will cause permission issues when the non-root user tries to write to the workspace. Consider changing ownership of the workspace after copying:
RUN chown -R ${USER_ID}:${GROUP_ID} ${WORKSPACE}