Skip to content

Commit 02c9d12

Browse files
author
Douglas Greiman
authored
Merge pull request #155 from GoogleCloudPlatform/dgreiman/buildsh
Separate building and testing phases via --build and --test flags.
2 parents 8df5ad6 + b25687d commit 02c9d12

File tree

6 files changed

+73
-96
lines changed

6 files changed

+73
-96
lines changed

build.sh

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ set -euo pipefail
1818

1919
# Actions
2020
benchmark=0 # Should run benchmarks?
21-
build=1 # Should build images?
22-
library_tests=0 # Should try to install top N Python libraries
23-
system_tests=0 # Should run system tests?
21+
build=0 # Should build images?
22+
system_test=0 # Should run system tests?
23+
test=0 # Should run standard test suite?
2424

2525
local=0 # Should run using local Docker daemon instead of GCR?
2626

@@ -40,32 +40,37 @@ Build and test artifacts in this repository
4040
4141
Options:
4242
--[no]benchmark: Run benchmarking suite (default false)
43-
--[no]build: Build all images (default true)
44-
--[no]library_tests: Run library compatiblity tests (default false)
43+
--[no]build: Build all images (default true if no options set)
44+
--[no]test: Run basic tests (default true if no options set)
4545
--[no]local: Build images using local Docker daemon (default false)
46-
--[no]system_tests: Run system tests (default false)
46+
--[no]system_test: Run system tests (default false)
4747
"
4848
}
49-
49+
5050
# Read environment variables
51-
if [ -z "${DOCKER_NAMESPACE+set}" ] ; then
51+
if [ -z "${DOCKER_NAMESPACE:+set}" ] ; then
5252
fatal 'Error: $DOCKER_NAMESPACE is not set; invoke with something like DOCKER_NAMESPACE=gcr.io/YOUR-PROJECT-NAME'
5353
fi
5454

55-
if [ -z "${BUILDER_DOCKER_NAMESPACE+set}" ] ; then
55+
if [ -z "${BUILDER_DOCKER_NAMESPACE:+set}" ] ; then
5656
export BUILDER_DOCKER_NAMESPACE="${DOCKER_NAMESPACE}"
5757
fi
5858

59-
if [ -z "${TAG+set}" ] ; then
59+
if [ -z "${TAG:+set}" ] ; then
6060
export TAG=`date +%Y-%m-%d-%H%M%S`
6161
fi
6262

63-
substitutions="\
63+
build_substitutions="\
6464
_BUILDER_DOCKER_NAMESPACE=${BUILDER_DOCKER_NAMESPACE},\
6565
_DOCKER_NAMESPACE=${DOCKER_NAMESPACE},\
6666
_TAG=${TAG}\
6767
"
6868

69+
substitutions="\
70+
_DOCKER_NAMESPACE=${DOCKER_NAMESPACE},\
71+
_TAG=${TAG}\
72+
"
73+
6974
# Read command line arguments
7075
while [ $# -gt 0 ]; do
7176
case "$1" in
@@ -85,14 +90,6 @@ while [ $# -gt 0 ]; do
8590
build=0
8691
shift
8792
;;
88-
--library_tests)
89-
library_tests=1
90-
shift
91-
;;
92-
--nolibrary_tests)
93-
library_tests=0
94-
shift
95-
;;
9693
--local)
9794
local=1
9895
shift
@@ -101,12 +98,20 @@ while [ $# -gt 0 ]; do
10198
local=0
10299
shift
103100
;;
104-
--system_tests)
105-
system_tests=1
101+
--system_test)
102+
system_test=1
103+
shift
104+
;;
105+
--nosystem_test)
106+
system_test=0
106107
shift
107108
;;
108-
--nosystem_tests)
109-
system_tests=0
109+
--test)
110+
test=1
111+
shift
112+
;;
113+
--notest)
114+
test=0
110115
shift
111116
;;
112117
*)
@@ -118,9 +123,12 @@ done
118123
# If no actions chosen, then tell the user
119124
if [ "${benchmark}" -eq 0 -a \
120125
"${build}" -eq 0 -a \
121-
"${library_tests}" -eq 0 -a \
122-
"${system_tests}" -eq 0 ]; then
123-
fatal 'Error: No actions specified (for example, --build), exiting'
126+
"${system_test}" -eq 0 -a \
127+
"${test}" -eq 0 \
128+
]; then
129+
echo 'No actions specified, defaulting to --build --test'
130+
build=1
131+
test=1
124132
fi
125133

