-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.full
150 lines (136 loc) · 5.26 KB
/
Dockerfile.full
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Copyright (c) 2022 Ho Kim (ho.kim@ulagbulag.io). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.
# Configure environment variables
ARG FUNCTION_HOME="/opt/dash/functions/builtins"
ARG PACKAGE="openark"
ARG PYTORCH_RELEASE="23.08"
ARG PYTHON_VERSION="3"
ARG ROS_DISTRO="humble"
# Be ready for serving
FROM "nvcr.io/nvidia/pytorch:${PYTORCH_RELEASE}-py${PYTHON_VERSION}" AS server
# Package Manager Configuration
ARG DEBIAN_FRONTEND='noninteractive'
# Server Configuration
EXPOSE 80/tcp
WORKDIR /usr/local/bin
CMD [ "/bin/sh" ]
# Install dependencies
RUN apt-get update && apt-get install -y \
curl \
hwloc \
s3fs \
udev \
# Cleanup
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*
# Install ROS2 dependencies
ARG ROS_DISTRO
RUN apt-get update && apt-get install -y \
software-properties-common \
&& add-apt-repository -y universe \
&& curl -sSL "https://raw.githubusercontent.com/ros/rosdistro/master/ros.key" -o "/usr/share/keyrings/ros-archive-keyring.gpg" \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" >"/etc/apt/sources.list.d/ros2.list" \
&& apt-get update && apt-get install -y \
"ros-${ROS_DISTRO}-ros-base" \
# Cleanup
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*
# Install python dependencies
ADD ./requirements.txt /requirements.txt
RUN true \
# Include target-dependent packages
&& sed -i 's/^\( *\)\(.*\# *include *( *[_0-9a-z-]\+ *)\)$/\1# \2/g' /requirements.txt \
&& sed -i "s/^\( *\)\# *\(.*\# *include *( *$(uname -m) *)\)$/\1\2/g" /requirements.txt \
# Install python dependencies
&& python3 -m pip install --no-cache-dir --requirement /requirements.txt \
# Cleanup
&& find /usr -type d -name '*__pycache__' -prune -exec rm -rf {} \; \
&& rm /requirements.txt \
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*
# Be ready for building
FROM server AS builder
# Install dependencies
ENV CARGO_HOME="/opt/cargo"
ENV RUSTUP_HOME="/opt/rustup"
RUN apt-get update && apt-get install -y \
build-essential \
clang \
cmake \
libclang-dev \
libhwloc-dev \
libprotobuf-dev \
libprotoc-dev \
libssl-dev \
libudev-dev \
llvm-dev \
mold \
nasm \
protobuf-compiler \
ros-dev-tools \
s3fs \
# Install rustup
&& curl 'https://sh.rustup.rs' -sSf | sh -s -- -y \
# Cleanup
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*
# Load source files
ADD . /src
WORKDIR /src
# Build it!
ARG FUNCTION_HOME
ARG ROS_DISTRO
ENV RUST_MIN_STACK=2097152
RUN \
# Cache build outputs
--mount=type=cache,target=/src/target \
--mount=type=cache,target=/usr/local/cargo/registry \
# Create output directories
mkdir -p /out/bin /out/lib \
# Setup ROS2 development environment
&& source "/opt/ros/${ROS_DISTRO}/setup.sh" \
# Include target-dependent packages
&& find ./ -type f -name Cargo.toml -exec sed -i 's/^\( *\)\(.*\# *include *( *[_0-9a-z-]\+ *)\)$/\1# \2/g' {} + \
&& find ./ -type f -name Cargo.toml -exec sed -i "s/^\( *\)\# *\(.*\# *include *( *$(uname -m) *)\)$/\1\2/g" {} + \
# Build
&& "${CARGO_HOME}/bin/rustup" default stable \
&& "${CARGO_HOME}/bin/cargo" build --all --workspace --release \
&& find ./target/release/ -maxdepth 1 -type f -perm -a=x -print0 | xargs -0 -I {} mv {} /out/bin \
&& mv ./LICENSE /LICENSE \
# Copy or-tools lib
&& find ./target/release/ -name 'libortools*.so*' -type f -print0 | xargs -0 -I {} mv {} /out/lib \
&& find ./target/release/ -name 'libortools*.so*' -type l -print0 | xargs -0 -I {} mv {} /out/lib \
# Copy pipe functions
&& mkdir -p "${FUNCTION_HOME}" \
&& mv ./crates/dash/pipe/functions/python/examples "${FUNCTION_HOME}/python"
# Copy executable files
FROM server
ARG FUNCTION_HOME
ARG PACKAGE
COPY --from=builder "${FUNCTION_HOME}" "${FUNCTION_HOME}"
COPY --from=builder /out/bin/* /usr/local/bin/
COPY --from=builder /out/lib/* /usr/local/lib/
COPY --from=builder /LICENSE /usr/share/licenses/${PACKAGE}/LICENSE
# Link 3rd-party binary
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib:/usr/local/lib64"
RUN true \
# Common
&& echo '/usr/local/lib' >/etc/ld.so.conf.d/100-path-local-lib.conf \
&& echo '/usr/local/lib64' >>/etc/ld.so.conf.d/100-path-local-lib.conf \
# CUDA :: NVIDIA
&& for file in /usr/local/lib/python*/dist-packages/nvidia/*/lib/*.so*; do true \
&& ln -sf "${file}" "/usr/local/lib/$(basename "${file}")" \
; done \
# CUDA :: PyTorch
&& for file in /usr/local/lib/python*/dist-packages/torch/lib/*.so*; do true \
&& ln -sf "${file}" "/usr/local/lib/$(basename "${file}")" \
; done \
# Apply
&& ldconfig
# # Link onnxruntime CAPI binary
# RUN ORT_DYLIB_PATH="$(python3 -c 'import inspect,os; import onnxruntime; print(f"{os.path.dirname(inspect.getfile(onnxruntime))}/capi")')" \
# && echo "/usr/local/bin" > "/etc/ld.so.conf.d/onnxruntime-$(arch).conf" \
# && echo "${ORT_DYLIB_PATH}" > "/etc/ld.so.conf.d/onnxruntime-capi-$(arch).conf" \
# && echo "export ORT_DYLIB_PATH=${ORT_DYLIB_PATH}" >> "/etc/environment" \
# && ldconfig