Skip to content

Commit

Permalink
Separate building and testing phases via --build and --test flags.
Browse files Browse the repository at this point in the history
Sometimes the tests fails for reasons not related to the runtime.
This gives us a way to build and push the image anyway.
  • Loading branch information
Doug Greiman committed Oct 20, 2017
1 parent 8df5ad6 commit 44af511
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 88 deletions.
72 changes: 36 additions & 36 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ set -euo pipefail

# Actions
benchmark=0 # Should run benchmarks?
build=1 # Should build images?
library_tests=0 # Should try to install top N Python libraries
build=0 # Should build images?
system_tests=0 # Should run system tests?
tests=0 # Should run standard test suite?

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

Expand All @@ -40,32 +40,37 @@ Build and test artifacts in this repository
Options:
--[no]benchmark: Run benchmarking suite (default false)
--[no]build: Build all images (default true)
--[no]library_tests: Run library compatiblity tests (default false)
--[no]build: Build all images (default true if no options set)
--[no]tests: Run basic tests (default true if no options set)
--[no]local: Build images using local Docker daemon (default false)
--[no]system_tests: Run system tests (default false)
"
}

# Read environment variables
if [ -z "${DOCKER_NAMESPACE+set}" ] ; then
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
if [ -z "${BUILDER_DOCKER_NAMESPACE:+set}" ] ; then
export BUILDER_DOCKER_NAMESPACE="${DOCKER_NAMESPACE}"
fi

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

substitutions="\
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
Expand All @@ -85,14 +90,6 @@ while [ $# -gt 0 ]; do
build=0
shift
;;
--library_tests)
library_tests=1
shift
;;
--nolibrary_tests)
library_tests=0
shift
;;
--local)
local=1
shift
Expand All @@ -109,6 +106,14 @@ while [ $# -gt 0 ]; do
system_tests=0
shift
;;
--tests)
tests=1
shift
;;
--notests)
tests=0
shift
;;
*)
usage
;;
Expand All @@ -118,9 +123,12 @@ done
# If no actions chosen, then tell the user
if [ "${benchmark}" -eq 0 -a \
"${build}" -eq 0 -a \
"${library_tests}" -eq 0 -a \
"${system_tests}" -eq 0 ]; then
fatal 'Error: No actions specified (for example, --build), exiting'
"${system_tests}" -eq 0 -a \
"${tests}" -eq 0 \
]; then
echo 'No actions specified, defaulting to --build --tests'
build=1
tests=1
fi

# Running build local or remote?
Expand Down Expand Up @@ -155,7 +163,8 @@ for outfile in \
tests/google-cloud-python-system/Dockerfile \
tests/integration/Dockerfile \
; do
envsubst <"${outfile}".in >"${outfile}" '$DEBIAN_BASE_IMAGE $STAGING_IMAGE $GOOGLE_CLOUD_PROJECT_FOR_TESTS'
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
Expand All @@ -174,36 +183,27 @@ 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 "${substitutions}"
${gcloud_cmd} --config cloudbuild.yaml --substitutions "${build_substitutions}"
fi

# Run just the library compatibility tests (for DPE Gardener bot usually)
if [ "${library_tests}" -eq 1 ]; then
# Run the tests that don't require (too many) external services
if [ "${tests}" -eq 1 ]; then
echo "Testing compatibility with popular Python libraries"
${gcloud_cmd} --config cloudbuild_library_tests.yaml --substitutions "${substitutions}"
${gcloud_cmd} --config cloudbuild_tests.yaml --substitutions "${substitutions}"
fi

# If both system tests and benchmarks are requested, run them both
# even if one or the other has errors. If the build step had errors,
# this script will have already exited.
exit_code=0

# Run system tests
if [ "${system_tests}" -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_tests.yaml --substitutions "${substitutions}" || \
exit_code=1
${gcloud_cmd} --config cloudbuild_system_tests.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}" || \
exit_code=1
${gcloud_cmd} --config cloudbuild_benchmark.yaml --substitutions "${substitutions}"
fi

