diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6d84c22da6a..5eb62f6a48b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -25,6 +25,7 @@ /billing/**/* @GoogleCloudPlatform/billing-samples-maintainers @GoogleCloudPlatform/python-samples-reviewers /blog/**/* @GoogleCloudPlatform/python-samples-reviewers /cdn/**/* @mpwarres @GoogleCloudPlatform/python-samples-reviewers +/cloudbuild/**/* @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/python-samples-reviewers /cloud-sql/**/* @GoogleCloudPlatform/infra-db-dpes @GoogleCloudPlatform/python-samples-reviewers /codelabs/**/* @GoogleCloudPlatform/python-samples-reviewers /composer/**/* @leahecole @rachael-ds @rafalbiegacz @GoogleCloudPlatform/python-samples-reviewers diff --git a/.github/blunderbuss.yml b/.github/blunderbuss.yml index bc1059f6faa..97dd93b5f3f 100644 --- a/.github/blunderbuss.yml +++ b/.github/blunderbuss.yml @@ -33,6 +33,10 @@ assign_issues_by: - 'api: cloudbilling' to: - GoogleCloudPlatform/billing-samples-maintainers +- labels: + - 'api: cloudbuild' + to: + - GoogleCloudPlatform/torus-dpe - labels: - 'api: cloudsql' to: diff --git a/cloudbuild/AUTHORING_GUIDE.md b/cloudbuild/AUTHORING_GUIDE.md new file mode 100644 index 00000000000..8249522ffc2 --- /dev/null +++ b/cloudbuild/AUTHORING_GUIDE.md @@ -0,0 +1 @@ +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md \ No newline at end of file diff --git a/cloudbuild/CONTRIBUTING.md b/cloudbuild/CONTRIBUTING.md new file mode 100644 index 00000000000..f5fe2e6baf1 --- /dev/null +++ b/cloudbuild/CONTRIBUTING.md @@ -0,0 +1 @@ +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md \ No newline at end of file diff --git a/cloudbuild/snippets/noxfile_config.py b/cloudbuild/snippets/noxfile_config.py new file mode 100644 index 00000000000..adf61a1fa73 --- /dev/null +++ b/cloudbuild/snippets/noxfile_config.py @@ -0,0 +1,40 @@ +# Copyright 2021 Google LLC +# +# 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. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be imported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + # NOTE: We currently only run the test in Python 3.8. + "ignored_versions": ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": True, + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + "envs": { + }, +} diff --git a/cloudbuild/snippets/quickstart.py b/cloudbuild/snippets/quickstart.py new file mode 100644 index 00000000000..e57c9bc5937 --- /dev/null +++ b/cloudbuild/snippets/quickstart.py @@ -0,0 +1,60 @@ +# Copyright 2021 Google LLC +# +# 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. + + +# [START cloudbuild_quickstart] +import google.auth +from google.cloud.devtools import cloudbuild_v1 + + +def quickstart() -> None: + """Create and execute a simple Google Cloud Build configuration, + print the in-progress status and print the completed status.""" + + # Authorize the client with Google defaults + credentials, project_id = google.auth.default() + client = cloudbuild_v1.services.cloud_build.CloudBuildClient() + + # If you're using Private Pools or a non-global default pool, add a regional + # `api_endpoint` to `CloudBuildClient()` + # For example, '-cloudbuild.googleapis.com' + # + # from google.api_core import client_options + # client_options = client_options.ClientOptions( + # api_endpoint="us-central1-cloudbuild.googleapis.com" + # ) + # client = cloudbuild_v1.services.cloud_build.CloudBuildClient(client_options=client_options) + + build = cloudbuild_v1.Build() + + # The following build steps will output "hello world" + # For more information on build configuration, see + # https://cloud.google.com/build/docs/configuring-builds/create-basic-configuration + build.steps = [{"name": "ubuntu", + "entrypoint": "bash", + "args": ["-c", "echo hello world"]}] + + operation = client.create_build(project_id=project_id, build=build) + # Print the in-progress operation + print("IN PROGRESS:") + print(operation.metadata) + + result = operation.result() + # Print the completed status + print("RESULT:", result.status) +# [END cloudbuild_quickstart] + + +if __name__ == "__main__": + quickstart() diff --git a/cloudbuild/snippets/quickstart_test.py b/cloudbuild/snippets/quickstart_test.py new file mode 100644 index 00000000000..ad846a533e0 --- /dev/null +++ b/cloudbuild/snippets/quickstart_test.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google LLC +# +# 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 +# +# https://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. + + +import pytest + +import quickstart + + +def test_quickstart(capsys: pytest.CaptureFixture) -> None: + quickstart.quickstart() + out, _ = capsys.readouterr() + # Prints in-progress message + assert "hello world" in out + # Prints final status + assert "Status.SUCCESS" in out diff --git a/cloudbuild/snippets/requirements-test.txt b/cloudbuild/snippets/requirements-test.txt new file mode 100644 index 00000000000..89cb815c988 --- /dev/null +++ b/cloudbuild/snippets/requirements-test.txt @@ -0,0 +1 @@ +pytest==7.2.0 \ No newline at end of file diff --git a/cloudbuild/snippets/requirements.txt b/cloudbuild/snippets/requirements.txt new file mode 100644 index 00000000000..c48aa8687fa --- /dev/null +++ b/cloudbuild/snippets/requirements.txt @@ -0,0 +1,2 @@ +google-cloud-build==3.9.3 +google-auth==2.14.0 \ No newline at end of file