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

jetson docker image #119

Merged
merged 28 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0deb841
nvidia docker image builds
tuas-travis-ci Feb 26, 2024
b4acdd6
cuda_check integration test
tuas-travis-ci Feb 26, 2024
f8bce66
docker dir makefile
tuas-travis-ci Feb 26, 2024
0348b7b
build all binaries
tuas-travis-ci Feb 26, 2024
1e4bfd4
fix build_jetson_image paths
tuas-travis-ci Feb 26, 2024
6f25d5f
cuda_check builds and works
tuas-travis-ci Mar 10, 2024
0884cf0
nvidia docker image builds
tuas-travis-ci Feb 26, 2024
49738fa
cuda_check integration test
tuas-travis-ci Feb 26, 2024
a0031f7
docker dir makefile
tuas-travis-ci Feb 26, 2024
8afd837
build all binaries
tuas-travis-ci Feb 26, 2024
fbb3f91
fix build_jetson_image paths
tuas-travis-ci Feb 26, 2024
8efafc9
cuda_check builds and works
tuas-travis-ci Mar 10, 2024
768620b
github action to build jetson dockerfile
atar13 Mar 11, 2024
5162dd3
pull_request
atar13 Mar 11, 2024
d0f5f6b
github actions might work?
atar13 Mar 13, 2024
6df7c0a
jetson Docker: compile obcpp and cuda_check
atar13 Mar 13, 2024
fb10828
bespoke github env
atar13 Mar 13, 2024
07a21fa
trying to free github runner space
atar13 Mar 13, 2024
f4307f4
disable half operators?
atar13 Mar 21, 2024
63d9556
trying dusty-nv's torchvision install
atar13 Mar 29, 2024
df1c960
Merge branch 'chore/jetson-dockerfile' of github.com:tritonuas/obcpp …
tuas-travis-ci Apr 10, 2024
80a1f3a
moved back to run make for torchvision
tuas-travis-ci Apr 10, 2024
bb87e0d
jetson docker composes
tuas-travis-ci Apr 10, 2024
8985ab1
Merge remote-tracking branch 'origin/main' into chore/jetson-dockerfile
atar13 Apr 10, 2024
aea1e36
disable jetson docker build
atar13 Apr 10, 2024
26b3b39
devcontianer use new x86 tag
atar13 Apr 10, 2024
08036cf
remove Dockerfile.nvidia in favor of Dockerfile.jetson
atar13 Apr 10, 2024
1ddf341
instructions for building jetson image
atar13 Apr 10, 2024
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
82 changes: 82 additions & 0 deletions .github/workflows/docker-jetson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Push Jetson Docker Image

on:
push:
branches:
- main
pull_request:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
TAG: "jetson"
DOCKERFILE_PATH: 'docker/Dockerfile.jetson'

