|
| 1 | +# Stage 1: Setup dependencies (based on chip-build). |
| 2 | +FROM ubuntu:22.04 as chip-build-cert |
| 3 | +ARG TARGETPLATFORM |
| 4 | +# COMMITHASH defines the target commit to build from. May be passed in using --build-arg. |
| 5 | +ARG COMMITHASH=e556daac2e1ed3a141034a6dcc7e410e4cd1f8f6 |
| 6 | + |
| 7 | +# Ensure TARGETPLATFORM is set |
| 8 | +RUN case ${TARGETPLATFORM} in \ |
| 9 | + "linux/amd64") \ |
| 10 | + echo "Building for linux/amd64" \ |
| 11 | + ;; \ |
| 12 | + "linux/arm64") \ |
| 13 | + echo "Building for linux/arm64" \ |
| 14 | + ;; \ |
| 15 | + *) \ |
| 16 | + if [ -z "$TARGETPLATFORM" ] ;\ |
| 17 | + then \ |
| 18 | + echo "TARGETPLATFORM not defined! Please run from buildkit (buildx)." \ |
| 19 | + && return 1 ;\ |
| 20 | + else \ |
| 21 | + echo "Unsupported platform ${TARGETPLATFORM}." \ |
| 22 | + && return 1 ;\ |
| 23 | + fi \ |
| 24 | + ;; \ |
| 25 | + esac |
| 26 | + |
| 27 | +# Below should be the same as chip-build except arm64 logic for cmake and node. |
| 28 | + |
| 29 | +# base build and check tools and libraries layer |
| 30 | +RUN set -x \ |
| 31 | + && apt-get update \ |
| 32 | + && DEBIAN_FRONTEND=noninteractive apt-get install -fy \ |
| 33 | + autoconf \ |
| 34 | + automake \ |
| 35 | + bison \ |
| 36 | + bridge-utils \ |
| 37 | + clang \ |
| 38 | + clang-format \ |
| 39 | + clang-tidy \ |
| 40 | + curl \ |
| 41 | + flex \ |
| 42 | + g++ \ |
| 43 | + git \ |
| 44 | + gperf \ |
| 45 | + iproute2 \ |
| 46 | + jq \ |
| 47 | + lcov \ |
| 48 | + libavahi-client-dev \ |
| 49 | + libavahi-common-dev \ |
| 50 | + libcairo2-dev \ |
| 51 | + libdbus-1-dev \ |
| 52 | + libdbus-glib-1-dev \ |
| 53 | + libgif-dev \ |
| 54 | + libglib2.0-dev \ |
| 55 | + libical-dev \ |
| 56 | + libjpeg-dev \ |
| 57 | + libdmalloc-dev \ |
| 58 | + libmbedtls-dev \ |
| 59 | + libncurses5-dev \ |
| 60 | + libncursesw5-dev \ |
| 61 | + libnspr4-dev \ |
| 62 | + libpango1.0-dev \ |
| 63 | + libpixman-1-dev \ |
| 64 | + libreadline-dev \ |
| 65 | + libssl-dev \ |
| 66 | + libtool \ |
| 67 | + libudev-dev \ |
| 68 | + libusb-1.0-0 \ |
| 69 | + libusb-dev \ |
| 70 | + libxml2-dev \ |
| 71 | + make \ |
| 72 | + net-tools \ |
| 73 | + ninja-build \ |
| 74 | + openjdk-8-jdk \ |
| 75 | + pkg-config \ |
| 76 | + python3 \ |
| 77 | + python3-dev \ |
| 78 | + python3-venv \ |
| 79 | + rsync \ |
| 80 | + shellcheck \ |
| 81 | + strace \ |
| 82 | + systemd \ |
| 83 | + udev \ |
| 84 | + unzip \ |
| 85 | + wget \ |
| 86 | + git-lfs \ |
| 87 | + zlib1g-dev \ |
| 88 | + && rm -rf /var/lib/apt/lists/ \ |
| 89 | + && git lfs install \ |
| 90 | + && : # last line |
| 91 | + |
| 92 | +# Cmake (Mbed OS requires >=3.19.0-rc3 version which is not available in Ubuntu 20.04 repository) |
| 93 | +RUN case ${TARGETPLATFORM} in \ |
| 94 | + "linux/amd64") \ |
| 95 | + set -x \ |
| 96 | + && (cd /tmp \ |
| 97 | + && wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.19.3/cmake-3.19.3-Linux-x86_64.sh \ |
| 98 | + && sh cmake-3.19.3-Linux-x86_64.sh --exclude-subdir --prefix=/usr/local \ |
| 99 | + && rm -rf cmake-3.19.3-Linux-x86_64.sh) \ |
| 100 | + && exec bash \ |
| 101 | + ;; \ |
| 102 | + "linux/arm64") \ |
| 103 | + set -x \ |
| 104 | + && (cd /tmp \ |
| 105 | + && wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.19.3/cmake-3.19.3-Linux-aarch64.sh \ |
| 106 | + && sh cmake-3.19.3-Linux-aarch64.sh --exclude-subdir --prefix=/usr/local \ |
| 107 | + && rm -rf cmake-3.19.3-Linux-aarch64.sh) \ |
| 108 | + && exec bash \ |
| 109 | + ;; \ |
| 110 | + *) \ |
| 111 | + test -n "$TARGETPLATFORM" \ |
| 112 | + echo "Unsupported platform ${TARGETPLATFORM}" \ |
| 113 | + ;; \ |
| 114 | + esac |
| 115 | + |
| 116 | +# Python 3 and PIP |
| 117 | +RUN set -x \ |
| 118 | + && DEBIAN_FRONTEND=noninteractive apt-get update \ |
| 119 | + && DEBIAN_FRONTEND=noninteractive apt-get install -y libgirepository1.0-dev \ |
| 120 | + && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common \ |
| 121 | + && add-apt-repository universe \ |
| 122 | + && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ |
| 123 | + && python3 get-pip.py \ |
| 124 | + && rm -rf /var/lib/apt/lists/ \ |
| 125 | + && : # last line |
| 126 | + |
| 127 | +RUN set -x \ |
| 128 | + && pip3 install attrs coloredlogs PyGithub pygit future portpicker mobly click cxxfilt ghapi pandas tabulate \ |
| 129 | + && : # last line |
| 130 | + |
| 131 | +# build and install gn |
| 132 | +RUN set -x \ |
| 133 | + && git clone https://gn.googlesource.com/gn \ |
| 134 | + && cd gn \ |
| 135 | + && python3 build/gen.py \ |
| 136 | + && ninja -C out \ |
| 137 | + && cp out/gn /usr/local/bin \ |
| 138 | + && cd .. \ |
| 139 | + && rm -rf gn \ |
| 140 | + && : # last line |
| 141 | + |
| 142 | +# Install bloat comparison tools |
| 143 | +RUN set -x \ |
| 144 | + && git clone https://github.com/google/bloaty.git \ |
| 145 | + && mkdir -p bloaty/build \ |
| 146 | + && cd bloaty/build \ |
| 147 | + && cmake ../ \ |
| 148 | + && make -j8 \ |
| 149 | + && make install \ |
| 150 | + && cd ../.. \ |
| 151 | + && rm -rf bloaty \ |
| 152 | + && : # last line |
| 153 | + |
| 154 | +# NodeJS: install a newer version than what apt-get would read |
| 155 | +# This installs the latest LTS version of nodejs |
| 156 | +RUN case ${TARGETPLATFORM} in \ |
| 157 | + "linux/amd64") \ |
| 158 | + set -x \ |
| 159 | + && mkdir node_js \ |
| 160 | + && cd node_js \ |
| 161 | + && wget https://nodejs.org/dist/v12.19.0/node-v12.19.0-linux-x64.tar.xz \ |
| 162 | + && tar xfvJ node-v12.19.0-linux-x64.tar.xz \ |
| 163 | + && mv node-v12.19.0-linux-x64 /opt/ \ |
| 164 | + && ln -s /opt/node-v12.19.0-linux-x64 /opt/node \ |
| 165 | + && ln -s /opt/node/bin/* /usr/bin \ |
| 166 | + && cd .. \ |
| 167 | + && rm -rf node_js \ |
| 168 | + ;; \ |
| 169 | + "linux/arm64")\ |
| 170 | + set -x \ |
| 171 | + && mkdir node_js \ |
| 172 | + && cd node_js \ |
| 173 | + && wget https://nodejs.org/dist/v12.19.0/node-v12.19.0-linux-arm64.tar.xz \ |
| 174 | + && tar xfvJ node-v12.19.0-linux-arm64.tar.xz \ |
| 175 | + && mv node-v12.19.0-linux-arm64 /opt/ \ |
| 176 | + && ln -s /opt/node-v12.19.0-linux-arm64 /opt/node \ |
| 177 | + && ln -s /opt/node/bin/* /usr/bin \ |
| 178 | + && cd .. \ |
| 179 | + && rm -rf node_js \ |
| 180 | + ;; \ |
| 181 | + *) ;; \ |
| 182 | + esac |
| 183 | + |
| 184 | +# Stage 1.5: Bootstrap Matter. |
| 185 | +RUN mkdir /root/connectedhomeip |
| 186 | +RUN git clone https://github.com/project-chip/connectedhomeip.git /root/connectedhomeip |
| 187 | +WORKDIR /root/connectedhomeip/ |
| 188 | +RUN git checkout ${COMMITHASH} |
| 189 | +RUN scripts/build/gn_bootstrap.sh |
| 190 | +RUN gn gen out/debug --args='chip_mdns="platform" chip_inet_config_enable_ipv4=false' |
| 191 | +RUN ninja -C out/debug |
| 192 | + |
| 193 | +# Stage 2: Build. |
| 194 | +from chip-build-cert as chip-build-cert-bins |
| 195 | +SHELL ["/bin/bash", "-c"] |
| 196 | +# Records Matter SDK commit hash to include in the image. |
| 197 | +RUN git rev-parse HEAD > /root/.sdk-sha-version |
| 198 | +RUN case ${TARGETPLATFORM} in \ |
| 199 | + "linux/amd64") \ |
| 200 | + set -x \ |
| 201 | + && source scripts/activate.sh \ |
| 202 | + && scripts/build/build_examples.py \ |
| 203 | + --target linux-x64-all-clusters-ipv6only \ |
| 204 | + --target linux-x64-all-clusters-minimal-ipv6only \ |
| 205 | + --target linux-x64-bridge-ipv6only \ |
| 206 | + --target linux-x64-tv-app-ipv6only \ |
| 207 | + --target linux-x64-tv-casting-app-ipv6only \ |
| 208 | + --target linux-x64-light-ipv6only \ |
| 209 | + --target linux-x64-thermostat-ipv6only \ |
| 210 | + --target linux-x64-ota-provider-ipv6only \ |
| 211 | + --target linux-x64-ota-requestor-ipv6only \ |
| 212 | + --target linux-x64-lock-ipv6only \ |
| 213 | + build \ |
| 214 | + && mv out/linux-x64-all-clusters-ipv6only/chip-all-clusters-app out/chip-all-clusters-app \ |
| 215 | + && mv out/linux-x64-all-clusters-minimal-ipv6only/chip-all-clusters-minimal-app out/chip-all-clusters-minimal-app \ |
| 216 | + && mv out/linux-x64-bridge-ipv6only/chip-bridge-app out/chip-bridge-app \ |
| 217 | + && mv out/linux-x64-tv-app-ipv6only/chip-tv-app out/chip-tv-app \ |
| 218 | + && mv out/linux-x64-tv-casting-app-ipv6only/chip-tv-casting-app out/chip-tv-casting-app \ |
| 219 | + && mv out/linux-x64-light-ipv6only/chip-lighting-app out/chip-lighting-app \ |
| 220 | + && mv out/linux-x64-thermostat-ipv6only/thermostat-app out/thermostat-app \ |
| 221 | + && mv out/linux-x64-ota-provider-ipv6only/chip-ota-provider-app out/chip-ota-provider-app \ |
| 222 | + && mv out/linux-x64-ota-requestor-ipv6only/chip-ota-requestor-app out/chip-ota-requestor-app \ |
| 223 | + && mv out/linux-x64-lock-ipv6only/chip-lock-app out/chip-lock-app \ |
| 224 | + ;; \ |
| 225 | + "linux/arm64")\ |
| 226 | + set -x \ |
| 227 | + && source scripts/activate.sh \ |
| 228 | + && scripts/build/build_examples.py \ |
| 229 | + --target linux-arm64-all-clusters-ipv6only \ |
| 230 | + --target linux-arm64-all-clusters-minimal-ipv6only \ |
| 231 | + --target linux-arm64-bridge-ipv6only \ |
| 232 | + --target linux-arm64-tv-app-ipv6only \ |
| 233 | + --target linux-arm64-tv-casting-app-ipv6only \ |
| 234 | + --target linux-arm64-light-ipv6only \ |
| 235 | + --target linux-arm64-thermostat-ipv6only \ |
| 236 | + --target linux-arm64-ota-provider-ipv6only \ |
| 237 | + --target linux-arm64-ota-requestor-ipv6only \ |
| 238 | + --target linux-arm64-lock-ipv6only \ |
| 239 | + build \ |
| 240 | + && mv out/linux-arm64-all-clusters-ipv6only/chip-all-clusters-app out/chip-all-clusters-app \ |
| 241 | + && mv out/linux-arm64-all-clusters-minimal-ipv6only/chip-all-clusters-minimal-app out/chip-all-clusters-minimal-app \ |
| 242 | + && mv out/linux-arm64-bridge-ipv6only/chip-bridge-app out/chip-bridge-app \ |
| 243 | + && mv out/linux-arm64-tv-app-ipv6only/chip-tv-app out/chip-tv-app \ |
| 244 | + && mv out/linux-arm64-tv-casting-app-ipv6only/chip-tv-casting-app out/chip-tv-casting-app \ |
| 245 | + && mv out/linux-arm64-light-ipv6only/chip-lighting-app out/chip-lighting-app \ |
| 246 | + && mv out/linux-arm64-thermostat-ipv6only/thermostat-app out/thermostat-app \ |
| 247 | + && mv out/linux-arm64-ota-provider-ipv6only/chip-ota-provider-app out/chip-ota-provider-app \ |
| 248 | + && mv out/linux-arm64-ota-requestor-ipv6only/chip-ota-requestor-app out/chip-ota-requestor-app \ |
| 249 | + && mv out/linux-arm64-lock-ipv6only/chip-lock-app out/chip-lock-app \ |
| 250 | + ;; \ |
| 251 | + *) ;; \ |
| 252 | + esac |
| 253 | + |
| 254 | +RUN npm --prefix third_party/zap/repo/ ci |
| 255 | +RUN scripts/examples/gn_build_test_example.sh app1 |
| 256 | + |
| 257 | +# Stage 3: Copy relevant cert bins to a minimal image to reduce size. |
| 258 | +FROM ubuntu:22.04 |
| 259 | +ENV TZ=Etc/UTC |
| 260 | +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone |
| 261 | +RUN apt-get update -y |
| 262 | +RUN apt-get install -y libssl-dev libdbus-1-dev libglib2.0-dev libavahi-client-dev avahi-utils iproute2 |
| 263 | +WORKDIR /root/ |
| 264 | +COPY --from=chip-build-cert-bins /root/.sdk-sha-version .sdk-sha-version |
| 265 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/debug/chip-tool chip-tool |
| 266 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/debug/chip-shell chip-shell |
| 267 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/debug/chip-cert chip-cert |
| 268 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-all-clusters-app chip-all-clusters-app |
| 269 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-all-clusters-minimal-app chip-all-clusters-minimal-app |
| 270 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-lighting-app chip-lighting-app |
| 271 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-tv-casting-app chip-tv-casting-app |
| 272 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-tv-app chip-tv-app |
| 273 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-bridge-app chip-bridge-app |
| 274 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/thermostat-app thermostat-app |
| 275 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-ota-provider-app chip-ota-provider-app |
| 276 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-ota-requestor-app chip-ota-requestor-app |
| 277 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-lock-app chip-lock-app |
| 278 | +COPY --from=chip-build-cert-bins /root/connectedhomeip/out/app1/chip-app1 chip-app1 |
0 commit comments