Skip to content

Commit 6f50a77

Browse files
Merge pull request #34 from LCAS/copilot/fix-33
Fix Docker build failure: detectron2 editable install error due to missing torch
2 parents b930eed + da63f81 commit 6f50a77

9 files changed

Lines changed: 126 additions & 101 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# syntax = devthefuture/dockerfile-x
22

3-
ARG BASE_IMAGE=lcas.lincoln.ac.uk/lcas/ros:jammy-humble-cuda11.8-opengl
3+
ARG BASE_IMAGE=lcas.lincoln.ac.uk/lcas/ros-docker-images:jammy-cuda11.8-humble-2
44
############################################################################################################
5-
FROM ${BASE_IMAGE} as base
5+
FROM ${BASE_IMAGE} AS base
66

77
USER root
88

@@ -27,14 +27,14 @@ INCLUDE .devcontainer/docker_include/user_install.dockerfile
2727

2828
############################################################################################################
2929
# get the source tree and analyse it for its package.xml only
30-
FROM user_space as sourcefilter
30+
FROM user_space AS sourcefilter
3131
COPY . /tmp/src
3232
# remove everything that isn't package.xml
3333
RUN find /tmp/src -type f \! -name "package.xml" -print | xargs rm -rf
3434

3535
############################################################################################################
3636
# install all dependencies listed in the package.xml
37-
FROM user_space as depbuilder
37+
FROM user_space AS depbuilder
3838
# copy the reduced source tree (only package.xml) from previous stage
3939
COPY --from=sourcefilter /tmp/src /tmp/src
4040
RUN rosdep update && apt-get update
@@ -44,11 +44,44 @@ RUN cd /tmp/src && rosdep install --from-paths . --ignore-src -r -y && cd && rm
4444
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
4545

4646
############################################################################################################
47-
FROM depbuilder as final
47+
FROM depbuilder AS final
4848

4949
USER $USER
5050

5151
# include the file to configure the user's .bashrc
5252
INCLUDE .devcontainer/docker_include/bashrc_config.dockerfile
5353

5454
CMD ["/bin/bash"]
55+
56+
# Deploys the application to production environment after successful build and test stages
57+
# This stage handles the final deployment process including:
58+
# - Setting up production environment variables
59+
# - Deploying built artifacts to target infrastructure
60+
# - Performing post-deployment health checks
61+
# - Notifying relevant stakeholders of deployment status
62+
FROM depbuilder AS deployed
63+
64+
USER root
65+
66+
# Copy the entire source code to the workspace
67+
RUN mkdir -p ${COLCON_WS}/src
68+
COPY . ${COLCON_WS}/src/
69+
70+
# Change ownership of the workspace to the user
71+
RUN chown -R ${USER}:${USER} ${COLCON_WS}
72+
73+
USER $USER
74+
75+
# Build the workspace
76+
WORKDIR ${COLCON_WS}
77+
RUN bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash; \
78+
colcon build --merge-install --cmake-args -DCMAKE_BUILD_TYPE=Release"
79+
80+
# Source the workspace in the entrypoint
81+
RUN echo "source ${COLCON_WS}/install/setup.bash" >> ~/.bashrc
82+
83+
# Set the working directory
84+
WORKDIR ${COLCON_WS}
85+
86+
# Default command
87+
CMD ["/bin/bash"]

