Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit b57f20d

Browse files
author
Douglas Greiman
authored
Merge pull request #67 from GoogleCloudPlatform/dgreiman/system-test-auth
Run system tests under Jenkins
2 parents 844ed45 + 3d559e6 commit b57f20d

6 files changed

Lines changed: 89 additions & 21 deletions

File tree

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ $(error IMAGE_NAME is not set; invoke make with something like IMAGE_NAME=google
77
endif
88

99
.PHONY: all
10-
all:
11-
cloud-test
10+
all: cloud-test
1211

1312
## Files that must be refreshed every build
1413

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ shell. You need to be authenticated to a Google Cloud Project to invoke the
7777
Google Container Builder service, and also to run the system tests.
7878

7979
```shell
80-
$ export GCLOUD_PROJECT=YOUR-PROJECT-NAME
80+
$ export GOOGLE_CLOUD_PROJECT=YOUR-PROJECT-NAME
8181
$ DOCKER_NAMESPACE=gcr.io/${GCLOUD_PROJECT}
8282
$ CANDIDATE_NAME=`date +%Y-%m-%d_%H_%M`
8383
$ export IMAGE_NAME=${DOCKER_NAMESPACE}/python:${CANDIDATE_NAME}
84+
$ gcloud config set project ${GOOGLE_CLOUD_PROJECT}
8485
```
8586

8687
To rebuild the image using the Google Container Builder service, do the
@@ -98,6 +99,47 @@ $ make local-build
9899
$ make local-test
99100
```
100101

102+
To open an interactive shell session to this image after building it, do the following:
103+
104+
``` shell
105+
docker run --it --entrypoint /bin/bash ${IMAGE_NAME}
106+
```
107+
108+
## Running the system tests
109+
110+
To run the system tests, you need a Google Cloud Project with a service account.
111+
From the [Google Cloud Console](https://console.cloud.google.com/), either
112+
create a new project or switch to an existing one. Next,
113+
[create a service account](
114+
https://cloud.google.com/iam/docs/creating-managing-service-accounts) that will
115+
be used to run the system tests. Once you have a service account,
116+
[create and download a service account key](https://cloud.google.com/iam/docs/managing-service-account-keys).
117+
118+
In the
119+
[IAM & Admin](https://console.cloud.google.com/permissions/projectpermissions)
120+
section, grant the `Owner` role to the service account you created above. Also
121+
grant the `Editor` role to the `cloud-logs@google.com` service account.
122+
123+
124+
Then, follow the
125+
[system test setup instructions](https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/CONTRIBUTING.rst#running-system-tests). It
126+
describes various steps, including running some scripts to populate and/or
127+
delete datastore example data and indexes (populate_datastore.py,
128+
clear_datastore.py, and `gcloud preview datastore create-indexes
129+
system_tests/data/index.yaml`).
130+
131+
From the cloud console, you will need to enable the following APIs for your project:
132+
133+
- Bigquery API
134+
- Cloud Bigtable Admin API
135+
- Google Cloud Natural Language API
136+
- Google Cloud Pub/Sub API
137+
- Google Cloud Storage JSON API
138+
- Google Cloud Vision API
139+
- Google Translate API
140+
- Stackdriver Logging API
141+
- Stackdriver Monitoring API
142+
101143
## Contributing changes
102144

103145
* See [CONTRIBUTING.md](CONTRIBUTING.md)

cloudbuild.yaml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
timeout: 3600s
1+
timeout: 7200s
22
steps:
33
- name: gcr.io/cloud-builders/docker
44
args: ['build', '--tag=interpreter', '--no-cache', 'python-interpreter-builder']

jenkins_build.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,31 @@ if [ -z "${DOCKER_NAMESPACE+set}" ] ; then
1111
echo "Error: DOCKER_NAMESPACE is not set; invoke with something like DOCKER_NAMESPACE=gcr.io/YOUR-PROJECT-NAME" >&2
1212
exit 1
1313
fi
14-
IMAGE_NAME="${DOCKER_NAMESPACE}/${RUNTIME_NAME}:${CANDIDATE_NAME}"
14+
export IMAGE_NAME="${DOCKER_NAMESPACE}/${RUNTIME_NAME}:${CANDIDATE_NAME}"
15+
16+
if [ -z "${GOOGLE_CLOUD_PROJECT+set}" ] ; then
17+
echo "Error: GOOGLE_CLOUD_PROJECT is not set; invoke with something like GOOGLE_CLOUD_PROJECT=YOUR-PROJECT-NAME" >&2
18+
exit 1
19+
fi
1520

16-
export IMAGE_NAME
1721
export FORCE_REBUILD
18-
make cloud-test
22+
23+
echo "=================================================================="
24+
echo "Building image ${IMAGE_NAME} and pushing to ${DOCKER_NAMESPACE} using ${GOOGLE_CLOUD_PROJECT}"
25+
echo "=================================================================="
26+
27+
make cloud-build
28+
29+
# We explicitly pull the image using 'gcloud', instead of letting
30+
# Docker do it, so that we have the right credentials.
31+
echo "=================================================================="
32+
gcloud info
33+
echo gcloud docker -- pull "${IMAGE_NAME}"
34+
gcloud docker -- pull "${IMAGE_NAME}"
35+
echo "=================================================================="
36+
37+
# Note that system test failures might be caused environment factors
38+
# outside our control. Also, the images will be pushed to GCR by the
39+
# previous build step regardless of system test failures.
40+
make integration-tests || \
41+
echo "ERROR: System test failure, please examine the logs"

system_tests/Dockerfile.in

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
FROM ${IMAGE_NAME}
22

3-
# Inject secrets
4-
ADD data/ data/
5-
ENV GOOGLE_APPLICATION_CREDENTIALS /app/data/cloud-python-runtime-qa-credentials.json
6-
ENV GCLOUD_PROJECT cloud-python-runtime-qa
3+
# Secrets injected at runtime
4+
ENV GOOGLE_APPLICATION_CREDENTIALS=/app/credentials/credentials.json
5+
ENV GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}
76

87
# Get the source.
9-
RUN git clone https://github.com/GoogleCloudPlatform/google-cloud-python.git
8+
RUN git clone --depth 1 https://github.com/GoogleCloudPlatform/google-cloud-python.git
109
WORKDIR google-cloud-python
1110

1211
# Install tox for running the system tests
1312
RUN pip install --upgrade tox
1413

15-
# List of system tests to run. Ideally would be all of them. But
16-
# some of them get permission or other errors that are probably
17-
# related to incomplete test setup.
18-
ENV MODULES="datastore storage speech bigquery pubsub language translate monitoring bigtable"
19-
20-
# Run Python 2.7, 3.4 system tests
21-
RUN GOOGLE_CLOUD_TESTS_API_KEY=$(cat /app/data/cloud-python-runtime-qa-api-key.txt) \
22-
tox -e system-tests,system-tests3 -- ${MODULES}
14+
# Run Python 2.7, 3.5 system tests
15+
ENTRYPOINT ["tox", "-e", "system-tests,system-tests3"]

system_tests/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22
# a `git clone` which can not be cached.
33
DOCKER_FLAGS ?= --no-cache
44

5+
ifndef GOOGLE_APPLICATION_CREDENTIALS
6+
$(error GOOGLE_APPLICATION_CREDENTIALS is not set; download service account credentials in JSON format from the Google Cloud Console and invoke make with something like GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json)
7+
endif
8+
9+
ifndef GOOGLE_CLOUD_PROJECT
10+
$(error GOOGLE_CLOUD_PROJECT is not set; invoke make with something like GOOGLE_CLOUD_PROJECT=my-project-name)
11+
endif
12+
13+
514
.PHONY: all
615
all: Dockerfile
7-
docker build $(DOCKER_FLAGS) .
16+
@echo "Running system tests in project ${GOOGLE_CLOUD_PROJECT} using service account credentials from ${GOOGLE_APPLICATION_CREDENTIALS}"
17+
docker build --tag google-cloud-python-system-tests $(DOCKER_FLAGS) .
18+
docker run --rm -v $(GOOGLE_APPLICATION_CREDENTIALS):/app/credentials/credentials.json google-cloud-python-system-tests
819

920
.PHONY: Dockerfile
1021
Dockerfile: Dockerfile.in

0 commit comments

Comments
 (0)