Skip to content

Commit

Permalink
arm image (#192)
Browse files Browse the repository at this point in the history
* arm docker image

* update base image

* cmake for arm

* possiblly missing dependencies?????

* use all the cores

* forgot cd pytorch-build

* Number of Cores that can compile without error on local Macbook

* only build arm on push to main

---------

Co-authored-by: Christopher Lee <chrisdenglee@gmail.com>
  • Loading branch information
atar13 and AskewParity authored Jun 10, 2024
1 parent 07a3f7a commit c93fc64
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 23 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/docker-arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Push ARM Docker Image

on:
push:
branches:
- main

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

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
with:
submodules: 'recursive'

- 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 }}:${{ env.TAG }}

- 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.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
labels: ${{ steps.meta.outputs.labels }}

87 changes: 64 additions & 23 deletions docker/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM arm64/ubuntu:22.04
FROM arm64v8/ubuntu:22.04

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

Expand Down Expand Up @@ -46,19 +46,22 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
# needed for matplotplus
gnuplot \
# imagemagick with c++ dependency
graphicsmagick-libmagick-dev-compat
libmagick++-dev \
# needed for pytorch
libopenblas-dev \
ninja-build \
libnuma-dev

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 pip3 install typing-extensions PyYAML cpplint numpy

RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
Expand All @@ -68,7 +71,7 @@ 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 \
&& wget https://github.com/Kitware/CMake/releases/download/v3.27.7/cmake-3.27.7-linux-aarch64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-3.24.1 \
Expand All @@ -81,26 +84,61 @@ RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v2.9.1 --
&& cd MAVSDK \
&& git submodule update --init --recursive \
&& cmake -DCMAKE_BUILD_TYPE=Release -Bbuild/default -H. \
&& cmake --build build/default -j2 --target install
&& cmake --build build/default -j4 --target install

# 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 USE_CUDA=0 \
USE_CUDNN=0 \
USE_NCCL=0 \
BUILD_TORCH=ON \
USE_MKLDNN=0 \
USE_ROCM=0 \
USE_KINETO=0 \
USE_NNPACK=1 \
BUILD_CAFFE2_OPS=0 \
BUILD_CAFFE2=0 \
cmake \
# don't need cuda, for now...
-DUSE_CUDA=0 \
# disable cudnn
-DUSE_CUDNN=0 \
# disable multigpu
-DUSE_NCCL=0 \
-DBUILD_TORCH=ON \
-DUSE_MKLDNN=0 \
-DUSE_ROCM=0 \
-DUSE_KINETO=0 \
-DUSE_NNPACK=1 \
-DBUILD_CAFFE2_OPS=0 \
-DBUILD_CAFFE2=0 \
-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 USE_CUDA=0 \
USE_CUDNN=0 \
USE_NCCL=0 \
BUILD_TORCH=ON \
USE_MKLDNN=0 \
USE_ROCM=0 \
USE_KINETO=0 \
USE_NNPACK=1 \
BUILD_CAFFE2_OPS=0 \
BUILD_CAFFE2=0 \
cmake --build . -j4 --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
Expand All @@ -113,20 +151,23 @@ RUN wget "https://github.com/pytorch/vision/archive/refs/tags/v${TORCHVISION_VER
&& 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 -j4 \
&& 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 pip3 install gdown
ENV PATH="${PATH}:${HOME}/.local/bin"

RUN make cuda_check VERBOSE=1
ARG ARENA_INSTALL_DIR=/arena-tmp
ARG ARENA_TAR_PATH="${ARENA_INSTALL_DIR}/ArenaSDK_Linux.tar.gz"
ENV ARENA_EXTRACTED_PATH="${ARENA_INSTALL_DIR}/ArenaSDK_Linux_ARM64"
WORKDIR ${ARENA_INSTALL_DIR}
RUN gdown 1VtBji-cWfetM5nXZwt55JuHPWPGahQOH -O ${ARENA_TAR_PATH}
RUN tar -xvzf ${ARENA_TAR_PATH}
WORKDIR ${ARENA_EXTRACTED_PATH}
RUN sh Arena_SDK_ARM64.conf

# login as non-root user
# USER $USERNAME
USER $USERNAME

CMD [ "/obcpp/build/bin/obcpp" ]
RUN pip3 install gdown
ENV PATH="${PATH}:${HOME}/.local/bin"

0 comments on commit c93fc64

Please sign in to comment.