4 # Copyright (c) 2020 Project CHIP Authors
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 # build.sh - utility for building (and optionally) tagging and pushing
22 # This script expects to find a Dockerfile next to $0, so symlink
23 # in an image name directory is the expected use case.
28 ORG=${DOCKER_BUILD_ORG:-connectedhomeip}
31 IMAGE=${DOCKER_BUILD_IMAGE:-$(basename "$(pwd)")}
34 VERSION=${DOCKER_BUILD_VERSION:-$(cat version)}
36 [[ ${*/--help//} != "${*}" ]] && {
38 echo "Usage: $me <OPTIONS>
40 Build and (optionally tag as latest, push) a docker image from Dockerfile in CWD
43 --no-cache passed as a docker build argument
44 --latest update latest to the current built version (\"$VERSION\")
45 --push push image(s) to docker.io (requires docker login for \"$ORG\")
46 --help get this message
53 echo "$me: *** ERROR: $*"
59 [[ -n $VERSION ]] || die "version cannot be empty"
61 # go find and build any CHIP images this image is "FROM"
62 awk -F/ '/^FROM connectedhomeip/ {print $2}' Dockerfile | while read -r dep; do
64 (cd "../$dep" && ./build.sh "$@")
68 if [[ ${*/--no-cache//} != "${*}" ]]; then
69 BUILD_ARGS+=(--no-cache)
72 docker build "${BUILD_ARGS[@]}" --build-arg VERSION="$VERSION" -t "$ORG/$IMAGE:$VERSION" .
74 [[ ${*/--latest//} != "${*}" ]] && {
75 docker tag "$ORG"/"$IMAGE":"$VERSION" "$ORG"/"$IMAGE":latest
78 [[ ${*/--push//} != "${*}" ]] && {
79 docker push "$ORG"/"$IMAGE":"$VERSION"
80 [[ ${*/--latest//} != "${*}" ]] && {
81 docker push "$ORG"/"$IMAGE":latest