Commit e70d0bc5 authored by Carlos Natalino's avatar Carlos Natalino
Browse files

Upgrade Device from Python 3.9 to 3.13.

The image now builds on python:3.13-slim with common_requirements_py313.in so grpcio and protobuf match Context and Service. cryptography, paramiko, numpy, and pandas are bumped to 3.13-capable releases, p4runtime stubs are regenerated for protobuf 6, and the Deployment uses native gRPC probes instead of grpc_health_probe.
parent 6c3e4c4c
Loading
Loading
Loading
Loading
+6 −6
Changes for manifests/deviceservice.yaml: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -41,16 +41,16 @@ spec:
            - name: LOG_LEVEL
              value: "INFO"
          startupProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:2020"]
            grpc:
              port: 2020
            failureThreshold: 30
            periodSeconds: 1
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:2020"]
            grpc:
              port: 2020
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:2020"]
            grpc:
              port: 2020
          resources:
            requests:
              cpu: 250m
+31 −6
Changes for src/device/Dockerfile: 31 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.9-slim
FROM python:3.13-slim

# Install dependencies
RUN apt-get --yes --quiet --quiet update && \
@@ -38,9 +38,9 @@ RUN ldconfig
ENV PYTHONUNBUFFERED=0

# Download the gRPC health probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
    wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
    chmod +x /bin/grpc_health_probe
# RUN GRPC_HEALTH_PROBE_VERSION=v0.4.40 && \
#     wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
#     chmod +x /bin/grpc_health_probe

# Get generic Python packages
RUN python3 -m pip install --upgrade 'pip==25.2'
@@ -50,7 +50,7 @@ RUN python3 -m pip install --upgrade 'pip-tools==7.3.0'
# Get common Python packages
# Note: this step enables sharing the previous Docker build steps among all the Python components
WORKDIR /var/teraflow
COPY common_requirements.in common_requirements.in
COPY common_requirements_py313.in common_requirements.in
RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in
RUN python3 -m pip install -r common_requirements.txt

@@ -72,9 +72,34 @@ RUN find . -type f -exec sed -i -E 's/^(import\ .*)_pb2/from . \1_pb2/g' {} \;
RUN mkdir -p /var/teraflow/device
WORKDIR /var/teraflow/device
COPY src/device/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in /var/teraflow/common_requirements.in
RUN python3 -m pip install -r requirements.txt

# p4runtime 1.3.0 ships stubs generated with an old protoc that cannot be
# imported under protobuf 6. Rebuild them with this image's grpc_tools.
RUN git clone --depth 1 --branch v1.3.0 https://github.com/p4lang/p4runtime.git /tmp/p4runtime
RUN python3 - <<'PY'
from pathlib import Path
import sys
import grpc_tools
import p4
from grpc_tools import protoc
site = Path(p4.__file__).resolve().parent.parent
inc = Path(grpc_tools.__file__).resolve().parent / "_proto"
proto = Path("/tmp/p4runtime/proto")
files = [str(p) for p in proto.rglob("*.proto")]
sys.exit(protoc.main([
    "protoc",
    f"-I{proto}",
    f"-I{inc}",
    f"-I{site}",
    f"--python_out={site}",
    f"--grpc_python_out={site}",
    *files,
]))
PY
RUN rm -rf /tmp/p4runtime

# Add component files into working directory
WORKDIR /var/teraflow
COPY src/device/. device/
+9 −7
Changes for src/device/requirements.in: 9 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
anytree==2.8.0
APScheduler>=3.10.4
bitarray==2.8.*
cryptography==36.0.2
cryptography==44.*
deepdiff==6.7.*
deepmerge==1.1.*
#fastcache==1.1.0
@@ -27,10 +27,11 @@ Jinja2==3.0.3
libyang==2.8.4
macaddress
ncclient==0.6.15
numpy<2.0.0
numpy==2.3.*
# stubs are regenerated in the Dockerfile so they import under protobuf 6
p4runtime==1.3.0
pandas==1.5.*
paramiko==2.11.*
pandas==2.3.*
paramiko==3.5.*
pyang==2.6.*
git+https://github.com/robshakir/pyangbind.git
python-json-logger==2.0.2
@@ -39,6 +40,7 @@ python-json-logger==2.0.2
requests==2.27.1
requests-mock==1.9.3
tabulate
typing_extensions
websockets==12.0
werkzeug==2.3.7
xmltodict==0.12.0
@@ -46,6 +48,6 @@ yattag

# pip's dependency resolver does not take into account installed packages.
# p4runtime does not specify the version of grpcio/protobuf it needs, so it tries to install latest one
# adding here again grpcio==1.47.* and protobuf==3.20.* with explicit versions to prevent collisions
grpcio==1.47.*
protobuf==3.20.*
# adding here again grpcio==1.73.* and protobuf==6.32.* with explicit versions to prevent collisions
grpcio==1.73.*
protobuf==6.32.*