forked from GoogleCloudPlatform/python-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·209 lines (179 loc) · 5.54 KB
/
build.sh
File metadata and controls
executable file
·209 lines (179 loc) · 5.54 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
# Copyright 2016 Google Inc. All rights reserved.
# 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
# http://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.
set -euo pipefail
# Actions
benchmark=0 # Should run benchmarks?
build=0 # Should build images?
system_test=0 # Should run system tests?
test=0 # Should run standard test suite?
local=0 # Should run using local Docker daemon instead of GCR?
# Note that $gcloud_cmd has spaces in it
gcloud_cmd="gcloud beta container builds submit ."
local_gcloud_cmd="scripts/local_cloudbuild.py"
# Helper functions
function fatal() {
echo "$1" >&2
exit 1
}
function usage {
fatal "Usage: $0 [OPTION]...
Build and test artifacts in this repository
Options:
--[no]benchmark: Run benchmarking suite (default false)
--[no]build: Build all images (default true if no options set)
--[no]test: Run basic tests (default true if no options set)
--[no]local: Build images using local Docker daemon (default false)
--[no]system_test: Run system tests (default false)
"
}
# Read environment variables
if [ -z "${DOCKER_NAMESPACE:+set}" ] ; then
fatal 'Error: $DOCKER_NAMESPACE is not set; invoke with something like DOCKER_NAMESPACE=gcr.io/YOUR-PROJECT-NAME'
fi
if [ -z "${BUILDER_DOCKER_NAMESPACE:+set}" ] ; then
export BUILDER_DOCKER_NAMESPACE="${DOCKER_NAMESPACE}"
fi
if [ -z "${TAG:+set}" ] ; then
export TAG=`date +%Y-%m-%d-%H%M%S`
fi
build_substitutions="\
_BUILDER_DOCKER_NAMESPACE=${BUILDER_DOCKER_NAMESPACE},\
_DOCKER_NAMESPACE=${DOCKER_NAMESPACE},\
_TAG=${TAG}\
"
substitutions="\
_DOCKER_NAMESPACE=${DOCKER_NAMESPACE},\
_TAG=${TAG}\
"
# Read command line arguments
while [ $# -gt 0 ]; do
case "$1" in
--benchmark)
benchmark=1
shift
;;
--nobenchmark)
benchmark=0
shift
;;
--build)
build=1
shift
;;
--nobuild)
build=0
shift
;;
--local)
local=1
shift
;;
--nolocal)
local=0
shift
;;
--system_test)
system_test=1
shift
;;
--nosystem_test)
system_test=0
shift
;;
--test)
test=1
shift
;;
--notest)
test=0
shift
;;
*)
usage
;;
esac
done
# If no actions chosen, then tell the user
if [ "${benchmark}" -eq 0 -a \
"${build}" -eq 0 -a \
"${system_test}" -eq 0 -a \
"${test}" -eq 0 \
]; then
echo 'No actions specified, defaulting to --build --test'
build=1
test=1
fi
# Running build local or remote?
if [ "${local}" -eq 1 ]; then
gcloud_cmd="${local_gcloud_cmd}"
fi
# Read action-specific environment variables
if [ "${system_test}" -eq 1 ]; then
if [ -z "${GOOGLE_APPLICATION_CREDENTIALS_FOR_TESTS+set}" ] ; then
fatal 'Error: $GOOGLE_APPLICATION_CREDENTIALS_FOR_TESTS is not set; invoke with something like GOOGLE_APPLICATION_CREDENTIALS_FOR_TESTS=/path/to/service/account/creds.json'
fi
if [ -z "${GOOGLE_CLOUD_PROJECT_FOR_TESTS+set}" ] ; then
fatal 'Error: $GOOGLE_CLOUD_PROJECT_FOR_TESTS is not set; invoke with something like GOOGLE_CLOUD_PROJECT_FOR_TESTS=YOUR-PROJECT-NAME'
fi
fi
# Use latest released Debian as our base image
export DEBIAN_BASE_IMAGE="gcr.io/google-appengine/debian8:latest"
export STAGING_IMAGE="${DOCKER_NAMESPACE}/python:${TAG}"
echo "Using base image name ${STAGING_IMAGE}"
# Generate Dockerfiles
for outfile in \
builder/gen-dockerfile/Dockerfile \
python-interpreter-builder/Dockerfile \
runtime-image/Dockerfile \
tests/benchmark/Dockerfile \
tests/eventlet/Dockerfile \
tests/google-cloud-python/Dockerfile \
tests/google-cloud-python-system/Dockerfile \
tests/integration/Dockerfile \
; do
envsubst <"${outfile}".in >"${outfile}" \
'$DEBIAN_BASE_IMAGE $STAGING_IMAGE $GOOGLE_CLOUD_PROJECT_FOR_TESTS $TAG'
done
# Make some files available to the runtime builder Docker context
mkdir -p builder/gen-dockerfile/data
for file in \
scripts/gen_dockerfile.py \
scripts/validation_utils.py \
scripts/data/* \
; do
cp -a "${file}" "builder/gen-dockerfile/${file##scripts/}"
done
# Make a file available to the eventlet test.
cp -a scripts/testdata/hello_world/main.py tests/eventlet/main.py
# Build images and push to GCR
if [ "${build}" -eq 1 ]; then
echo "Building images"
${gcloud_cmd} --config cloudbuild.yaml --substitutions "${build_substitutions}"
fi
# Run the tests that don't require (too many) external services
if [ "${test}" -eq 1 ]; then
echo "Testing compatibility with popular Python libraries"
${gcloud_cmd} --config cloudbuild_test.yaml --substitutions "${substitutions}"
fi
# Run system tests
if [ "${system_test}" -eq 1 ]; then
echo "Running system tests using project ${GOOGLE_CLOUD_PROJECT_FOR_TESTS}"
trap "rm -f tests/google-cloud-python-system/credentials.json" EXIT
cp "${GOOGLE_APPLICATION_CREDENTIALS_FOR_TESTS}" tests/google-cloud-python-system/credentials.json
${gcloud_cmd} --config cloudbuild_system_test.yaml --substitutions "${substitutions}"
rm -f tests/google-cloud-python-system/credentials.json
fi
# Run benchmarks
if [ "${benchmark}" -eq 1 ] ; then
echo "Running benchmark"
${gcloud_cmd} --config cloudbuild_benchmark.yaml --substitutions "${substitutions}"
fi