Skip to content

Commit a7ed11e

Browse files
authored
build: use trampoline_v2 for python samples and allow custom dockerfile (#1232)
* Use trampoline_v2 ([Docker CI Helper](https://github.com/GoogleCloudPlatform/docker-ci-helper)) for all python samples. * Optionally allow samples to run with a Dockerfile specified in the library repository at `.kokoro/docker/samples`. On a successful test run, this Dockerfile is uploaded to `gcr.io/cloud-devrel-kokoro-resources/{repo-name}-samples-docker`. The option is enabled by passing `custom_samples_dockerfile=True` to `common.py_library` in `owlbot.py`. ```py templated_files = common.py_library(microgenerator=True, custom_samples_dockerfile=True) ``` See googleapis/python-asset#308 for an example of moving samples to to trampoline_v2. See googleapis/python-recaptcha-enterprise#128 for an example of moving to trampoline_v2 + using a custom Dockerfile.
1 parent 2607ffc commit a7ed11e

File tree

16 files changed

+136
-21
lines changed

16 files changed

+136
-21
lines changed

synthtool/gcp/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ def py_library(self, **kwargs) -> Path:
237237
if "samples" not in kwargs:
238238
self.excludes += ["samples/AUTHORING_GUIDE.md", "samples/CONTRIBUTING.md"]
239239

240+
# Assume the python-docs-samples Dockerfile is used for samples by default
241+
if "custom_samples_dockerfile" not in kwargs:
242+
kwargs["custom_samples_dockerfile"] = False
243+
240244
ret = self._generic_library("python_library", **kwargs)
241245

242246
# If split_system_tests is set to True, we disable the system

synthtool/gcp/templates/python_library/.kokoro/samples/lint/common.cfg

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,29 @@ env_vars: {
1717
key: "TRAMPOLINE_BUILD_FILE"
1818
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples.sh"
1919
}
20+
{% if custom_samples_dockerfile %}
21+
env_vars: {
22+
key: "TRAMPOLINE_IMAGE"
23+
value: "gcr.io/cloud-devrel-kokoro-resources/{{ metadata['repo']['repo'].split('/')[1] }}-samples-docker"
24+
}
2025

26+
# Configure the docker image for kokoro-trampoline.
27+
env_vars: {
28+
key: "TRAMPOLINE_DOCKERFILE"
29+
value: ".kokoro/docker/samples/Dockerfile"
30+
}
31+
{% else %}
2132
# Configure the docker image for kokoro-trampoline.
2233
env_vars: {
2334
key: "TRAMPOLINE_IMAGE"
2435
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
2536
}
26-
37+
{% endif %}
2738
# Download secrets for samples
2839
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
2940

3041
# Download trampoline resources.
3142
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
3243

3344
# Use the trampoline script to run in docker.
34-
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline.sh"
45+
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline_v2.sh"

synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/common.cfg

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,29 @@ env_vars: {
2323
key: "TRAMPOLINE_BUILD_FILE"
2424
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples.sh"
2525
}
26+
{% if custom_samples_dockerfile %}
27+
env_vars: {
28+
key: "TRAMPOLINE_IMAGE"
29+
value: "gcr.io/cloud-devrel-kokoro-resources/{{ metadata['repo']['repo'].split('/')[1] }}-samples-docker"
30+
}
2631

32+
# Configure the docker image for kokoro-trampoline.
33+
env_vars: {
34+
key: "TRAMPOLINE_DOCKERFILE"
35+
value: ".kokoro/docker/samples/Dockerfile"
36+
}
37+
{% else %}
2738
# Configure the docker image for kokoro-trampoline.
2839
env_vars: {
2940
key: "TRAMPOLINE_IMAGE"
3041
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
3142
}
32-
43+
{% endif %}
3344
# Download secrets for samples
3445
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
3546

3647
# Download trampoline resources.
3748
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
3849

3950
# Use the trampoline script to run in docker.
40-
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline.sh"
51+
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline_v2.sh"

synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic-head.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ env_vars: {
99
key: "TRAMPOLINE_BUILD_FILE"
1010
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples-against-head.sh"
1111
}
12+
{% if custom_samples_dockerfile %}
13+
# Upload the docker image after successful builds.
14+
env_vars: {
15+
key: "TRAMPOLINE_IMAGE_UPLOAD"
16+
value: "true"
17+
}
18+
{% endif %}

synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
env_vars: {
44
key: "INSTALL_LIBRARY_FROM_SOURCE"
55
value: "False"
6-
}
6+
}
7+
{% if custom_samples_dockerfile %}
8+
# Upload the docker image after successful builds.
9+
env_vars: {
10+
key: "TRAMPOLINE_IMAGE_UPLOAD"
11+
value: "true"
12+
}
13+
{% endif %}

synthtool/gcp/templates/python_library/.kokoro/samples/python3.7/common.cfg

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,29 @@ env_vars: {
2323
key: "TRAMPOLINE_BUILD_FILE"
2424
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples.sh"
2525
}
26+
{% if custom_samples_dockerfile %}
27+
env_vars: {
28+
key: "TRAMPOLINE_IMAGE"
29+
value: "gcr.io/cloud-devrel-kokoro-resources/{{ metadata['repo']['repo'].split('/')[1] }}-samples-docker"
30+
}
2631

32+
# Configure the docker image for kokoro-trampoline.
33+
env_vars: {
34+
key: "TRAMPOLINE_DOCKERFILE"
35+
value: ".kokoro/docker/samples/Dockerfile"
36+
}
37+
{% else %}
2738
# Configure the docker image for kokoro-trampoline.
2839
env_vars: {
2940
key: "TRAMPOLINE_IMAGE"
3041
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
3142
}
32-
43+
{% endif %}
3344
# Download secrets for samples
3445
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
3546

3647
# Download trampoline resources.
3748
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
3849

3950
# Use the trampoline script to run in docker.
40-
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline.sh"
51+
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline_v2.sh"

synthtool/gcp/templates/python_library/.kokoro/samples/python3.7/periodic.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
env_vars: {
44
key: "INSTALL_LIBRARY_FROM_SOURCE"
55
value: "False"
6-
}
6+
}
7+
{% if custom_samples_dockerfile %}
8+
# Upload the docker image after successful builds.
9+
env_vars: {
10+
key: "TRAMPOLINE_IMAGE_UPLOAD"
11+
value: "true"
12+
}
13+
{% endif %}

synthtool/gcp/templates/python_library/.kokoro/samples/python3.8/common.cfg

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,29 @@ env_vars: {
2323
key: "TRAMPOLINE_BUILD_FILE"
2424
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples.sh"
2525
}
26+
{% if custom_samples_dockerfile %}
27+
env_vars: {
28+
key: "TRAMPOLINE_IMAGE"
29+
value: "gcr.io/cloud-devrel-kokoro-resources/{{ metadata['repo']['repo'].split('/')[1] }}-samples-docker"
30+
}
2631

32+
# Configure the docker image for kokoro-trampoline.
33+
env_vars: {
34+
key: "TRAMPOLINE_DOCKERFILE"
35+
value: ".kokoro/docker/samples/Dockerfile"
36+
}
37+
{% else %}
2738
# Configure the docker image for kokoro-trampoline.
2839
env_vars: {
2940
key: "TRAMPOLINE_IMAGE"
3041
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
3142
}
32-
43+
{% endif %}
3344
# Download secrets for samples
3445
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
3546

3647
# Download trampoline resources.
3748
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
3849

3950
# Use the trampoline script to run in docker.
40-
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline.sh"
51+
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline_v2.sh"

synthtool/gcp/templates/python_library/.kokoro/samples/python3.8/periodic-head.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ env_vars: {
99
key: "TRAMPOLINE_BUILD_FILE"
1010
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples-against-head.sh"
1111
}
12+
{% if custom_samples_dockerfile %}
13+
# Upload the docker image after successful builds.
14+
env_vars: {
15+
key: "TRAMPOLINE_IMAGE_UPLOAD"
16+
value: "true"
17+
}
18+
{% endif %}

synthtool/gcp/templates/python_library/.kokoro/samples/python3.8/periodic.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
env_vars: {
44
key: "INSTALL_LIBRARY_FROM_SOURCE"
55
value: "False"
6-
}
6+
}
7+
{% if custom_samples_dockerfile %}
8+
# Upload the docker image after successful builds.
9+
env_vars: {
10+
key: "TRAMPOLINE_IMAGE_UPLOAD"
11+
value: "true"
12+
}
13+
{% endif %}