126134
# Running build local or remote?
@@ -129,7 +137,7 @@ if [ "${local}" -eq 1 ]; then
129137
fi
130138

131139
# Read action-specific environment variables
132-
if [ "${system_tests}" -eq 1 ]; then
140+
if [ "${system_test}" -eq 1 ]; then
133141
if [ -z "${GOOGLE_APPLICATION_CREDENTIALS_FOR_TESTS+set}" ] ; then
134142
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'
135143
fi
@@ -155,7 +163,8 @@ for outfile in \
155163
tests/google-cloud-python-system/Dockerfile \
156164
tests/integration/Dockerfile \
157165
; do
158-
envsubst <"${outfile}".in >"${outfile}" '$DEBIAN_BASE_IMAGE $STAGING_IMAGE $GOOGLE_CLOUD_PROJECT_FOR_TESTS'
166+
envsubst <"${outfile}".in >"${outfile}" \
167+
'$DEBIAN_BASE_IMAGE $STAGING_IMAGE $GOOGLE_CLOUD_PROJECT_FOR_TESTS $TAG'
159168
done
160169

161170
# Make some files available to the runtime builder Docker context
@@ -174,36 +183,27 @@ cp -a scripts/testdata/hello_world/main.py tests/eventlet/main.py
174183
# Build images and push to GCR
175184
if [ "${build}" -eq 1 ]; then
176185
echo "Building images"
177-
${gcloud_cmd} --config cloudbuild.yaml --substitutions "${substitutions}"
186+
${gcloud_cmd} --config cloudbuild.yaml --substitutions "${build_substitutions}"
178187
fi
179188

180-
# Run just the library compatibility tests (for DPE Gardener bot usually)
181-
if [ "${library_tests}" -eq 1 ]; then
189+
# Run the tests that don't require (too many) external services
190+
if [ "${test}" -eq 1 ]; then
182191
echo "Testing compatibility with popular Python libraries"
183-
${gcloud_cmd} --config cloudbuild_library_tests.yaml --substitutions "${substitutions}"
192+
${gcloud_cmd} --config cloudbuild_test.yaml --substitutions "${substitutions}"
184193
fi
185194

186-
# If both system tests and benchmarks are requested, run them both
187-
# even if one or the other has errors. If the build step had errors,
188-
# this script will have already exited.
189-
exit_code=0
190-
191195
# Run system tests
192-
if [ "${system_tests}" -eq 1 ]; then
196+
if [ "${system_test}" -eq 1 ]; then
193197
echo "Running system tests using project ${GOOGLE_CLOUD_PROJECT_FOR_TESTS}"
194198

195199
trap "rm -f tests/google-cloud-python-system/credentials.json" EXIT
196200
cp "${GOOGLE_APPLICATION_CREDENTIALS_FOR_TESTS}" tests/google-cloud-python-system/credentials.json
197-
${gcloud_cmd} --config cloudbuild_system_tests.yaml --substitutions "${substitutions}" || \
198-
exit_code=1
201+
${gcloud_cmd} --config cloudbuild_system_test.yaml --substitutions "${substitutions}"
199202
rm -f tests/google-cloud-python-system/credentials.json
200203
fi
201204

202205
# Run benchmarks
203206
if [ "${benchmark}" -eq 1 ] ; then
204207
echo "Running benchmark"
205-
${gcloud_cmd} --config cloudbuild_benchmark.yaml --substitutions "${substitutions}" || \
206-
exit_code=1
208+
${gcloud_cmd} --config cloudbuild_benchmark.yaml --substitutions "${substitutions}"
207209
fi
208-
209-
exit ${exit_code}

