-
Notifications
You must be signed in to change notification settings - Fork 811
/
Copy pathdev.Dockerfile
187 lines (115 loc) · 4.75 KB
/
dev.Dockerfile
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# syntax=docker/dockerfile-upstream:master
FROM python:3.10-slim as base
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /workspace
RUN --mount=type=cache,target=/var/lib/apt \
--mount=type=cache,target=/var/cache/apt \
apt-get update && \
apt-get install -q -y --no-install-recommends --allow-remove-essential \
bash build-essential ca-certificates git tree
FROM base as protobuf-3
COPY <<-EOT requirements.txt
protobuf>=3.5.0,<4.0dev
grpcio-tools
mypy-protobuf
EOT
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
FROM base as protobuf-4
COPY <<-EOT requirements.txt
protobuf>=4.0,<5.0dev
grpcio-tools
mypy-protobuf
EOT
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
############################################
# BentoML gRPC protobuf 3 generation
FROM protobuf-3 as run-grpcio-tools-3
ARG PROTOCOL_VERSION
ARG GENERATED_PB3_DIR
RUN mkdir -p /result/${GENERATED_PB3_DIR}
RUN --mount=type=bind,target=.,rw <<EOT
set -ex
mkdir -p ${GENERATED_PB3_DIR}
python -m grpc_tools.protoc \
-Isrc --grpc_python_out=${GENERATED_PB3_DIR} --python_out=${GENERATED_PB3_DIR} \
--mypy_out=${GENERATED_PB3_DIR} --mypy_grpc_out=${GENERATED_PB3_DIR} \
src/bentoml/grpc/${PROTOCOL_VERSION}/service.proto
mv ${GENERATED_PB3_DIR}/bentoml/grpc/${PROTOCOL_VERSION}/* /result/${GENERATED_PB3_DIR}
touch /result/${GENERATED_PB3_DIR}/__init__.py
rm -rf /result/${GENERATED_PB3_DIR}/${PROTOCOL_VERSION}
EOT
FROM scratch as protobuf-3-output
ARG GENERATED_PB3_DIR
COPY --from=run-grpcio-tools-3 /result/${GENERATED_PB3_DIR} /
############################################
# Triton stubs generation
FROM protobuf-3 as generate-triton-stubs
ARG GENERATED_DIR
RUN mkdir -p /result/${GENERATED_DIR}
RUN --mount=type=bind,target=.,rw <<EOT
set -ex
git clone --depth 1 --filter=blob:none --sparse https://github.com/triton-inference-server/common.git
cd common && git sparse-checkout set protobuf
cp protobuf/model_config.proto model_config.proto
cp protobuf/grpc_service.proto service.proto
mkdir -p ${GENERATED_DIR}
python -m grpc_tools.protoc -I. --mypy_out=${GENERATED_DIR} model_config.proto
python -m grpc_tools.protoc -I. --mypy_out=${GENERATED_DIR} --mypy_grpc_out=${GENERATED_DIR} service.proto
tree typings/tritonclient || exit 1
mv typings/tritonclient/grpc/* /result/${GENERATED_DIR}
EOT
FROM scratch as triton-protobuf-output
ARG GENERATED_DIR
COPY --from=generate-triton-stubs /result/${GENERATED_DIR} /
############################################
# Tests protobuf 3 generation
FROM protobuf-3 as generate-tests-proto-3
RUN mkdir -p /result/tests/proto/_generated_pb3
RUN --mount=type=bind,target=.,rw <<EOT
set -ex
mkdir -p tests/proto/_generated_pb3
python -m grpc_tools.protoc \
-I. --grpc_python_out=tests/proto/_generated_pb3 --python_out=tests/proto/_generated_pb3 \
--mypy_out=tests/proto/_generated_pb3 --mypy_grpc_out=tests/proto/_generated_pb3 \
tests/proto/service_test.proto
mv tests/proto/_generated_pb3/tests/proto/* /result/tests/proto/_generated_pb3
touch /result/tests/proto/_generated_pb3/__init__.py
EOT
FROM scratch as generate-tests-proto-3-output
COPY --from=generate-tests-proto-3 /result/* /
############################################
# BentoML gRPC protobuf 4 generation
FROM protobuf-4 as run-grpcio-tools-4
ARG PROTOCOL_VERSION
ARG GENERATED_PB4_DIR
RUN mkdir -p /result/${GENERATED_PB4_DIR}
RUN --mount=type=bind,target=.,rw <<EOT
set -ex
mkdir -p ${GENERATED_PB4_DIR}
python -m grpc_tools.protoc \
-Isrc --grpc_python_out=${GENERATED_PB4_DIR} --python_out=${GENERATED_PB4_DIR} \
--mypy_out=${GENERATED_PB4_DIR} --mypy_grpc_out=${GENERATED_PB4_DIR} \
src/bentoml/grpc/${PROTOCOL_VERSION}/service.proto
mv ${GENERATED_PB4_DIR}/bentoml/grpc/${PROTOCOL_VERSION}/* /result/${GENERATED_PB4_DIR}
touch /result/${GENERATED_PB4_DIR}/__init__.py
rm -rf /result/${GENERATED_PB4_DIR}/${PROTOCOL_VERSION}
EOT
FROM scratch as protobuf-4-output
ARG GENERATED_PB4_DIR
COPY --from=run-grpcio-tools-4 /result/${GENERATED_PB4_DIR} /
############################################
# Tests protobuf 4 generation
FROM protobuf-4 as generate-tests-proto-4
RUN mkdir -p /result/tests/proto/_generated_pb4
RUN --mount=type=bind,target=.,rw <<EOT
set -ex
mkdir -p tests/proto/_generated_pb4
python -m grpc_tools.protoc \
-I. --grpc_python_out=tests/proto/_generated_pb4 --python_out=tests/proto/_generated_pb4 \
--mypy_out=tests/proto/_generated_pb4 --mypy_grpc_out=tests/proto/_generated_pb4 \
tests/proto/service_test.proto
mv tests/proto/_generated_pb4/tests/proto/* /result/tests/proto/_generated_pb4
touch /result/tests/proto/_generated_pb4/__init__.py
EOT
FROM scratch as generate-tests-proto-4-output
COPY --from=generate-tests-proto-4 /result/* /