exit ${exit_code}
25 changes: 1 addition & 24 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,12 @@ steps:
name: gcr.io/cloud-builders/docker:latest
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python:${_TAG}',
'--no-cache', '/workspace/runtime-image/']
- # Validate structure of base runtime image
name: gcr.io/gcp-runtimes/structure_test:latest
args: [
'-i', '${_DOCKER_NAMESPACE}/python:${_TAG}',
'--config', '/workspace/tests/virtualenv/virtualenv_default.yaml',
'--config', '/workspace/tests/virtualenv/virtualenv_python34.yaml',
'--config', '/workspace/tests/virtualenv/virtualenv_python35.yaml',
'--config', '/workspace/tests/virtualenv/virtualenv_python36.yaml',
'--config', '/workspace/tests/no-virtualenv/no-virtualenv.yaml',
'--config', '/workspace/tests/python2-libraries/python2-libraries.yaml',
'--config', '/workspace/tests/python3-libraries/python3-libraries.yaml',
'--config', '/workspace/tests/license-test/license-test.yaml',
'-v'
]
- # Run compatibility tests
name: gcr.io/cloud-builders/docker:latest
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/eventlet:${_TAG}',
'--no-cache', '/workspace/tests/eventlet/']
- # Build image to run google client library unit tests
name: gcr.io/cloud-builders/docker:latest
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}',
'--no-cache', '/workspace/tests/google-cloud-python/']
- # Run google client library unit tests
name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}
- # Build runtime builder image
name: gcr.io/cloud-builders/docker:latest
args: ['build', '--tag=${_BUILDER_DOCKER_NAMESPACE}/python/gen-dockerfile:${_TAG}',
'--no-cache', '/workspace/builder/gen-dockerfile/']
images: [
'${_DOCKER_NAMESPACE}/python/interpreter-builder:${_TAG}',
'${_DOCKER_NAMESPACE}/python:${_TAG}',
'${_BUILDER_DOCKER_NAMESPACE}/python/gen-dockerfile:${_TAG}',
]
4 changes: 0 additions & 4 deletions cloudbuild_benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ steps:
- name: gcr.io/cloud-builders/docker:latest
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/benchmark:${_TAG}',
'--no-cache', '/workspace/tests/benchmark/']
env: [
# Avoid warning about unused substitutions
'UNUSED1=${_BUILDER_DOCKER_NAMESPACE}',
]
images: [
# Intentionally empty
]
20 changes: 0 additions & 20 deletions cloudbuild_library_tests.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions cloudbuild_system_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ steps:
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/google-cloud-python-system:${_TAG}',
'--no-cache', '/workspace/tests/google-cloud-python-system/']
- name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python-system:${_TAG}
env: [
# Avoid warning about unused substitutions
'UNUSED1=${_BUILDER_DOCKER_NAMESPACE}',
]
images: [
# Intentionally empty
]
28 changes: 28 additions & 0 deletions cloudbuild_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
timeout: 3600s
steps:
- # Validate structure of base runtime image
name: gcr.io/gcp-runtimes/structure_test:latest
args: [
'-i', '${_DOCKER_NAMESPACE}/python:${_TAG}',
'--config', '/workspace/tests/virtualenv/virtualenv_default.yaml',
'--config', '/workspace/tests/virtualenv/virtualenv_python34.yaml',
'--config', '/workspace/tests/virtualenv/virtualenv_python35.yaml',
'--config', '/workspace/tests/virtualenv/virtualenv_python36.yaml',
'--config', '/workspace/tests/no-virtualenv/no-virtualenv.yaml',
'--config', '/workspace/tests/python2-libraries/python2-libraries.yaml',
'--config', '/workspace/tests/python3-libraries/python3-libraries.yaml',
'--config', '/workspace/tests/license-test/license-test.yaml',
'-v'
]
- # Run compatibility tests
name: gcr.io/cloud-builders/docker:latest
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/eventlet:${_TAG}',
'--no-cache', '/workspace/tests/eventlet/']
- # Build image to run google client library unit tests
name: gcr.io/cloud-builders/docker:latest
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}',
'--no-cache', '/workspace/tests/google-cloud-python/']
- # Run google client library unit tests
name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}
images: [
]

0 comments on commit 44af511

Please sign in to comment.