cloudbuild.yaml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,12 @@ steps:
1111
name: gcr.io/cloud-builders/docker:latest
1212
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python:${_TAG}',
1313
'--no-cache', '/workspace/runtime-image/']
14-
- # Validate structure of base runtime image
15-
name: gcr.io/gcp-runtimes/structure_test:latest
16-
args: [
17-
'-i', '${_DOCKER_NAMESPACE}/python:${_TAG}',
18-
'--config', '/workspace/tests/virtualenv/virtualenv_default.yaml',
19-
'--config', '/workspace/tests/virtualenv/virtualenv_python34.yaml',
20-
'--config', '/workspace/tests/virtualenv/virtualenv_python35.yaml',
21-
'--config', '/workspace/tests/virtualenv/virtualenv_python36.yaml',
22-
'--config', '/workspace/tests/no-virtualenv/no-virtualenv.yaml',
23-
'--config', '/workspace/tests/python2-libraries/python2-libraries.yaml',
24-
'--config', '/workspace/tests/python3-libraries/python3-libraries.yaml',
25-
'--config', '/workspace/tests/license-test/license-test.yaml',
26-
'-v'
27-
]
28-
- # Run compatibility tests
29-
name: gcr.io/cloud-builders/docker:latest
30-
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/eventlet:${_TAG}',
31-
'--no-cache', '/workspace/tests/eventlet/']
32-
- # Build image to run google client library unit tests
33-
name: gcr.io/cloud-builders/docker:latest
34-
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}',
35-
'--no-cache', '/workspace/tests/google-cloud-python/']
36-
- # Run google client library unit tests
37-
name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}
3814
- # Build runtime builder image
3915
name: gcr.io/cloud-builders/docker:latest
4016
args: ['build', '--tag=${_BUILDER_DOCKER_NAMESPACE}/python/gen-dockerfile:${_TAG}',
4117
'--no-cache', '/workspace/builder/gen-dockerfile/']
4218
images: [
19+
'${_DOCKER_NAMESPACE}/python/interpreter-builder:${_TAG}',
4320
'${_DOCKER_NAMESPACE}/python:${_TAG}',
4421
'${_BUILDER_DOCKER_NAMESPACE}/python/gen-dockerfile:${_TAG}',
4522
]

cloudbuild_benchmark.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ steps:
33
- name: gcr.io/cloud-builders/docker:latest
44
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/benchmark:${_TAG}',
55
'--no-cache', '/workspace/tests/benchmark/']
6-
env: [
7-
# Avoid warning about unused substitutions
8-
'UNUSED1=${_BUILDER_DOCKER_NAMESPACE}',
9-
]
106
images: [
117
# Intentionally empty
128
]

cloudbuild_library_tests.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ steps:
44
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/google-cloud-python-system:${_TAG}',
55
'--no-cache', '/workspace/tests/google-cloud-python-system/']
66
- name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python-system:${_TAG}
7-
env: [
8-
# Avoid warning about unused substitutions
9-
'UNUSED1=${_BUILDER_DOCKER_NAMESPACE}',
10-
]
117
images: [
128
# Intentionally empty
139
]

cloudbuild_test.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
timeout: 3600s
2+
steps:
3+
- # Validate structure of base runtime image
4+
name: gcr.io/gcp-runtimes/structure_test:latest
5+
args: [
6+
'-i', '${_DOCKER_NAMESPACE}/python:${_TAG}',
7+
'--config', '/workspace/tests/virtualenv/virtualenv_default.yaml',
8+
'--config', '/workspace/tests/virtualenv/virtualenv_python34.yaml',
9+
'--config', '/workspace/tests/virtualenv/virtualenv_python35.yaml',
10+
'--config', '/workspace/tests/virtualenv/virtualenv_python36.yaml',
11+
'--config', '/workspace/tests/no-virtualenv/no-virtualenv.yaml',
12+
'--config', '/workspace/tests/python2-libraries/python2-libraries.yaml',
13+
'--config', '/workspace/tests/python3-libraries/python3-libraries.yaml',
14+
'--config', '/workspace/tests/license-test/license-test.yaml',
15+
'-v'
16+
]
17+
- # Run compatibility tests
18+
name: gcr.io/cloud-builders/docker:latest
19+
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/eventlet:${_TAG}',
20+
'--no-cache', '/workspace/tests/eventlet/']
21+
- # Build image to run google client library unit tests
22+
name: gcr.io/cloud-builders/docker:latest
23+
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}',
24+
'--no-cache', '/workspace/tests/google-cloud-python/']
25+
- # Run google client library unit tests
26+
name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}
27+
images: [
28+
]

0 commit comments

Comments
 (0)