From 68c044c574eba2dca39330091281009320241b3d Mon Sep 17 00:00:00 2001 From: Oguz Ozturk Date: Tue, 24 Dec 2024 13:48:57 +0300 Subject: [PATCH 1/6] Add simulator and visualizer containers Signed-off-by: Oguz Ozturk --- .../actions/docker-build-and-push/action.yaml | 29 +++++ docker/docker-bake-tools.hcl | 22 ++++ docker/tools/Dockerfile | 101 ++++++++++++++++++ docker/tools/etc/entrypoint.sh | 82 ++++++++++++++ docker/tools/etc/xstartup | 15 +++ 5 files changed, 249 insertions(+) create mode 100644 docker/docker-bake-tools.hcl create mode 100644 docker/tools/Dockerfile create mode 100644 docker/tools/etc/entrypoint.sh create mode 100644 docker/tools/etc/xstartup diff --git a/.github/actions/docker-build-and-push/action.yaml b/.github/actions/docker-build-and-push/action.yaml index 5feb1bcc41..424b824456 100644 --- a/.github/actions/docker-build-and-push/action.yaml +++ b/.github/actions/docker-build-and-push/action.yaml @@ -181,6 +181,32 @@ runs: flavor: | latest=false + - name: Docker meta for autoware:universe-visualizer + id: meta-universe-visualizer + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }} + tags: | + type=raw,value=universe-visualizer-${{ inputs.platform }} + type=raw,value=universe-visualizer-${{ steps.date.outputs.date }}-${{ inputs.platform }} + type=ref,event=tag,prefix=universe-visualizer-,suffix=-${{ inputs.platform }} + bake-target: docker-metadata-action-universe-visualizer + flavor: | + latest=false + + - name: Docker meta for autoware:universe-simulator + id: meta-universe-simulator + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }} + tags: | + type=raw,value=universe-simulator-${{ inputs.platform }} + type=raw,value=universe-simulator-${{ steps.date.outputs.date }}-${{ inputs.platform }} + type=ref,event=tag,prefix=universe-simulator-,suffix=-${{ inputs.platform }} + bake-target: docker-metadata-action-universe-simulator + flavor: | + latest=false + - name: Docker meta for autoware:universe-devel id: meta-universe-devel uses: docker/metadata-action@v5 @@ -220,6 +246,7 @@ runs: push: true files: | docker/docker-bake.hcl + docker/docker-bake-tools.hcl ${{ steps.meta-core-devel.outputs.bake-file }} ${{ steps.meta-universe-sensing-perception-devel.outputs.bake-file }} ${{ steps.meta-universe-sensing-perception.outputs.bake-file }} @@ -231,6 +258,8 @@ runs: ${{ steps.meta-universe-vehicle-system.outputs.bake-file }} ${{ steps.meta-universe-devel.outputs.bake-file }} ${{ steps.meta-universe.outputs.bake-file }} + ${{ steps.meta-simulator.outputs.bake-file }} + ${{ steps.meta-visualizer.outputs.bake-file }} provenance: false set: | ${{ inputs.build-args }} diff --git a/docker/docker-bake-tools.hcl b/docker/docker-bake-tools.hcl new file mode 100644 index 0000000000..4a41a20adb --- /dev/null +++ b/docker/docker-bake-tools.hcl @@ -0,0 +1,22 @@ +group "default" { + targets = [ + "simulator", + "visualizer" + ] +} + +// For docker/metadata-action +target "docker-metadata-action-simulator" {} +target "docker-metadata-action-visualizer" {} + +target "simulator" { + inherits = ["docker-metadata-action-simulator"] + dockerfile = "docker/tools/Dockerfile" + target = "simulator" +} + +target "visualizer" { + inherits = ["docker-metadata-action-visualizer"] + dockerfile = "docker/tools/Dockerfile" + target = "visualizer" +} diff --git a/docker/tools/Dockerfile b/docker/tools/Dockerfile new file mode 100644 index 0000000000..c309a9d0bc --- /dev/null +++ b/docker/tools/Dockerfile @@ -0,0 +1,101 @@ +ARG ROS_DISTRO + +### Builder +FROM ghcr.io/autowarefoundation/autoware:universe-devel AS builder +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +ENV CCACHE_DIR="/root/.ccache" +WORKDIR /autoware +COPY src /autoware/src +COPY simulator.repos /autoware/simulator.repos +COPY docker/scripts/resolve_rosdep_keys.sh /autoware/resolve_rosdep_keys.sh +RUN chmod +x /autoware/resolve_rosdep_keys.sh + +# Install dependencies and build the simulator +RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + vcs import src < simulator.repos \ + && apt-get update \ + && rosdep update && rosdep install -y --from-paths src --ignore-src --rosdistro $ROS_DISTRO \ + && source /opt/ros/"$ROS_DISTRO"/setup.bash && source /opt/autoware/setup.bash \ + && colcon build --cmake-args \ + "-Wno-dev" \ + "--no-warn-unused-cli" \ + --install-base /opt/autoware \ + --merge-install \ + --mixin release compile-commands ccache \ + --base-paths /autoware/src/simulator \ + && find /opt/autoware/lib -type f -name "*.py" -exec chmod +x {} \; \ + && find /opt/autoware/share -type f -name "*.py" -exec chmod +x {} \; \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + +# Extract rosdep dependencies for simulator +RUN /autoware/resolve_rosdep_keys.sh /autoware/src/simulator ${ROS_DISTRO} \ + > /rosdep-simulator-depend-packages.txt \ + && cat /rosdep-simulator-depend-packages.txt + +### Simulator +FROM ghcr.io/autowarefoundation/autoware:universe AS simulator +WORKDIR /autoware +COPY --from=builder /opt/autoware /opt/autoware +COPY --from=builder /rosdep-simulator-depend-packages.txt /tmp/rosdep-simulator-depend-packages.txt + +RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + apt-get update && apt-get install -y curl unzip \ + && source /opt/ros/"$ROS_DISTRO"/setup.bash && source /opt/autoware/setup.bash \ + && rosdep update \ + && cat /tmp/rosdep-simulator-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* "$HOME"/.cache && \ + echo "source /opt/autoware/setup.bash" > /etc/bash.bashrc + +COPY docker/tools/etc/entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/bin/bash"] + +### Visualizer +FROM simulator AS visualizer +WORKDIR /autoware + +# Install openbox and VNC requirements +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl unzip openbox tigervnc-standalone-server tigervnc-common \ + novnc websockify python3-numpy python3-xdg \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Set up VNC password +RUN mkdir -p ~/.vnc && \ + echo "openadkit" | vncpasswd -f > ~/.vnc/passwd && \ + chmod 600 ~/.vnc/passwd + +# Create SSL certificate for NoVNC +RUN openssl req -x509 -nodes -newkey rsa:2048 \ + -keyout /etc/ssl/private/novnc.key \ + -out /etc/ssl/certs/novnc.crt \ + -days 365 \ + -subj "/O=Autoware-OpenADKit/CN=localhost" + +# Install ngrok for optional public access if no public ip available +RUN curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \ + | tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && \ + echo "deb https://ngrok-agent.s3.amazonaws.com buster main" \ + | tee /etc/apt/sources.list.d/ngrok.list && \ + apt update && \ + apt install ngrok + +# Need to expose VNC and NoVNC ports when running the container +EXPOSE 5900 6080 + +# Add source commands to bash startup +RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> /root/.bashrc && \ + echo "source /opt/autoware/setup.bash" >> /root/.bashrc + +# Copy startup scripts +COPY docker/tools/etc/xstartup /root/.vnc/xstartup +COPY docker/tools/etc/entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh && chmod +x /root/.vnc/xstartup +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/bin/bash"] \ No newline at end of file diff --git a/docker/tools/etc/entrypoint.sh b/docker/tools/etc/entrypoint.sh new file mode 100644 index 0000000000..fe42782207 --- /dev/null +++ b/docker/tools/etc/entrypoint.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +configure_vnc() { + # Create Openbox application configuration + mkdir -p /etc/xdg/openbox + cat > /etc/xdg/openbox/rc.xml << 'EOF' + + + + + yes + + center + center + + yes + 1 + + + +EOF + # Create rviz2 start script + cat > /usr/local/bin/start-rviz2.sh << 'EOF' +#!/bin/bash +source /opt/ros/humble/setup.bash +source /opt/autoware/setup.bash +if [ -n "$RVIZ_CONFIG" ]; then + exec rviz2 -d "$RVIZ_CONFIG" +else + exec rviz2 +fi +EOF + chmod +x /usr/local/bin/start-rviz2.sh + echo "echo 'Autostart executed at $(date)' >> /tmp/autostart.log" >> /etc/xdg/openbox/autostart + echo "/usr/local/bin/start-rviz2.sh" >> /etc/xdg/openbox/autostart + + # Start VNC server with Openbox + echo "Starting VNC server with Openbox..." + vncserver :99 -geometry 1024x768 -depth 16 -pixelformat rgb565 + VNC_RESULT=$? + + if [ $VNC_RESULT -ne 0 ]; then + echo "Failed to start VNC server (exit code: $VNC_RESULT)" + exit $VNC_RESULT + fi + + # Set the DISPLAY variable to match VNC server + echo "Setting DISPLAY to :99" + echo "export DISPLAY=:99" >> ~/.bashrc + sleep 2 + + # Start NoVNC + echo "Starting NoVNC..." + websockify --daemon --web=/usr/share/novnc/ --cert=/etc/ssl/certs/novnc.crt --key=/etc/ssl/private/novnc.key 6080 localhost:5999 + + # Configure ngrok if set + if [ -n "$NGROK_AUTHTOKEN" ]; then + ngrok config add-authtoken "$NGROK_AUTHTOKEN" + + if [ -n "$NGROK_URL" ]; then + ngrok http --url="$NGROK_URL" 6080 --log=stdout >ngrok.log & + else + ngrok http 6080 --log=stdout >ngrok.log & + sleep 2 + NGROK_URL=$(grep -oP 'url=\K[^\s]+' ngrok.log) + fi + fi + + # Print info + echo -e "\033[32m-------------------------------------------------------------------------\033[0m" + echo -e "\033[32mBrowser interface available at local address http://$(hostname -I | cut -d' ' -f1):6080/vnc.html?resize=scale&password=openadkit&autoconnect=true\033[0m" + [ -z "$NGROK_AUTHTOKEN" ] && echo -e "\033[32mIf you have a static public ip you can access it on WEB at http://$(curl -s ifconfig.me):6080/vnc.html?resize=scale&password=openadkit&autoconnect=true\033[0m" + [ -n "$NGROK_AUTHTOKEN" ] && echo -e "\033[32mBrowser interface available at WEB address $NGROK_URL/vnc.html?resize=scale&password=openadkit&autoconnect=true\033[0m" + echo -e "\033[32m-------------------------------------------------------------------------\033[0m" +} + +# shellcheck disable=SC1090 +[ "$VNC_ENABLED" == "true" ] && configure_vnc +source "/opt/ros/$ROS_DISTRO/setup.bash" +source "/opt/autoware/setup.bash" +exec "$@" \ No newline at end of file diff --git a/docker/tools/etc/xstartup b/docker/tools/etc/xstartup new file mode 100644 index 0000000000..cd435a8d1b --- /dev/null +++ b/docker/tools/etc/xstartup @@ -0,0 +1,15 @@ +#!/bin/sh + +unset SESSION_MANAGER +unset DBUS_SESSION_BUS_ADDRESS +export DISPLAY=:99 + +[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup +[ -r "$HOME/.Xresources" ] && xrdb "$HOME/.Xresources" + +# Start Openbox window manager +echo "Starting Openbox window manager..." +openbox-session & + +# Keep the session alive +sleep infinity \ No newline at end of file From fc716717e2b36f0051cefeeaabeb7a54978ffd3a Mon Sep 17 00:00:00 2001 From: Oguz Ozturk Date: Tue, 24 Dec 2024 14:12:15 +0300 Subject: [PATCH 2/6] . Signed-off-by: Oguz Ozturk --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 679e11b25e..53eaf71ad0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,6 +10,7 @@ docker !docker/etc !docker/scripts +!docker/tools # Ignore a part of files under src src/**/.* From e0ad5f2e01b383fb94a2451260404bbb7ed53752 Mon Sep 17 00:00:00 2001 From: Oguz Ozturk Date: Tue, 24 Dec 2024 14:23:08 +0300 Subject: [PATCH 3/6] . Signed-off-by: Oguz Ozturk --- .github/actions/docker-build-and-push/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/docker-build-and-push/action.yaml b/.github/actions/docker-build-and-push/action.yaml index 424b824456..6692718aaf 100644 --- a/.github/actions/docker-build-and-push/action.yaml +++ b/.github/actions/docker-build-and-push/action.yaml @@ -195,7 +195,7 @@ runs: latest=false - name: Docker meta for autoware:universe-simulator - id: meta-universe-simulator + id: meta-simulator uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }} @@ -208,7 +208,7 @@ runs: latest=false - name: Docker meta for autoware:universe-devel - id: meta-universe-devel + id: meta-devel uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }} From 3fae5f4e0a48f4fc9244563a86f436da2c55924c Mon Sep 17 00:00:00 2001 From: Oguz Ozturk Date: Tue, 24 Dec 2024 14:39:50 +0300 Subject: [PATCH 4/6] . Signed-off-by: Oguz Ozturk --- .../actions/docker-build-and-push/action.yaml | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/actions/docker-build-and-push/action.yaml b/.github/actions/docker-build-and-push/action.yaml index 6692718aaf..64f14a19ba 100644 --- a/.github/actions/docker-build-and-push/action.yaml +++ b/.github/actions/docker-build-and-push/action.yaml @@ -181,29 +181,29 @@ runs: flavor: | latest=false - - name: Docker meta for autoware:universe-visualizer - id: meta-universe-visualizer + - name: Docker meta for autoware:visualizer + id: meta-visualizer uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }} tags: | - type=raw,value=universe-visualizer-${{ inputs.platform }} - type=raw,value=universe-visualizer-${{ steps.date.outputs.date }}-${{ inputs.platform }} - type=ref,event=tag,prefix=universe-visualizer-,suffix=-${{ inputs.platform }} - bake-target: docker-metadata-action-universe-visualizer + type=raw,value=visualizer-${{ inputs.platform }} + type=raw,value=visualizer-${{ steps.date.outputs.date }}-${{ inputs.platform }} + type=ref,event=tag,prefix=visualizer-,suffix=-${{ inputs.platform }} + bake-target: docker-metadata-action-visualizer flavor: | latest=false - - name: Docker meta for autoware:universe-simulator + - name: Docker meta for autoware:simulator id: meta-simulator uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository_owner }}/${{ inputs.target-image }} tags: | - type=raw,value=universe-simulator-${{ inputs.platform }} - type=raw,value=universe-simulator-${{ steps.date.outputs.date }}-${{ inputs.platform }} - type=ref,event=tag,prefix=universe-simulator-,suffix=-${{ inputs.platform }} - bake-target: docker-metadata-action-universe-simulator + type=raw,value=simulator-${{ inputs.platform }} + type=raw,value=simulator-${{ steps.date.outputs.date }}-${{ inputs.platform }} + type=ref,event=tag,prefix=simulator-,suffix=-${{ inputs.platform }} + bake-target: docker-metadata-action-simulator flavor: | latest=false From f7337c8a7015055eb7be649d4e98435824971958 Mon Sep 17 00:00:00 2001 From: Oguz Ozturk Date: Thu, 2 Jan 2025 15:03:35 +0300 Subject: [PATCH 5/6] . Signed-off-by: Oguz Ozturk --- docker/tools/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/tools/Dockerfile b/docker/tools/Dockerfile index c309a9d0bc..e5f338f2fe 100644 --- a/docker/tools/Dockerfile +++ b/docker/tools/Dockerfile @@ -45,6 +45,9 @@ RUN --mount=type=ssh \ apt-get update && apt-get install -y curl unzip \ && source /opt/ros/"$ROS_DISTRO"/setup.bash && source /opt/autoware/setup.bash \ && rosdep update \ + # Remove xmlschema and yamale from rosdep packages since we install via pip + && sed -i '/\(xmlschema\|yamale\)/d' /tmp/rosdep-simulator-depend-packages.txt \ + && pip install yamale xmlschema \ && cat /tmp/rosdep-simulator-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* "$HOME"/.cache && \ From 79d8a6fd64efc37fa8ec79394d3e592a207ea76b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 13:47:53 +0000 Subject: [PATCH 6/6] style(pre-commit): autofix --- docker/tools/Dockerfile | 2 +- docker/tools/etc/entrypoint.sh | 12 ++++++------ docker/tools/etc/xstartup | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docker/tools/Dockerfile b/docker/tools/Dockerfile index e5f338f2fe..b6c3d94418 100644 --- a/docker/tools/Dockerfile +++ b/docker/tools/Dockerfile @@ -101,4 +101,4 @@ COPY docker/tools/etc/xstartup /root/.vnc/xstartup COPY docker/tools/etc/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh && chmod +x /root/.vnc/xstartup ENTRYPOINT ["/entrypoint.sh"] -CMD ["/bin/bash"] \ No newline at end of file +CMD ["/bin/bash"] diff --git a/docker/tools/etc/entrypoint.sh b/docker/tools/etc/entrypoint.sh index fe42782207..ba6f69f2ef 100644 --- a/docker/tools/etc/entrypoint.sh +++ b/docker/tools/etc/entrypoint.sh @@ -3,7 +3,7 @@ configure_vnc() { # Create Openbox application configuration mkdir -p /etc/xdg/openbox - cat > /etc/xdg/openbox/rc.xml << 'EOF' + cat >/etc/xdg/openbox/rc.xml <<'EOF' @@ -21,7 +21,7 @@ configure_vnc() { EOF # Create rviz2 start script - cat > /usr/local/bin/start-rviz2.sh << 'EOF' + cat >/usr/local/bin/start-rviz2.sh <<'EOF' #!/bin/bash source /opt/ros/humble/setup.bash source /opt/autoware/setup.bash @@ -32,8 +32,8 @@ else fi EOF chmod +x /usr/local/bin/start-rviz2.sh - echo "echo 'Autostart executed at $(date)' >> /tmp/autostart.log" >> /etc/xdg/openbox/autostart - echo "/usr/local/bin/start-rviz2.sh" >> /etc/xdg/openbox/autostart + echo "echo 'Autostart executed at $(date)' >> /tmp/autostart.log" >>/etc/xdg/openbox/autostart + echo "/usr/local/bin/start-rviz2.sh" >>/etc/xdg/openbox/autostart # Start VNC server with Openbox echo "Starting VNC server with Openbox..." @@ -47,7 +47,7 @@ EOF # Set the DISPLAY variable to match VNC server echo "Setting DISPLAY to :99" - echo "export DISPLAY=:99" >> ~/.bashrc + echo "export DISPLAY=:99" >>~/.bashrc sleep 2 # Start NoVNC @@ -79,4 +79,4 @@ EOF [ "$VNC_ENABLED" == "true" ] && configure_vnc source "/opt/ros/$ROS_DISTRO/setup.bash" source "/opt/autoware/setup.bash" -exec "$@" \ No newline at end of file +exec "$@" diff --git a/docker/tools/etc/xstartup b/docker/tools/etc/xstartup index cd435a8d1b..ba1c8c814a 100644 --- a/docker/tools/etc/xstartup +++ b/docker/tools/etc/xstartup @@ -12,4 +12,4 @@ echo "Starting Openbox window manager..." openbox-session & # Keep the session alive -sleep infinity \ No newline at end of file +sleep infinity