Skip to content

Commit

Permalink
Fix up cert bins docker script. (#23874)
Browse files Browse the repository at this point in the history
* Run cert bins compilation as a single run to preserve build environment

* Need to also checkout submodules for builds to work

* Update to the SHA inside #23869

* Re-create the npm CI logic since the repo SHA is pinned in certbins

* make checkout and bootstrap separate layers, so they can be re-run separately. Checkout and bootstrap is slow.

* update shell to bash to allow for source usage

* Correct naming: in the image version I have, name of the app is without minimal

* Remove minimal all clusters app build because build-examples script is buggy in the given version

* Replace tabs with spaces

* Install zap to make sure builds work
  • Loading branch information
andy31415 authored Dec 2, 2022
1 parent 46b2114 commit a307034
Showing 1 changed file with 101 additions and 86 deletions.
187 changes: 101 additions & 86 deletions integrations/docker/images/chip-cert-bins/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
FROM ubuntu:22.04 as chip-build-cert
ARG TARGETPLATFORM
# COMMITHASH defines the target commit to build from. May be passed in using --build-arg.
ARG COMMITHASH=e556daac2e1ed3a141034a6dcc7e410e4cd1f8f6
ARG COMMITHASH=21245f42393e63dbb16fb4d99d8bf96aef7ae0fc

# Ensure TARGETPLATFORM is set
RUN case ${TARGETPLATFORM} in \
"linux/amd64") \
echo "Building for linux/amd64" \
;; \
;; \
"linux/arm64") \
echo "Building for linux/arm64" \
;; \
;; \
*) \
if [ -z "$TARGETPLATFORM" ] ;\
then \
echo "TARGETPLATFORM not defined! Please run from buildkit (buildx)." \
&& return 1 ;\
else \
echo "Unsupported platform ${TARGETPLATFORM}." \
&& return 1 ;\
fi \
;; \
if [ -z "$TARGETPLATFORM" ] ;\
then \
echo "TARGETPLATFORM not defined! Please run from buildkit (buildx)." \
&& return 1 ;\
else \
echo "Unsupported platform ${TARGETPLATFORM}." \
&& return 1 ;\
fi \
;; \
esac

# Below should be the same as chip-build except arm64 logic for cmake and node.
Expand Down Expand Up @@ -108,9 +108,9 @@ RUN case ${TARGETPLATFORM} in \
&& exec bash \
;; \
*) \
test -n "$TARGETPLATFORM" \
echo "Unsupported platform ${TARGETPLATFORM}" \
;; \
test -n "$TARGETPLATFORM" \
echo "Unsupported platform ${TARGETPLATFORM}" \
;; \
esac

