Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / integrations / docker / build.sh
1 #!/usr/bin/env bash
2
3 #
4 # Copyright (c) 2020 Project CHIP Authors
5 #
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
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
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.
17 #
18
19 # build.sh   - utility for building (and optionally) tagging and pushing
20 #               the a Docker image
21 #
22 # This script expects to find a Dockerfile next to $0, so symlink
23 #  in an image name directory is the expected use case.
24
25 me=$(basename "$0")
26 cd "$(dirname "$0")"
27
28 ORG=${DOCKER_BUILD_ORG:-connectedhomeip}
29
30 # directory name is
31 IMAGE=${DOCKER_BUILD_IMAGE:-$(basename "$(pwd)")}
32
33 # version
34 VERSION=${DOCKER_BUILD_VERSION:-$(cat version)}
35
36 [[ ${*/--help//} != "${*}" ]] && {
37     set +x
38     echo "Usage: $me <OPTIONS>
39
40   Build and (optionally tag as latest, push) a docker image from Dockerfile in CWD
41
42   Options:
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
47
48 "
49     exit 0
50 }
51
52 die() {
53     echo "$me: *** ERROR: $*"
54     exit 1
55 }
56
57 set -ex
58
59 [[ -n $VERSION ]] || die "version cannot be empty"
60
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
63     dep=${dep%:*}
64     (cd "../$dep" && ./build.sh "$@")
65 done
66
67 BUILD_ARGS=()
68 if [[ ${*/--no-cache//} != "${*}" ]]; then
69     BUILD_ARGS+=(--no-cache)
70 fi
71
72 docker build "${BUILD_ARGS[@]}" --build-arg VERSION="$VERSION" -t "$ORG/$IMAGE:$VERSION" .
73
74 [[ ${*/--latest//} != "${*}" ]] && {
75     docker tag "$ORG"/"$IMAGE":"$VERSION" "$ORG"/"$IMAGE":latest
76 }
77
78 [[ ${*/--push//} != "${*}" ]] && {
79     docker push "$ORG"/"$IMAGE":"$VERSION"
80     [[ ${*/--latest//} != "${*}" ]] && {
81         docker push "$ORG"/"$IMAGE":latest
82     }
83 }
84
85 exit 0