Skip to content

Commit

Permalink
Build zap in images from local sources; log SHAs
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Apr 13, 2022
1 parent df733ec commit c2f5f4f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
55 changes: 49 additions & 6 deletions integrations/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ VERSION=${DOCKER_BUILD_VERSION:-$(sed 's/ .*//' version)}
Build and (optionally tag as latest, push) a docker image from Dockerfile in CWD
Options:
--no-cache passed as a docker build argument
--latest update latest to the current built version (\"$VERSION\")
--push push image(s) to docker.io (requires docker login for \"$ORG\")
--help get this message
--squash squash docker layers before push them to docker.io (requires docker-squash python module)
--no-cache passed as a docker build argument
--latest update latest to the current built version (\"$VERSION\")
--push push image(s) to docker.io (requires docker login for \"$ORG\")
--help get this message
--squash squash docker layers before push them to docker.io (requires docker-squash python module)
--zap-path path to a local directory containing zap (root of git repo). Without this option, zap is copied from the working tree.
"
exit 0
}
Expand All @@ -72,9 +72,52 @@ if [[ ${*/--no-cache//} != "${*}" ]]; then
BUILD_ARGS+=(--no-cache)
fi

# Special condition to include zap source in build context
# This copies from the working tree but we should clone @ build time with the hashes here to ensure local changes cannot cause issues
ZAP_INCLUDING_IMAGE='chip-build-zap'
if [[ $IMAGE == $ZAP_INCLUDING_IMAGE ]]; then

WORKING_TREE_ROOT=$(dirname $(readlink -e '../../..'))
ZAP_DEFAULT_LOCATION='third_party/zap/repo'
ZAP_INCLUDING_IMAGE_CONTEXT=$(pwd)
ZAP_INFO_FILE_NAME=zapinfo
cd $WORKING_TREE_ROOT
CHIP_SHA=$(git show | head -n 1 | awk '{print $2}')
cd $ZAP_INCLUDING_IMAGE_CONTEXT

if [[ ${*/--zap//} != "${*}" ]]; then
# Include zap in image from local folder
# Must be a git repo
ZAP_CUSTOM_PATH=${*/--zap=/}
ZAP_CUSTOM_PATH=$(echo $ZAP_CUSTOM_PATH | awk '{print $1}')
echo "Using custom zap dir" $ZAP_CUSTOM_PATH
cd $ZAP_CUSTOM_PATH
ZAP_SHA=$(git show | head -n 1 | awk '{print $2}')
cd $ZAP_INCLUDING_IMAGE_CONTEXT
cp -R $ZAP_CUSTOM_PATH .
mv ./$(basename $ZAP_CUSTOM_PATH) ./$(basename $ZAP_DEFAULT_LOCATION)
ZAP_INSTALL_CUSTOMIZED='YES'
else
# Copy zap into build context, save SHA info
cd $WORKING_TREE_ROOT
ZAP_SHA=$(git ls-tree master $ZAP_DEFAULT_LOCATION | awk '{print $3}')
git submodule update --init --recursive -- $ZAP_DEFAULT_LOCATION
cp -R $ZAP_DEFAULT_LOCATION $ZAP_INCLUDING_IMAGE_CONTEXT
cd $ZAP_INCLUDING_IMAGE_CONTEXT
ZAP_INSTALL_CUSTOMIZED='NO'
fi
echo "CUSTOM" $ZAP_INSTALL_CUSTOMIZED "project-chip/connectedhomeip" $CHIP_SHA "project-chip/zap" $ZAP_SHA>> $ZAP_INFO_FILE_NAME
fi

docker build "${BUILD_ARGS[@]}" --build-arg VERSION="$VERSION" -t "$ORG/$IMAGE:$VERSION" .
docker image prune --force

# Clean up zap from build conext
if [[ ${*/--zap//} != "${*}" ]]; then
rm -R $ZAP_INCLUDING_IMAGE_CONTEXT/$(basename $ZAP_DEFAULT_LOCATION)
rm -R $ZAP_INCLUDING_IMAGE_CONTEXT/$ZAP_INFO_FILE_NAME
fi

[[ ${*/--latest//} != "${*}" ]] && {
docker tag "$ORG"/"$IMAGE":"$VERSION" "$ORG"/"$IMAGE":latest
}
Expand Down
9 changes: 9 additions & 0 deletions integrations/docker/images/chip-build-zap/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ RUN pip3 install --no-cache-dir \
jinja2==3.0.3 \
lark==1.0.0 \
stringcase==1.2.0

WORKDIR /
COPY zapinfo zapinfo
COPY repo zapinstall
WORKDIR zapinstall
RUN npm ci

RUN mkdir ../zapout
RUN node ./src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/zigbee/gen-templates.json -i ./test/resource/three-endpoint-device.zap -o ../zapout

0 comments on commit c2f5f4f

Please sign in to comment.