|
| 1 | +FROM ubuntu:24.04 AS builder |
| 2 | + |
| 3 | +ARG DEBIAN_FRONTEND=noninteractive |
| 4 | +ARG BEHAVIORAL_MODEL_VERSION=main |
| 5 | +ARG PI_VERSION=main |
| 6 | +ARG P4C_VERSION=main |
| 7 | + |
| 8 | +# Step 1: Install all build dependencies |
| 9 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 10 | + autoconf automake bison build-essential clang cmake curl flex g++ git \ |
| 11 | + libboost-dev libboost-filesystem-dev libboost-graph-dev \ |
| 12 | + libboost-iostreams-dev libboost-program-options-dev libboost-system-dev \ |
| 13 | + libboost-test-dev libboost-thread-dev libbz2-dev libevent-dev libffi-dev \ |
| 14 | + libfl-dev libgc-dev libgflags-dev libgmp-dev libgrpc++-dev libgrpc-dev \ |
| 15 | + libelf-dev liblzma-dev libpcap-dev libprotobuf-dev libreadline-dev \ |
| 16 | + libssl-dev libtool libtool-bin llvm make net-tools patchelf pkg-config \ |
| 17 | + protobuf-compiler protobuf-compiler-grpc python3-dev python3-pip \ |
| 18 | + python3-venv tcpdump unzip valgrind wget \ |
| 19 | + && rm -rf /var/lib/apt/lists/* |
| 20 | + |
| 21 | +WORKDIR /build |
| 22 | + |
| 23 | +# Step 2: Build Thrift 0.16.0 |
| 24 | +RUN git clone --depth 1 --branch v0.16.0 https://github.com/apache/thrift.git thrift-0.16.0 \ |
| 25 | + && cd thrift-0.16.0 \ |
| 26 | + && ./bootstrap.sh \ |
| 27 | + && ./configure --with-cpp --with-python --without-java --without-ruby \ |
| 28 | + --without-nodejs --without-go --without-erlang --without-lua \ |
| 29 | + --without-php --without-swift --without-rs --without-dotnetcore \ |
| 30 | + --without-haskell --without-perl --without-c_glib --without-d \ |
| 31 | + --without-qt5 \ |
| 32 | + && make -j$(nproc) \ |
| 33 | + && make install \ |
| 34 | + && cd /build && rm -rf thrift-0.16.0 |
| 35 | + |
| 36 | +# Step 3: Build nanomsg 1.0.0 |
| 37 | +RUN git clone --depth 1 --branch 1.0.0 https://github.com/nanomsg/nanomsg.git nanomsg-1.0.0 \ |
| 38 | + && cd nanomsg-1.0.0 \ |
| 39 | + && mkdir build && cd build \ |
| 40 | + && cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \ |
| 41 | + && make -j$(nproc) \ |
| 42 | + && make install \ |
| 43 | + && cd /build && rm -rf nanomsg-1.0.0 |
| 44 | + |
| 45 | +RUN ldconfig |
| 46 | + |
| 47 | +# Step 5: Build PI |
| 48 | +RUN git clone https://github.com/p4lang/PI.git \ |
| 49 | + && cd PI \ |
| 50 | + && if [ "$PI_VERSION" != "main" ]; then git checkout $PI_VERSION; fi \ |
| 51 | + && git submodule update --init --recursive \ |
| 52 | + && ./autogen.sh \ |
| 53 | + && ./configure --with-proto --without-internal-rpc --without-cli --without-bmv2 \ |
| 54 | + && make -j$(nproc) \ |
| 55 | + && make install \ |
| 56 | + && cd /build && rm -rf PI |
| 57 | + |
| 58 | +RUN ldconfig |
| 59 | + |
| 60 | +# Step 6: Build behavioral-model |
| 61 | +# Patches are from vm-ubuntu-24.04/patches/ in the tutorials repo. |
| 62 | +# Build context must be set to the tutorials/ root: |
| 63 | +# docker build -f bindist/Dockerfile -t p4-bindist . |
| 64 | +COPY vm-ubuntu-24.04/patches/behavioral-model-support-fedora.patch /build/patches/ |
| 65 | +COPY vm-ubuntu-24.04/patches/behavioral-model-support-venv.patch /build/patches/ |
| 66 | +RUN git clone https://github.com/p4lang/behavioral-model.git \ |
| 67 | + && cd behavioral-model \ |
| 68 | + && if [ "$BEHAVIORAL_MODEL_VERSION" != "main" ]; then git checkout $BEHAVIORAL_MODEL_VERSION; fi \ |
| 69 | + && git submodule update --init --recursive \ |
| 70 | + && patch -p1 < /build/patches/behavioral-model-support-fedora.patch \ |
| 71 | + && patch -p1 < /build/patches/behavioral-model-support-venv.patch \ |
| 72 | + && ./autogen.sh \ |
| 73 | + && ./configure --with-pi --with-thrift --enable-debugger \ |
| 74 | + && make -j$(nproc) \ |
| 75 | + && make install-strip \ |
| 76 | + && cd /build && rm -rf behavioral-model |
| 77 | + |
| 78 | +RUN ldconfig |
| 79 | + |
| 80 | +# Step 7: Build p4c with static linking |
| 81 | +RUN git clone --recurse-submodules https://github.com/p4lang/p4c.git \ |
| 82 | + && cd p4c \ |
| 83 | + && if [ "$P4C_VERSION" != "main" ]; then git checkout $P4C_VERSION && git submodule update --init --recursive; fi \ |
| 84 | + && mkdir build && cd build \ |
| 85 | + && cmake .. \ |
| 86 | + -DCMAKE_BUILD_TYPE=Release \ |
| 87 | + -DSTATIC_BUILD_WITH_DYNAMIC_GLIBC=ON \ |
| 88 | + -DENABLE_TEST_TOOLS=OFF \ |
| 89 | + -DCMAKE_INSTALL_PREFIX=/usr/local \ |
| 90 | + && make -j$(nproc) \ |
| 91 | + && make install \ |
| 92 | + && cd /build && rm -rf p4c |
| 93 | + |
| 94 | +# Step 8: Collect artifacts into bindist |
| 95 | +RUN mkdir -p /build/bindist/p4-bindist-ubuntu2404-x86_64/{bin,lib,share} |
| 96 | + |
| 97 | +# Copy p4c binaries |
| 98 | +RUN for bin in p4c p4c-bm2-ss p4c-bm2-psa p4c-bm2-pna p4c-dpdk p4c-ebpf \ |
| 99 | + p4c-ubpf p4c-pna-p4tc p4c-graphs p4test; do \ |
| 100 | + cp /usr/local/bin/$bin /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/ 2>/dev/null || true; \ |
| 101 | + done |
| 102 | + |
| 103 | +# Copy behavioral-model binaries |
| 104 | +RUN cp /usr/local/bin/simple_switch /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/ \ |
| 105 | + && cp /usr/local/bin/simple_switch_grpc /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/ \ |
| 106 | + && cp /usr/local/bin/simple_switch_CLI /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/ |
| 107 | + |
| 108 | +# Copy bundled shared libraries (not available via apt on Ubuntu 24.04) |
| 109 | +RUN cp -a /usr/local/lib/libthrift*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \ |
| 110 | + && cp -a /usr/local/lib/libnanomsg*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \ |
| 111 | + && cp -a /usr/local/lib/libpi*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \ |
| 112 | + && cp -a /usr/local/lib/libbm*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \ |
| 113 | + && cp -a /usr/local/lib/libsimpleswitch*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ \ |
| 114 | + && cp -a /usr/local/lib/libruntimestubs*.so* /build/bindist/p4-bindist-ubuntu2404-x86_64/lib/ |
| 115 | + |
| 116 | +# Copy p4c share files |
| 117 | +RUN cp -r /usr/local/share/p4c /build/bindist/p4-bindist-ubuntu2404-x86_64/share/ |
| 118 | + |
| 119 | +# Fix RPATHs on behavioral-model binaries |
| 120 | +RUN for bin in simple_switch simple_switch_grpc; do \ |
| 121 | + patchelf --set-rpath '$ORIGIN/../lib' /build/bindist/p4-bindist-ubuntu2404-x86_64/bin/$bin; \ |
| 122 | + done |
| 123 | + |
| 124 | +# Copy install script |
| 125 | +COPY bindist/install.sh /build/bindist/p4-bindist-ubuntu2404-x86_64/install.sh |
| 126 | +RUN chmod +x /build/bindist/p4-bindist-ubuntu2404-x86_64/install.sh |
| 127 | + |
| 128 | +# Create the tarball |
| 129 | +RUN cd /build/bindist \ |
| 130 | + && tar czf p4-bindist-ubuntu2404-x86_64.tar.gz p4-bindist-ubuntu2404-x86_64/ |
| 131 | + |
| 132 | +# Final stage: just the tarball |
| 133 | +FROM scratch |
| 134 | +COPY --from=builder /build/bindist/p4-bindist-ubuntu2404-x86_64.tar.gz / |
0 commit comments