synthtool/gcp/templates/python_library/.kokoro/samples/python3.9/common.cfg

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,29 @@ env_vars: {
2323
key: "TRAMPOLINE_BUILD_FILE"
2424
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples.sh"
2525
}
26+
{% if custom_samples_dockerfile %}
27+
env_vars: {
28+
key: "TRAMPOLINE_IMAGE"
29+
value: "gcr.io/cloud-devrel-kokoro-resources/{{ metadata['repo']['repo'].split('/')[1] }}-samples-docker"
30+
}
2631

32+
# Configure the docker image for kokoro-trampoline.
33+
env_vars: {
34+
key: "TRAMPOLINE_DOCKERFILE"
35+
value: ".kokoro/docker/samples/Dockerfile"
36+
}
37+
{% else %}
2738
# Configure the docker image for kokoro-trampoline.
2839
env_vars: {
2940
key: "TRAMPOLINE_IMAGE"
3041
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
3142
}
32-
43+
{% endif %}
3344
# Download secrets for samples
3445
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
3546

3647
# Download trampoline resources.
3748
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
3849

3950
# Use the trampoline script to run in docker.
40-
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline.sh"
51+
build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline_v2.sh"

synthtool/gcp/templates/python_library/.kokoro/samples/python3.9/periodic-head.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ env_vars: {
99
key: "TRAMPOLINE_BUILD_FILE"
1010
value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples-against-head.sh"
1111
}
12+
{% if custom_samples_dockerfile %}
13+
# Upload the docker image after successful builds.
14+
env_vars: {
15+
key: "TRAMPOLINE_IMAGE_UPLOAD"
16+
value: "true"
17+
}
18+
{% endif %}

