frigate icon indicating copy to clipboard operation
frigate copied to clipboard

Updated Dockerfiles to be able to build for Jetpack 6

Open AndBobsYourUncle opened this issue 9 months ago • 8 comments

Spent a good day or so trying to get the base images for Jetpack 6 to be able to be used to build Frigate. Since it now is based on Ubuntu 22, that means that it also does not have Python 3.9.

So, you have to use deadsnakes, and there are a few other packages that need to have different versions installed.

Tried to make a minimal footprint, and this definitely can get cleaned up a bit and more conditionals thrown in. Wanted to get this PR up just in case others also were curious if it was possible before we actually clean it up to merge.

Successfully built using:

ARCH=arm64 BASE_IMAGE=nvcr.io/nvidia/l4t-tensorrt:r8.6.2-runtime  \
SLIM_BASE=nvcr.io/nvidia/l4t-tensorrt:r8.6.2-runtime \
TRT_BASE=nvcr.io/nvidia/tensorrt:24.04-py3 \
docker buildx bake --load --file=docker/tensorrt/trt.hcl \
  --set tensorrt.tags=frigate:latest-tensorrt-jp6 tensorrt

Container running for the first time, generating the TensorRT file: Screenshot 2024-05-09 at 11 09 35 PM

It appears to also be using GPU: Screenshot 2024-05-09 at 11 10 30 PM

AndBobsYourUncle avatar May 10 '24 03:05 AndBobsYourUncle

Deploy Preview for frigate-docs canceled.

Name Link
Latest commit 3be19592f8180d7dcc1bf700fdf1997f4f98887a
Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/663db79e47caee000843dc5c

netlify[bot] avatar May 10 '24 03:05 netlify[bot]

@NickM-27

I don't think it should be necessary to install these packages on the main dockerfile and other scripts that are unrelated to the jetson image.

You're right, I thought that was strange as well. However, since Jetson devices use an image that is based on Ubuntu 22.04, that means they include Python 3.10 by default. Also, Python 3.9 is simply not available to install in Ubuntu 22.04.

So, to recap:

  1. Python 3.9 is not available to install on the base layer in Jetpack 6.0 base images. Therefore, none of the other places in Docker have it available.
  2. libdc1394-22-dev is not available in Ubuntu 22.04, and instead is replaced by libdc1394-dev
  3. python3-tflite-runtime python3-pycoral cannot be installed as they were in Ubuntu 22.04, because of the Python version
  4. libprotobuf17 has been replaced by libprotobuf23 in Ubuntu 22.04
  5. The list goes on...

Do you think we should pull out Jetpack 6.0 as a fresh Docker image built from scratch? I started out building with just a change to the buld_jetson_ffmpeg.sh script, but ran into all these other problems along the way (hence why it took a whole day to get it built and working).

AndBobsYourUncle avatar May 10 '24 16:05 AndBobsYourUncle

So, if we cannot do these changes, then perhaps I must wait for the migration to Python 3.10 for Frigate before I can use it with Jetpack 6.0?

AndBobsYourUncle avatar May 10 '24 17:05 AndBobsYourUncle

So, if we cannot do these changes, then perhaps I must wait for the migration to Python 3.10 for Frigate before I can use it with Jetpack 6.0?

seems likely, we would not want to be doing changes to the other docker images at this point in the release cycle

NickM-27 avatar May 10 '24 17:05 NickM-27

seems likely, we would not want to be doing changes to the other docker images at this point in the release cycle

Well, then that is a bummer. A lot of wasted work then 😅

AndBobsYourUncle avatar May 10 '24 17:05 AndBobsYourUncle

in general it is a good idea to propose an idea before spending a lot of time on it, especially for a community supported detector like Jetson which is not code-owned by the maintainers of frigate itself

NickM-27 avatar May 10 '24 17:05 NickM-27

in general it is a good idea to propose an idea before spending a lot of time on it, especially for a community supported detector like Jetson which is not code-owned by the maintainers of frigate itself

Not blaming you for my wasted time at all. I have my Jetson device sitting here, upgraded, and wanted to get Frigate working on it.

I'll patiently wait until Frigate gets the rest of its Docker upgraded to Python 3.10. In the meantime I'll likely just keep building this on the side so that I can at least keep running it on my machine (and for other people who also might be stuck waiting for Jetpack 6.0 support).

AndBobsYourUncle avatar May 10 '24 17:05 AndBobsYourUncle

@AndBobsYourUncle thanks for keeping this support going!

Frigate's normal base image is debian:11, so the natural upgrade is to debian:12, which comes with Python 3.11. Ubuntu 22.04 comes with Python 3.10 but you can apt-install python3.11 and update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 just like it currently does for python3.9. If you can upgrade your PR to use 3.11 instead of 3.10, you'll be well positioned to slide in after the Debian upgrade (and if you're feeling generous you could PR that too, recognizing it won't be merged right now but clarifying that the Jetpack 6 support doesn't actually require as many changes).

madsciencetist avatar May 31 '24 03:05 madsciencetist

I get some error when tryting to build this container:

 => => sha256:25c18e2b33d29c4a543fef468178852711b9f3a94d09a99fcf80f6e841c1ac2f 17.83MB / 192.39MB  195.4s
 => [tensorrt internal] load build context                                                           0.0s
 => => transferring context: 4.01kB                                                                  0.0s
 => [rootfs rootfs 2/4] COPY frigate frigate/                                                        0.1s
 => [tensorrt rootfs 3/4] COPY migrations migrations/                                                0.0s
 => CANCELED [wheels wheels 1/7] RUN apt-get -qq update     && apt-get -qq install -y     apt-tran  66.9s
 => CANCELED [wget wget 1/2] RUN apt-get update     && apt-get install -y wget xz-utils     && rm   66.8s
 => ERROR [tensorrt build-wheels 2/4] RUN apt-get -qq update     && apt-get -qq install -y --no-in  55.1s
 => CANCELED [tensorrt-base deps 1/4] RUN --mount=type=bind,source=docker/main/install_deps.sh,tar  66.8s
 => CANCELED [tensorrt-base nginx 1/1] RUN --mount=type=tmpfs,target=/tmp --mount=type=tmpfs,targe  66.8s
------
 > [tensorrt build-wheels 2/4] RUN apt-get -qq update     && apt-get -qq install -y --no-install-recommends        python3.9 python3.9-dev        wget build-essential cmake git     && rm -rf /var/lib/apt/lists/*:
52.51 W: https://repo.download.nvidia.com/jetson/common/dists/r36.0/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
54.93 E: Unable to locate package python3.9-dev
54.93 E: Couldn't find any package by glob 'python3.9-dev'
54.93 E: Couldn't find any package by regex 'python3.9-dev'
------
Dockerfile.arm64:11
--------------------
  10 |     # Use a separate container to build wheels to prevent build dependencies in final image
  11 | >>> RUN apt-get -qq update \
  12 | >>>     && apt-get -qq install -y --no-install-recommends \
  13 | >>>        python3.9 python3.9-dev \
  14 | >>>        wget build-essential cmake git \
  15 | >>>     && rm -rf /var/lib/apt/lists/*
  16 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get -qq update     && apt-get -qq install -y --no-install-recommends        python3.9 python3.9-dev        wget build-essential cmake git     && rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100

bogdanr avatar Aug 13 '24 08:08 bogdanr

@AndBobsYourUncle Did you publish an image for your build with Jetpack 6 ? I would be interested to take a look!

fpaupier avatar Sep 20 '24 08:09 fpaupier