jobs:
changes:
runs-on: ubuntu-latest
outputs:
dockerfile: ${{ steps.changes.outputs.dockerfile }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
dockerfile:
- ${{ env.DOCKERFILE_PATH }}

build-and-push-image:
needs: changes
if: ${{ needs.changes.outputs.dockerfile == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: true

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
platforms: linux/arm64
file: ${{ env.DOCKERFILE_PATH }}
context: .
push: true
tags: ${{ env.TAG }}
labels: ${{ steps.meta.outputs.labels }}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Push Docker Image
name: Push x86 Docker Image

on:
push:
Expand All @@ -8,6 +8,8 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
TAG: "x86"
DOCKERFILE_PATH: 'docker/Dockerfile.x86'

jobs:
changes:
Expand All @@ -21,7 +23,7 @@ jobs:
with:
filters: |
dockerfile:
- '.devcontainer/Dockerfile'
- ${{ env.DOCKERFILE_PATH }}

build-and-push-image:
needs: changes
Expand Down Expand Up @@ -50,9 +52,9 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
file: .devcontainer/Dockerfile
file: ${{ env.DOCKERFILE_PATH }}
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ env.TAG }}
labels: ${{ steps.meta.outputs.labels }}

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ lib/
bin/
logs/

Makefile
CMakeFiles/
build/
CMakeCache.txt
Expand All @@ -26,4 +25,4 @@ libcore_library.dylib
.DS_Store

**/*.pb.cc
**/*.pb.h
**/*.pb.h
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ add_subdirectory(src)

add_subdirectory(tests/integration)

# cuda_check
add_executable(cuda_check ${SOURCES} tests/integration/cuda_check.cpp)
target_add_torch(cuda_check)
target_add_json(cuda_check)
target_add_httplib(cuda_check)
target_add_mavsdk(cuda_check)
target_add_matplot(cuda_check)
target_add_protobuf(cuda_check)
target_add_opencv(cuda_check)
target_add_loguru(cuda_check)
# for some reason calling target_add_imagemagick here conflicts with, so we are including/linking without the function call
# target_add_imagemagick(cuda_check)
target_include_directories(cuda_check PRIVATE ${ImageMagick_INCLUDE_DIRS})
target_link_libraries(cuda_check PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES})
# =============================

# =============================
Expand Down
133 changes: 133 additions & 0 deletions docker/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
FROM arm64/ubuntu:22.04

ARG USERNAME=tuas USER_UID=1000 USER_GID=1000 DEBIAN_FRONTEND=noninteractive

# Needed to spawn up a GUI in headless mode for matplotplus to work
ENV QT_QPA_PLATFORM="vnc"

# Create a non-root user
RUN groupadd -f --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
# exit 0 ensures that it won't prematurely stop if for some reason the user already exists

# https://gist.github.com/SSARCandy/fc960d8905330ac695e71e3f3807ce3d
# OpenCV dependencies from above
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y build-essential \
software-properties-common \
sudo \
gdb \
git \
wget \
ccache \
vim \
curl \
unzip \
protobuf-compiler \
libopencv-dev \
# Need these to install Python 3.11 from pyenv
python3-pip \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
# libxm12-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
# needed for matplotplus
gnuplot \
# imagemagick with c++ dependency
graphicsmagick-libmagick-dev-compat

RUN apt-add-repository universe
RUN apt-get install -y cpplint

# Update Python to 3.11 so that libtorch can be properly built from source
ENV PYENV_ROOT="/.pyenv"
RUN curl https://pyenv.run | bash
ENV PATH="${PATH}:${PYENV_ROOT}/bin"
RUN eval "$(pyenv init -)"
RUN pyenv install 3.11
RUN pyenv global 3.11
RUN pip3 install typing-extensions PyYAML

RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Download latest CMake from their repositories
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& wget https://github.com/Kitware/CMake/releases/download/v3.27.7/cmake-3.27.7-linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-3.24.1 \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin

# install prebuilt MAVSDK to system
# https://github.com/mavlink/MAVSDK/releases
ARG MAVSDK_VERSION=1.4.17
ARG MAVSDK_DEB=libmavsdk-dev_${MAVSDK_VERSION}_debian11_arm64.deb
RUN wget https://github.com/mavlink/MAVSDK/releases/download/v${MAVSDK_VERSION}/${MAVSDK_DEB} \
&& dpkg -i ${MAVSDK_DEB} \
&& rm ${MAVSDK_DEB}

# the official docs say also these
# https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
# cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
# python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

# pull pre-built libtorch
ARG LIBTORCH_VERSION=2.1.0
ARG LIBTORCH_INSTALL_DIR=/libtorch-tmp
WORKDIR ${LIBTORCH_INSTALL_DIR}
RUN git clone -b main --recurse-submodule https://github.com/pytorch/pytorch.git
RUN mkdir pytorch-build
RUN cd pytorch-build
RUN cmake -D_GLIBCXX_USE_CXX11_ABI=1 -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Release -DPYTHON_EXECUTABLE:PATH=`which python3` -DCMAKE_PREFIX_PATH=../pytorch-install ${LIBTORCH_INSTALL_DIR}/pytorch
RUN cmake --build . --target install

# RUN wget "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-${LIBTORCH_VERSION}%2Bcpu.zip" \
# && unzip "libtorch-cxx11-abi-shared-with-deps-${LIBTORCH_VERSION}+cpu.zip"
# needed to build torchvision below and to build targets that use libtorch inside the container
ENV CMAKE_PREFIX_PATH="${LIBTORCH_INSTALL_DIR}/libtorch"

# pull and build torchvision
# refer to this page for version compatibilty with pytorch (libtorch) https://github.com/pytorch/pytorch/wiki/PyTorch-Versions
ARG TORCHVISION_VERSION=0.16.0
ARG TORCHVISION_INSTALL_DIR=/torchvision-tmp
WORKDIR ${TORCHVISION_INSTALL_DIR}
RUN wget "https://github.com/pytorch/vision/archive/refs/tags/v${TORCHVISION_VERSION}.zip" \
&& unzip "v${TORCHVISION_VERSION}.zip" \
&& mkdir -p "${TORCHVISION_INSTALL_DIR}/vision-${TORCHVISION_VERSION}/build" \
&& cd "${TORCHVISION_INSTALL_DIR}/vision-${TORCHVISION_VERSION}/build" \
&& cmake -DWITH_CUDA=off -D_GLIBCXX_USE_CXX11_ABI=1 -DCMAKE_BUILD_TYPE=Release .. \
&& make -j2 \
&& make install

WORKDIR /obcpp
COPY . .

RUN rm -rf /obcpp/build
WORKDIR /obcpp/build
ENV CMAKE_PREFIX_PATH="/usr/local/lib/python3.8/dist-packages/torch/share/cmake/Torch;/usr/local/share/cmake/TorchVision"
RUN GITHUB_ACTIONS=true cmake -DCMAKE_PREFIX_PATH="/usr/local/lib/python3.8/dist-packages/torch/share/cmake/Torch;/usr/local/share/cmake/TorchVision" -DCMAKE_MODULE_PATH="/usr/local/share/cmake/TorchVision" -DCMAKE_BUILD_TYPE="Debug" ..

RUN make cuda_check VERBOSE=1

# login as non-root user
# USER $USERNAME

CMD [ "/obcpp/build/bin/obcpp" ]
103 changes: 103 additions & 0 deletions docker/Dockerfile.jetson
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
FROM tritonuas/jetson-base:r35.3.1

# this base image came from dusty-nv/jetson-containers
# ./build.sh --name=tritonuas/jetson-base pytorch:2.1 torchvision opencv

ARG USERNAME=tuas USER_UID=1000 USER_GID=1000 DEBIAN_FRONTEND=noninteractive

# Needed to spawn up a GUI in headless mode for matplotplus to work
ENV QT_QPA_PLATFORM="vnc"

# Create a non-root user
RUN groupadd -f --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
# exit 0 ensures that it won't prematurely stop if for some reason the user already exists

# https://gist.github.com/SSARCandy/fc960d8905330ac695e71e3f3807ce3d
# OpenCV dependencies from above
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y build-essential \
software-properties-common \
sudo \
gdb \
git \
wget \
ccache \
vim \
curl \
unzip \
protobuf-compiler \
# Need these to install Python 3.11 from pyenv
python3-pip \
libssl-dev \
libjpeg-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
# needed for matplotplus
gnuplot \
# imagemagick with c++ dependency
libmagick++-dev \
# needed for pytorch
libopenblas-dev

RUN pip3 install typing-extensions PyYAML cpplint

RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# install prebuilt MAVSDK to system
# https://github.com/mavlink/MAVSDK/releases
ARG MAVSDK_VERSION=1.4.17
ARG MAVSDK_DEB=libmavsdk-dev_${MAVSDK_VERSION}_debian11_arm64.deb
RUN wget https://github.com/mavlink/MAVSDK/releases/download/v${MAVSDK_VERSION}/${MAVSDK_DEB} \
&& dpkg -i ${MAVSDK_DEB} \
&& rm ${MAVSDK_DEB}

# pull and build torchvision
# refer to this page for version compatibilty with pytorch (libtorch) https://github.com/pytorch/pytorch/wiki/PyTorch-Versions
ARG TORCHVISION_VERSION=0.16.0
#ARG TORCHVISION_INSTALL_DIR=/torchvision-tmp
WORKDIR ${TORCHVISION_INSTALL_DIR}
RUN wget "https://github.com/pytorch/vision/archive/refs/tags/v${TORCHVISION_VERSION}.zip" \
&& unzip "v${TORCHVISION_VERSION}.zip" \
&& cd vision-0.16.0 \
&& mkdir build \
&& cd build \
&& cmake -DWITH_CUDA=1 -DCUDA_HAS_FP16=1 -DCUDA_NO_HALF_OPERATORS=1 -DCUDA_NO_HALF_CONVERSIONS=1 -DCUDA_NO_HALF2_OPERATORS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/usr/local/lib/python3.8/dist-packages/torch/share/cmake/Torch" .. \
&& make -j4 \
&& make install

# Install g++10 and replace the older version. For some reason some c++ 20 features aren't working with g++9 even though
# we have CMake configured to use c++ 20 https://stackoverflow.com/questions/69037873/why-am-i-missing-c20-headers-and-how-do-i-fix-this
RUN apt-get update && apt-get install -y g++-10 gcc-10
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
RUN update-alternatives --set gcc /usr/bin/gcc-10
RUN update-alternatives --set g++ /usr/bin/g++-10

WORKDIR /obcpp
COPY . .

RUN rm -rf /obcpp/build
WORKDIR /obcpp/build
ENV CMAKE_PREFIX_PATH="/usr/local/lib/python3.8/dist-packages/torch/share/cmake/Torch;/usr/local/share/cmake/TorchVision"
RUN GITHUB_ACTIONS=true cmake -DCMAKE_PREFIX_PATH="/usr/local/lib/python3.8/dist-packages/torch/share/cmake/Torch;/usr/local/share/cmake/TorchVision" -DCMAKE_MODULE_PATH="/usr/local/share/cmake/TorchVision" -DCMAKE_BUILD_TYPE="Release" ..

RUN make obcpp cuda_check load_torchvision_model VERBOSE=1

# login as non-root user
# USER $USERNAME

CMD [ "/obcpp/build/bin/obcpp" ]
Loading
Loading