synthtool/gcp/templates/python_library/.kokoro/samples/python3.9/periodic.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
env_vars: {
44
key: "INSTALL_LIBRARY_FROM_SOURCE"
55
value: "False"
6-
}
6+
}
7+
{% if custom_samples_dockerfile %}
8+
# Upload the docker image after successful builds.
9+
env_vars: {
10+
key: "TRAMPOLINE_IMAGE_UPLOAD"
11+
value: "true"
12+
}
13+
{% endif %}

synthtool/gcp/templates/python_library/.kokoro/test-samples-against-head.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ set -eo pipefail
2323
# Enables `**` to include files nested inside sub-folders
2424
shopt -s globstar
2525

26-
cd github/{{ metadata['repo']['repo'].split('/')[1] }}
27-
2826
exec .kokoro/test-samples-impl.sh

synthtool/gcp/templates/python_library/.kokoro/test-samples.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ set -eo pipefail
2424
# Enables `**` to include files nested inside sub-folders
2525
shopt -s globstar
2626

27-
cd github/{{ metadata['repo']['repo'].split('/')[1] }}
28-
2927
# Run periodic samples tests at latest release
3028
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
3129
# preserving the test runner implementation.

synthtool/gcp/templates/python_library/.trampolinerc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,26 @@
1616

1717
# Add required env vars here.
1818
required_envvars+=(
19-
"STAGING_BUCKET"
20-
"V2_STAGING_BUCKET"
2119
)
2220

2321
# Add env vars which are passed down into the container here.
2422
pass_down_envvars+=(
23+
"NOX_SESSION"
24+
###############
25+
# Docs builds
26+
###############
2527
"STAGING_BUCKET"
2628
"V2_STAGING_BUCKET"
27-
"NOX_SESSION"
29+
##################
30+
# Samples builds
31+
##################
32+
"INSTALL_LIBRARY_FROM_SOURCE"
33+
"RUN_TESTS_SESSION"
34+
"BUILD_SPECIFIC_GCLOUD_PROJECT"
35+
# Target directories.
36+
"RUN_TESTS_DIRS"
37+
# The nox session to run.
38+
"RUN_TESTS_SESSION"
2839
)
2940

3041
# Prevent unintentional override on the default image.

0 commit comments

Comments
 (0)