.devcontainer/cuda-opengl/devcontainer.json renamed to .devcontainer/devcontainer.json

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
{
66
// Define the container name for easy identification
7-
"name": "L-CAS Humble CUDA-OpenGL Devcontainer",
7+
"name": "L-CAS Humble CUDA-OpenGL Devcontainer for AOC Fruit Detector",
88

9-
// Specify the Docker Compose file(s) required to set up the dev container
10-
"dockerComposeFile": ["../docker-compose.yml"],
11-
"service": "fruit_detector", // Define the main service to use in the container
9+
// Use Dockerfile directly instead of docker-compose
10+
"build": {
11+
"dockerfile": "./Dockerfile",
12+
"context": "..",
13+
"target": "final"
14+
},
1215
"workspaceFolder": "/home/ros/fruit_detector_ws/", // Path to the workspace within the container
16+
"workspaceMount": "source=${localWorkspaceFolder},target=/home/ros/fruit_detector_ws/src,type=bind", // Mount local workspace into the container
17+
//"workspaceFolder": "/home/ros/fruit_detector_ws/", // Path to the workspace within the container
1318

1419
// Forward specific ports from the container to the host machine
1520
"forwardPorts": [5801], // Port for remote desktop access
@@ -26,17 +31,39 @@
2631
// "postCreateCommand": "sudo src/aoc_fruit_detector/.devcontainer/scripts/post-create.sh'",
2732

2833
// Define environment variables to facilitate mounting local source code
29-
"remoteEnv": {
30-
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" // Sets local workspace path in the container
31-
},
34+
// "remoteEnv": {
35+
// "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" // Sets local workspace path in the container
36+
// },
3237

3338
"remoteUser": "ros", // Set the default user inside the container
3439
"updateRemoteUserUID": true, // Align container user UID with host user for permission consistency
35-
"shutdownAction": "stopCompose", // Gracefully stop the Compose environment on shutdown
40+
41+
"capAdd": ["NET_ADMIN"],
42+
43+
// Container environment variables
44+
"containerEnv": {
45+
"HOST_USER": "${localEnv:USER}",
46+
"HOST_HOSTNAME": "${localEnv:HOSTNAME}"
47+
},
48+
49+
// Mount additional volumes
50+
"mounts": [
51+
"source=/etc/timezone,target=/etc/timezone,type=bind,readonly",
52+
"source=/etc/localtime,target=/etc/localtime,type=bind,readonly",
53+
"source=/media,target=/media,type=bind"
54+
],
55+
56+
// Initialize command to set up networking
57+
"initializeCommand": "echo 'Setting up devcontainer...'",
58+
"postStartCommand": "/opt/entrypoint.sh /bin/true; ./src/.devcontainer/scripts/post-create.sh", // Run post-create script to set up the environment
3659

3760
// VS Code customizations: Install specific extensions on container startup
3861
"customizations": {
3962
"vscode": {
63+
"settings": {
64+
"git.defaultCloneDirectory": "/home/ros/fruit_detector_ws/src",
65+
"git.repositorySearchMaxDepth": 2
66+
},
4067
"extensions": [
4168
"ms-python.python", // Python support
4269
"GitHub.vscode-pull-request-github", // GitHub pull request and issue support
@@ -50,9 +77,7 @@
5077
},
5178

5279
// Define minimum requirements for the host machine when running this container
53-
// "hostRequirements": {
54-
// "gpu": "optional", // GPU support is optional, useful for CUDA if available
55-
// "cpus": 2, // Minimum 2 CPU cores recommended
56-
// "memory": "8gb" // Minimum 8GB RAM recommended
57-
// }
80+
"hostRequirements": {
81+
"gpu": "optional" // GPU support is optional, useful for CUDA if available
82+
}
5883
}

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
version: "3.8"
21
services:
32
fruit_detector:
43
labels:
54
- deploy.user=${USER}
6-
image: lcas.lincoln.ac.uk/lcas/ros:jammy-humble-cuda11.8-opengl
5+
image: lcas.lincoln.ac.uk/lcas/ros-docker-images:jammy-cuda11.8-humble-2
76
build:
87
dockerfile: .devcontainer/Dockerfile
98
context: ..

.devcontainer/repos/external.repos

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ repositories:
22
detectron2:
33
type: git
44
url: https://github.com/facebookresearch/detectron2.git
5-
version: main
6-
depth: 1
5+
version: 754469e176b224d17460612bdaa2cb8112b04cd9
6+
depth: 1

.devcontainer/scripts/install_external_ros_packages.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
# Exit immediately if a command exits with a non-zero status and enable debug mode for verbose output
44
set -e -x
55

6+
# Deactivate virtual environment to use system Python and avoid conflicts
7+
# The base image has a virtual environment active in /opt/venv that needs to be deactivated
8+
unset VIRTUAL_ENV
9+
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
10+
export PYTHONPATH=""
11+
12+
source /opt/ros/humble/setup.bash
13+
614
# Update rosdep database to ensure all dependencies are up-to-date
7-
rosdep update
15+
rosdep update --rosdistro ${ROS_DISTRO}
816
sudo apt-get update
917

1018
# Navigate to the src directory of the current workspace
@@ -22,7 +30,10 @@ vcs import < ${WS}/src/repos/external.repos
2230
# The '-y' flag automatically answers "yes" to any prompts
2331
rosdep install -r -y -i --from-paths .
2432

25-
# Install Python dependencies for the ultralytics_ros package
26-
python3 -m pip install -e detectron2
33+
# Install detectron2 in editable mode
34+
35+
#python3 -m pip install torch
36+
sudo pip install torch==2.7.0 torchvision==0.22.0 torchaudio==2.7.0 --index-url https://download.pytorch.org/whl/cu118
37+
sudo python -m pip install 'git+https://github.com/facebookresearch/detectron2.git@754469e176b224d17460612bdaa2cb8112b04cd9'
2738

2839
echo "Setup complete."
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
#!/bin/bash
22

33
set -e -x
4+
sudo apt-get update
5+
sudo apt-get install net-tools -y
6+
sudo ifconfig lo multicast || true
47

5-
colcon build
8+
sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev lo || true
9+
10+
11+
# Creates a colcon configuration directory and sets up default build options
12+
# - Creates ~/.colcon directory if it doesn't exist
13+
# - Generates a defaults.yaml file with symlink-install enabled for faster builds
14+
# - Symlink installation avoids copying files, making iterative development more efficient
15+
mkdir -p ${HOME}/.colcon
16+
cat << EOF > ${HOME}/.colcon/defaults.yaml
17+
{
18+
"build": {
19+
"symlink-install": true
20+
}
21+
}
22+
EOF
23+
24+
# network hack for DDS
25+
26+
rosdep update --rosdistro ${ROS_DISTRO}
27+
rosdep install -y --from-paths src/ -i --rosdistro ${ROS_DISTRO} -r
28+
29+
colcon build --continue-on-error

.github/workflows/dev-container.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
include:
19-
- configFile: .devcontainer/cuda-opengl/devcontainer.json
19+
- configFile: .devcontainer/devcontainer.json
2020
imageTag: cuda-opengl-hri
2121
steps:
2222
- name: Node Js

.github/workflows/docker-build-image.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20-
- base_image: lcas.lincoln.ac.uk/lcas/ros:jammy-humble-cuda11.8-opengl
20+
- base_image: lcas.lincoln.ac.uk/lcas/ros-docker-images:jammy-cuda11.8-humble-2
2121
ros_distro: humble
2222
push_image: lcas.lincoln.ac.uk/lcas/aoc_fruit_detector
2323

@@ -47,9 +47,13 @@ jobs:
4747
# list of Docker images to use as base name for tags
4848
images: |
4949
${{ matrix.push_image }}
50+
flavor: |
51+
latest=auto
5052
tags: |
53+
type=semver,pattern={{version}}
54+
type=semver,pattern={{major}}.{{minor}}
55+
type=semver,pattern={{major}}
5156
type=ref,event=branch,pattern=main
52-
latest
5357
5458
- name: Build Public Docker Image
5559
uses: docker/build-push-action@v6
@@ -60,8 +64,7 @@ jobs:
6064
push: ${{ github.event_name != 'pull_request' }}
6165
tags: ${{ steps.meta_public.outputs.tags }}
6266
labels: ${{ steps.meta_public.outputs.labels }}
63-
target: user_space
64-
#tags: ${{ matrix.push_image }},${{ matrix.push_image }}-${{ env.BRANCH }}
67+
target: deployed
6568
build-args: |
6669
BASE_IMAGE=${{ matrix.base_image }}
6770
BRANCH=${{ env.BRANCH }}

.github/workflows/ros-ci.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)