# Python 3 and PIP
Expand Down Expand Up @@ -156,28 +156,28 @@ RUN set -x \
RUN case ${TARGETPLATFORM} in \
"linux/amd64") \
set -x \
&& mkdir node_js \
&& cd node_js \
&& wget https://nodejs.org/dist/v12.19.0/node-v12.19.0-linux-x64.tar.xz \
&& tar xfvJ node-v12.19.0-linux-x64.tar.xz \
&& mv node-v12.19.0-linux-x64 /opt/ \
&& ln -s /opt/node-v12.19.0-linux-x64 /opt/node \
&& ln -s /opt/node/bin/* /usr/bin \
&& cd .. \
&& rm -rf node_js \
;; \
&& mkdir node_js \
&& cd node_js \
&& wget https://nodejs.org/dist/v12.19.0/node-v12.19.0-linux-x64.tar.xz \
&& tar xfvJ node-v12.19.0-linux-x64.tar.xz \
&& mv node-v12.19.0-linux-x64 /opt/ \
&& ln -s /opt/node-v12.19.0-linux-x64 /opt/node \
&& ln -s /opt/node/bin/* /usr/bin \
&& cd .. \
&& rm -rf node_js \
;; \
"linux/arm64")\
set -x \
&& mkdir node_js \
&& cd node_js \
&& wget https://nodejs.org/dist/v12.19.0/node-v12.19.0-linux-arm64.tar.xz \
&& tar xfvJ node-v12.19.0-linux-arm64.tar.xz \
&& mv node-v12.19.0-linux-arm64 /opt/ \
&& ln -s /opt/node-v12.19.0-linux-arm64 /opt/node \
&& ln -s /opt/node/bin/* /usr/bin \
&& cd .. \
&& rm -rf node_js \
;; \
&& mkdir node_js \
&& cd node_js \
&& wget https://nodejs.org/dist/v12.19.0/node-v12.19.0-linux-arm64.tar.xz \
&& tar xfvJ node-v12.19.0-linux-arm64.tar.xz \
&& mv node-v12.19.0-linux-arm64 /opt/ \
&& ln -s /opt/node-v12.19.0-linux-arm64 /opt/node \
&& ln -s /opt/node/bin/* /usr/bin \
&& cd .. \
&& rm -rf node_js \
;; \
*) ;; \
esac

Expand All @@ -186,71 +186,87 @@ RUN mkdir /root/connectedhomeip
RUN git clone https://github.com/project-chip/connectedhomeip.git /root/connectedhomeip
WORKDIR /root/connectedhomeip/
RUN git checkout ${COMMITHASH}
RUN ./scripts/checkout_submodules.py --shallow --platform linux
RUN scripts/build/gn_bootstrap.sh
RUN gn gen out/debug --args='chip_mdns="platform" chip_inet_config_enable_ipv4=false'
RUN ninja -C out/debug
SHELL ["/bin/bash", "-c"]
RUN set -x && \
source scripts/activate.sh \
&& gn gen out/debug --args='chip_mdns="platform" chip_inet_config_enable_ipv4=false' \
&& ninja -C out/debug

# Stage 2: Build.
from chip-build-cert as chip-build-cert-bins
SHELL ["/bin/bash", "-c"]
# Records Matter SDK commit hash to include in the image.
RUN git rev-parse HEAD > /root/.sdk-sha-version

# TODO: below the build of linux-arm64-all-clusters-minimal-ipv6only/linux-x64-all-clusters-minimal-ipv6only
# is NOT performed because the given SHA does not build minimal and
# builds the regular all-clusters app instead.
RUN case ${TARGETPLATFORM} in \
"linux/amd64") \
set -x \
&& source scripts/activate.sh \
&& scripts/build/build_examples.py \
--target linux-x64-all-clusters-ipv6only \
--target linux-x64-all-clusters-minimal-ipv6only \
--target linux-x64-bridge-ipv6only \
--target linux-x64-tv-app-ipv6only \
--target linux-x64-tv-casting-app-ipv6only \
--target linux-x64-light-ipv6only \
--target linux-x64-thermostat-ipv6only \
--target linux-x64-ota-provider-ipv6only \
--target linux-x64-ota-requestor-ipv6only \
--target linux-x64-lock-ipv6only \
build \
&& mv out/linux-x64-all-clusters-ipv6only/chip-all-clusters-app out/chip-all-clusters-app \
&& mv out/linux-x64-all-clusters-minimal-ipv6only/chip-all-clusters-minimal-app out/chip-all-clusters-minimal-app \
&& mv out/linux-x64-bridge-ipv6only/chip-bridge-app out/chip-bridge-app \
&& mv out/linux-x64-tv-app-ipv6only/chip-tv-app out/chip-tv-app \
&& mv out/linux-x64-tv-casting-app-ipv6only/chip-tv-casting-app out/chip-tv-casting-app \
&& mv out/linux-x64-light-ipv6only/chip-lighting-app out/chip-lighting-app \
&& mv out/linux-x64-thermostat-ipv6only/thermostat-app out/thermostat-app \
&& mv out/linux-x64-ota-provider-ipv6only/chip-ota-provider-app out/chip-ota-provider-app \
&& mv out/linux-x64-ota-requestor-ipv6only/chip-ota-requestor-app out/chip-ota-requestor-app \
&& mv out/linux-x64-lock-ipv6only/chip-lock-app out/chip-lock-app \
;; \
&& source scripts/activate.sh \
&& scripts/build/build_examples.py \
--target linux-x64-all-clusters-ipv6only \
--target linux-x64-bridge-ipv6only \
--target linux-x64-tv-app-ipv6only \
--target linux-x64-tv-casting-app-ipv6only \
--target linux-x64-light-ipv6only \
--target linux-x64-thermostat-ipv6only \
--target linux-x64-ota-provider-ipv6only \
--target linux-x64-ota-requestor-ipv6only \
--target linux-x64-lock-ipv6only \
build \
&& mv out/linux-x64-all-clusters-ipv6only/chip-all-clusters-app out/chip-all-clusters-app \
&& mv out/linux-x64-bridge-ipv6only/chip-bridge-app out/chip-bridge-app \
&& mv out/linux-x64-tv-app-ipv6only/chip-tv-app out/chip-tv-app \
&& mv out/linux-x64-tv-casting-app-ipv6only/chip-tv-casting-app out/chip-tv-casting-app \
&& mv out/linux-x64-light-ipv6only/chip-lighting-app out/chip-lighting-app \
&& mv out/linux-x64-thermostat-ipv6only/thermostat-app out/thermostat-app \
&& mv out/linux-x64-ota-provider-ipv6only/chip-ota-provider-app out/chip-ota-provider-app \
&& mv out/linux-x64-ota-requestor-ipv6only/chip-ota-requestor-app out/chip-ota-requestor-app \
&& mv out/linux-x64-lock-ipv6only/chip-lock-app out/chip-lock-app \
;; \
"linux/arm64")\
set -x \
&& source scripts/activate.sh \
&& scripts/build/build_examples.py \
--target linux-arm64-all-clusters-ipv6only \
--target linux-arm64-all-clusters-minimal-ipv6only \
--target linux-arm64-bridge-ipv6only \
--target linux-arm64-tv-app-ipv6only \
--target linux-arm64-tv-casting-app-ipv6only \
--target linux-arm64-light-ipv6only \
--target linux-arm64-thermostat-ipv6only \
--target linux-arm64-ota-provider-ipv6only \
--target linux-arm64-ota-requestor-ipv6only \
--target linux-arm64-lock-ipv6only \
build \
&& mv out/linux-arm64-all-clusters-ipv6only/chip-all-clusters-app out/chip-all-clusters-app \
&& mv out/linux-arm64-all-clusters-minimal-ipv6only/chip-all-clusters-minimal-app out/chip-all-clusters-minimal-app \
&& mv out/linux-arm64-bridge-ipv6only/chip-bridge-app out/chip-bridge-app \
&& mv out/linux-arm64-tv-app-ipv6only/chip-tv-app out/chip-tv-app \
&& mv out/linux-arm64-tv-casting-app-ipv6only/chip-tv-casting-app out/chip-tv-casting-app \
&& mv out/linux-arm64-light-ipv6only/chip-lighting-app out/chip-lighting-app \
&& mv out/linux-arm64-thermostat-ipv6only/thermostat-app out/thermostat-app \
&& mv out/linux-arm64-ota-provider-ipv6only/chip-ota-provider-app out/chip-ota-provider-app \
&& mv out/linux-arm64-ota-requestor-ipv6only/chip-ota-requestor-app out/chip-ota-requestor-app \
&& mv out/linux-arm64-lock-ipv6only/chip-lock-app out/chip-lock-app \
;; \
&& source scripts/activate.sh \
&& scripts/build/build_examples.py \
--target linux-arm64-all-clusters-ipv6only \
--target linux-arm64-bridge-ipv6only \
--target linux-arm64-tv-app-ipv6only \
--target linux-arm64-tv-casting-app-ipv6only \
--target linux-arm64-light-ipv6only \
--target linux-arm64-thermostat-ipv6only \
--target linux-arm64-ota-provider-ipv6only \
--target linux-arm64-ota-requestor-ipv6only \
--target linux-arm64-lock-ipv6only \
build \
&& mv out/linux-arm64-all-clusters-ipv6only/chip-all-clusters-app out/chip-all-clusters-app \
&& mv out/linux-arm64-bridge-ipv6only/chip-bridge-app out/chip-bridge-app \
&& mv out/linux-arm64-tv-app-ipv6only/chip-tv-app out/chip-tv-app \
&& mv out/linux-arm64-tv-casting-app-ipv6only/chip-tv-casting-app out/chip-tv-casting-app \
&& mv out/linux-arm64-light-ipv6only/chip-lighting-app out/chip-lighting-app \
&& mv out/linux-arm64-thermostat-ipv6only/thermostat-app out/thermostat-app \
&& mv out/linux-arm64-ota-provider-ipv6only/chip-ota-provider-app out/chip-ota-provider-app \
&& mv out/linux-arm64-ota-requestor-ipv6only/chip-ota-requestor-app out/chip-ota-requestor-app \
&& mv out/linux-arm64-lock-ipv6only/chip-lock-app out/chip-lock-app \
;; \
*) ;; \
esac

# Install a known ZAP release
# Only keep the cli version, since `zap` is 143MB and not usable (UI)
ENV ZAP_VERSION=v2022.11.29-nightly
RUN set -x \
&& mkdir -p /opt/zap-${ZAP_VERSION} \
&& cd /opt/zap-${ZAP_VERSION} \
&& wget https://github.com/project-chip/zap/releases/download/${ZAP_VERSION}/zap-linux.zip \
&& unzip zap-linux.zip \
&& rm zap-linux.zip \
&& rm zap \
&& ln -s /opt/zap-${ZAP_VERSION}/zap-cli /usr/bin/ \
&& : # last line
RUN scripts/examples/gn_build_test_example.sh app1

RUN source scripts/activate.sh && scripts/build_python.sh -m platform -d true -i no
Expand All @@ -267,7 +283,6 @@ COPY --from=chip-build-cert-bins /root/connectedhomeip/out/debug/chip-tool chip-
COPY --from=chip-build-cert-bins /root/connectedhomeip/out/debug/chip-shell chip-shell
COPY --from=chip-build-cert-bins /root/connectedhomeip/out/debug/chip-cert chip-cert
COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-all-clusters-app chip-all-clusters-app
COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-all-clusters-minimal-app chip-all-clusters-minimal-app
COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-lighting-app chip-lighting-app
COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-tv-casting-app chip-tv-casting-app
COPY --from=chip-build-cert-bins /root/connectedhomeip/out/chip-tv-app chip-tv-app
Expand Down

0 comments on commit a307034

Please sign in to comment.