forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_api_server.sh
executable file
·119 lines (105 loc) · 3.13 KB
/
build_api_server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script lets you build the API server image. It is mostly useful in
# build/test infrastructure that uses Remote Build Execution. Since access to
# RBE requires authentication credentials, this script lets you pass those
# credentials to the docker builder to be used by Bazel.
set -e
usage() {
cat <<EOM
Usage:
$0 [ --use_remote_build ] [ --gcp_credentials_file <FILE> ] -i IMAGE_TAG
--use_remote_build Use Remote Build Execution (RBE). Defaults to true.
--gcp_credentials_file Path to JSON file with credentials for RBE.
EOM
}
OPTS=i:
LONGOPTS=use_remote_build,gcp_credentials_file:
PARSED=$(getopt --longoptions=$LONGOPTS --options=$OPTS --name "$0" -- "$@")
eval set -- "$PARSED"
USE_REMOTE_BUILD=false
GCP_CREDENTIALS_FILE="gs://ml-pipeline-test-bazel/ml-pipeline-test-bazel-builder-credentials.json"
MACHINE_ARCH=`uname -m`
while true; do
case $1 in
--use_remote_build)
USE_REMOTE_BUILD=true;
shift;;
--gcp_credentials_file)
GCP_CREDENTIALS_FILE=$2;
shift 2;;
-i)
IMAGE_TAG=$2;
shift 2;;
--)
shift;
break;;
*)
usage;
exit 1;;
esac
done
if [[ -z "${IMAGE_TAG}" ]]; then
echo "Error: no image tag specified"
usage
exit 1
fi
WORKING_DIRECTORY="$(cd $(dirname "${BASH_SOURCE[0]}")/../. && pwd )"
cd ${WORKING_DIRECTORY}
if [[ ${USE_REMOTE_BUILD} == true ]]; then
echo "Building API Server Using Remote Build Execution..."
if [[ -z "${GCP_CREDENTIALS_FILE}" ]]; then
echo "Error: GCP_CREDENTIALS_FILE not specified"
exit 1
fi
GCP_CREDENTIALS="$(gsutil cat ${GCP_CREDENTIALS_FILE})"
if [ $MACHINE_ARCH == "aarch64" ]; then
docker build \
-t bazel:0.24.0 \
-f backend/Dockerfile.bazel .
docker build \
-t "${IMAGE_TAG}" \
-f backend/Dockerfile \
. \
--build-arg use_remote_build=true \
--build-arg google_application_credentials="${GCP_CREDENTIALS}" \
--build-arg BAZEL_IMAGE=bazel:0.24.0
else
docker build \
-t "${IMAGE_TAG}" \
-f backend/Dockerfile \
. \
--build-arg use_remote_build=true \
--build-arg google_application_credentials="${GCP_CREDENTIALS}"
fi
else
echo "Building API Server with local execution..."
if [ $MACHINE_ARCH == "aarch64" ]; then
docker build \
-t bazel:0.24.0 \
-f backend/Dockerfile.bazel .
docker build \
-t "${IMAGE_TAG}" \
-f backend/Dockerfile \
. \
--build-arg BAZEL_IMAGE=bazel:0.24.0
else
docker build \
-t "${IMAGE_TAG}" \
-f backend/Dockerfile \
.
fi
fi