From 0b65f156c1e9fde402b21bd726c3584ec1d67aa0 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 17:07:18 +0000 Subject: [PATCH 01/36] chore: bake synthtool into library_generation docker image --- library_generation/configuration/synthtool-committish | 1 + 1 file changed, 1 insertion(+) create mode 100644 library_generation/configuration/synthtool-committish diff --git a/library_generation/configuration/synthtool-committish b/library_generation/configuration/synthtool-committish new file mode 100644 index 0000000000..9a47302405 --- /dev/null +++ b/library_generation/configuration/synthtool-committish @@ -0,0 +1 @@ +6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 From a6bb064e5b8b43491ef68b3f1e3d09f3d56845cf Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 18:31:13 +0000 Subject: [PATCH 02/36] remove synthtool usage --- library_generation/README.md | 2 -- .../generate_composed_library.py | 1 - library_generation/model/generation_config.py | 3 -- library_generation/postprocess_library.sh | 31 +++---------------- .../google-cloud-java/generation_config.yaml | 3 +- .../java-bigtable/generation_config.yaml | 1 - .../config_without_temp_excludes.yaml | 1 - .../test-config/generation_config.yaml | 1 - .../test/utilities_unit_tests.py | 5 --- ...generation_config_comparator_unit_tests.py | 14 --------- 10 files changed, 6 insertions(+), 56 deletions(-) diff --git a/library_generation/README.md b/library_generation/README.md index 75fc32695d..c34514cb74 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -92,7 +92,6 @@ They are shared by library level parameters. | grpc_version | No | inferred from the generator if not specified | | googleapis-commitish | Yes | | | owlbot-cli-image | Yes | | -| synthtool-commitish | Yes | | | template_excludes | Yes | | ### Library level parameters @@ -142,7 +141,6 @@ gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 destination_path: google-cloud-java template_excludes: - ".github/*" diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index 4caf0c45ff..005a6f11d2 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -110,7 +110,6 @@ def generate_composed_library( versions_file, owlbot_cli_source_folder, config.owlbot_cli_image, - config.synthtool_commitish, str(config.is_monorepo).lower(), config.path_to_yaml, ], diff --git a/library_generation/model/generation_config.py b/library_generation/model/generation_config.py index 22823b903d..989af140a7 100644 --- a/library_generation/model/generation_config.py +++ b/library_generation/model/generation_config.py @@ -30,7 +30,6 @@ def __init__( gapic_generator_version: str, googleapis_commitish: str, owlbot_cli_image: str, - synthtool_commitish: str, template_excludes: List[str], path_to_yaml: str, libraries: List[LibraryConfig], @@ -40,7 +39,6 @@ def __init__( self.gapic_generator_version = gapic_generator_version self.googleapis_commitish = googleapis_commitish self.owlbot_cli_image = owlbot_cli_image - self.synthtool_commitish = synthtool_commitish self.template_excludes = template_excludes self.path_to_yaml = path_to_yaml self.libraries = libraries @@ -106,7 +104,6 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: protobuf_version=__optional(config, "protobuf_version", None), googleapis_commitish=__required(config, "googleapis_commitish"), owlbot_cli_image=__required(config, "owlbot_cli_image"), - synthtool_commitish=__required(config, "synthtool_commitish"), template_excludes=__required(config, "template_excludes"), path_to_yaml=path_to_yaml, libraries=parsed_libraries, diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index c6a5b4020d..3b42617eb2 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -16,11 +16,9 @@ # 4 - owlbot_cli_source_folder: alternative folder with a structure exactly like # googleapis-gen. It will be used instead of preprocessed_sources_path if # 5 - owlbot_cli_image_sha: SHA of the image containing the OwlBot CLI -# 6 - synthtool_commitish: Commit SHA of the synthtool repo -# provided -# 7 - is_monorepo: whether this library is a monorepo, which implies slightly +# 6 - is_monorepo: whether this library is a monorepo, which implies slightly # different logic -# 8 - configuration_yaml_path: path to the configuration yaml containing library +# 7 - configuration_yaml_path: path to the configuration yaml containing library # generation information for this library set -exo pipefail scripts_root=$(dirname "$(readlink -f "$0")") @@ -30,13 +28,12 @@ preprocessed_sources_path=$2 versions_file=$3 owlbot_cli_source_folder=$4 owlbot_cli_image_sha=$5 -synthtool_commitish=$6 -is_monorepo=$7 -configuration_yaml_path=$8 +is_monorepo=$6 +configuration_yaml_path=$7 source "${scripts_root}"/utilities.sh -declare -a required_inputs=("postprocessing_target" "versions_file" "owlbot_cli_image_sha" "synthtool_commitish" "is_monorepo") +declare -a required_inputs=("postprocessing_target" "versions_file" "owlbot_cli_image_sha" "is_monorepo") for required_input in "${required_inputs[@]}"; do if [[ -z "${!required_input}" ]]; then echo "missing required ${required_input} argument, please specify one" @@ -129,24 +126,6 @@ if [[ "${is_monorepo}" == "true" ]]; then rm "${postprocessing_target}/.OwlBot.hermetic.yaml" fi -# we clone the synthtool library and manually build it -mkdir -p /tmp/synthtool -pushd /tmp/synthtool - -if [ ! -d "synthtool" ]; then - git clone https://github.com/googleapis/synthtool.git -fi -git config --global --add safe.directory /tmp/synthtool/synthtool -pushd "synthtool" - -git fetch --all -git reset --hard "${synthtool_commitish}" - -python3 -m pip install -e . -python3 -m pip install -r requirements.in -popd # synthtool -popd # temp dir - # run the postprocessor echo 'running owl-bot post-processor' pushd "${postprocessing_target}" diff --git a/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml index 839f80996e..1e3be07725 100644 --- a/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml @@ -2,7 +2,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 4ce0ff67a3d4509be641cbe47a35844ddc1268fc owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 5e1fb2032fa44bc170677b38713023b4fec51a4e template_excludes: - ".github/*" - ".kokoro/*" @@ -55,4 +54,4 @@ libraries: api_description: Provides insights about your customers and their Assured Workloads based on your Sovereign Controls by Partners offering. GAPICs: - proto_path: google/cloud/cloudcontrolspartner/v1 - - proto_path: google/cloud/cloudcontrolspartner/v1beta \ No newline at end of file + - proto_path: google/cloud/cloudcontrolspartner/v1beta diff --git a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml index 48afd9eef7..944ee954b7 100644 --- a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml +++ b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml @@ -2,7 +2,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 9868a57470a969ffa1d21194a5c05d7a6e4e98cc owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: a6fb7d5f072b75698af1cbf06c5b001565753cfb template_excludes: - ".gitignore" - ".kokoro/presubmit/integration.cfg" diff --git a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml index 9def2f3be6..8907f96bf7 100644 --- a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml +++ b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.34.0 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 libraries: - api_shortname: apigeeconnect name_pretty: Apigee Connect diff --git a/library_generation/test/resources/test-config/generation_config.yaml b/library_generation/test/resources/test-config/generation_config.yaml index d84ed3afd2..c2744c14b6 100644 --- a/library_generation/test/resources/test-config/generation_config.yaml +++ b/library_generation/test/resources/test-config/generation_config.yaml @@ -2,7 +2,6 @@ gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 template_excludes: - ".github/*" - ".kokoro/*" diff --git a/library_generation/test/utilities_unit_tests.py b/library_generation/test/utilities_unit_tests.py index 3d114f977f..cfecf61911 100644 --- a/library_generation/test/utilities_unit_tests.py +++ b/library_generation/test/utilities_unit_tests.py @@ -146,7 +146,6 @@ def test_eprint_valid_input_succeeds(self): f"{test_config_dir}/config_without_googleapis.yaml", ), ("owlbot_cli_image", f"{test_config_dir}/config_without_owlbot.yaml"), - ("synthtool_commitish", f"{test_config_dir}/config_without_synthtool.yaml"), ( "template_excludes", f"{test_config_dir}/config_without_temp_excludes.yaml", @@ -172,9 +171,6 @@ def test_from_yaml_succeeds(self): "sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409", config.owlbot_cli_image, ) - self.assertEqual( - "6612ab8f3afcd5e292aecd647f0fa68812c9f5b5", config.synthtool_commitish - ) self.assertEqual( [ ".github/*", @@ -526,7 +522,6 @@ def __get_a_gen_config( gapic_generator_version="", googleapis_commitish="", owlbot_cli_image="", - synthtool_commitish="", template_excludes=[ ".github/*", ".kokoro/*", diff --git a/library_generation/test/utils/generation_config_comparator_unit_tests.py b/library_generation/test/utils/generation_config_comparator_unit_tests.py index c2c025c579..cd7d925310 100644 --- a/library_generation/test/utils/generation_config_comparator_unit_tests.py +++ b/library_generation/test/utils/generation_config_comparator_unit_tests.py @@ -40,7 +40,6 @@ def setUp(self) -> None: gapic_generator_version="", googleapis_commitish="", owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -51,7 +50,6 @@ def setUp(self) -> None: gapic_generator_version="", googleapis_commitish="", owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -103,18 +101,6 @@ def test_compare_config_owlbot_cli_update(self): self.assertEqual("owlbot_cli_image", config_change.changed_param) self.assertEqual("image_version_456", config_change.latest_value) - def test_compare_config_synthtool_update(self): - self.baseline_config.synthtool_commitish = "commit123" - self.latest_config.synthtool_commitish = "commit456" - result = compare_config( - baseline_config=self.baseline_config, - latest_config=self.latest_config, - ) - self.assertTrue(len(result[ChangeType.REPO_LEVEL_CHANGE]) == 1) - config_change = result[ChangeType.REPO_LEVEL_CHANGE][0] - self.assertEqual("synthtool_commitish", config_change.changed_param) - self.assertEqual("commit456", config_change.latest_value) - def test_compare_protobuf_update(self): self.baseline_config.protobuf_version = "3.25.2" self.latest_config.protobuf_version = "3.27.0" From d4f27e27fb57bfd26ca71f4245e416389aa24d5f Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 18:18:05 +0000 Subject: [PATCH 03/36] do not use config file --- library_generation/configuration/synthtool-committish | 1 - 1 file changed, 1 deletion(-) delete mode 100644 library_generation/configuration/synthtool-committish diff --git a/library_generation/configuration/synthtool-committish b/library_generation/configuration/synthtool-committish deleted file mode 100644 index 9a47302405..0000000000 --- a/library_generation/configuration/synthtool-committish +++ /dev/null @@ -1 +0,0 @@ -6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 From 19a0b0405a3c54a07fcf6b6deb1f58e7c8ce5ce3 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 18:24:18 +0000 Subject: [PATCH 04/36] bake synthtool in dockerfile --- .../library_generation.Dockerfile | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 4b3b1f4b1c..d26a7f360e 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -14,22 +14,35 @@ # build from the root of this repo: FROM gcr.io/cloud-devrel-public-resources/python +ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 -# install tools +# install OS tools RUN apt-get update && apt-get install -y \ unzip openjdk-17-jdk rsync maven jq \ && apt-get clean +# copy source code COPY library_generation /src +# install synthtool +WORKDIR /synthtool +RUN git clone https://github.com/googleapis/synthtool +WORKDIR /synthtool/synthtool +RUN git checkout "${SYNTHTOOL_COMMITTISH}" +RUN python3 -m pip install --no-deps -e . +RUN python3 -m pip install -r requirements.in + + +# use python 3.11 (the base image has several python versions; here we define the default one) RUN rm $(which python3) RUN ln -s $(which python3.11) /usr/local/bin/python RUN ln -s $(which python3.11) /usr/local/bin/python3 RUN python -m pip install --upgrade pip -RUN cd /src && python -m pip install -r requirements.in -RUN cd /src && python -m pip install . +WORKDIR /src +RUN python -m pip install -r requirements.in +RUN python -m pip install . -# set dummy git credentials for empty commit used in postprocessing +# set dummy git credentials for the empty commit used in postprocessing RUN git config --global user.email "cloud-java-bot@google.com" RUN git config --global user.name "Cloud Java Bot" @@ -37,4 +50,6 @@ WORKDIR /workspace RUN chmod 750 /workspace RUN chmod 750 /src/generate_repo.py +# define runtime env vars +ENV RUNNING_IN_DOCKER=true CMD [ "/src/generate_repo.py" ] From bc693b5090051c324a6b22c9379cd1c145bb07fc Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:18:10 +0000 Subject: [PATCH 05/36] bake copy-code into the image --- .../library_generation.Dockerfile | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index d26a7f360e..554525ff05 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -14,7 +14,13 @@ # build from the root of this repo: FROM gcr.io/cloud-devrel-public-resources/python + ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 +ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 + +# build the image using bash +RUN echo ~ +SHELL ["/bin/bash", "--login", "-c"] # install OS tools RUN apt-get update && apt-get install -y \ @@ -25,13 +31,29 @@ RUN apt-get update && apt-get install -y \ COPY library_generation /src # install synthtool -WORKDIR /synthtool +WORKDIR /tools RUN git clone https://github.com/googleapis/synthtool -WORKDIR /synthtool/synthtool +WORKDIR /tools/synthtool RUN git checkout "${SYNTHTOOL_COMMITTISH}" RUN python3 -m pip install --no-deps -e . RUN python3 -m pip install -r requirements.in +# install node +ENV NODE_VERSION 20.12.0 +# Install nvm with node and npm +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash +RUN ls /root/.nvm +ENV PATH=${PATH}:/root/.nvm/versions/node/v${NODE_VERSION}/bin +RUN node --version +RUN npm --version + +# install the owl-bot CLI +WORKDIR /tools +RUN git clone https://github.com/googleapis/repo-automation-bots +WORKDIR /tools/repo-automation-bots/packages/owl-bot +RUN npm i && npm run compile && npm link +RUN owl-bot copy-code --version + # use python 3.11 (the base image has several python versions; here we define the default one) RUN rm $(which python3) From f335cbbb5aae7df7a055967c90f3be7c5fe9a5fe Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:23:06 +0000 Subject: [PATCH 06/36] remove unnecessary SHELL statement --- .cloudbuild/library_generation/library_generation.Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 554525ff05..73c3db850f 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -18,10 +18,6 @@ FROM gcr.io/cloud-devrel-public-resources/python ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 -# build the image using bash -RUN echo ~ -SHELL ["/bin/bash", "--login", "-c"] - # install OS tools RUN apt-get update && apt-get install -y \ unzip openjdk-17-jdk rsync maven jq \ From aab50efab3a47487c5ac48ded29a24bc0525aa9c Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:25:29 +0000 Subject: [PATCH 07/36] add info for installing synthtool --- library_generation/DEVELOPMENT.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 library_generation/DEVELOPMENT.md diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md new file mode 100644 index 0000000000..ce04ff5d63 --- /dev/null +++ b/library_generation/DEVELOPMENT.md @@ -0,0 +1,17 @@ +# Local Development +## Installing prerequisites +### Install synthtool +```bash +git clone https://github.com/googleapis/synthtool +cd synthtool +python3 -m pip install --require-hashes -r requirements.txt +python3 -m pip install --no-deps -e . +python -m synthtool --version +``` +### Install the owl-bot CLI +```bash +git clone https://github.com/googleapis/repo-automation-bots +cd repo-automation-bots/packages/owl-bot +npm i && npm run compile && npm link +owl-bot copy-code --version +``` From f97cdca1f47c7ca0305483ef492eb9fa71ae2e5a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:36:31 +0000 Subject: [PATCH 08/36] modify owl-bot usage in postprocess_library --- library_generation/postprocess_library.sh | 39 +++-------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index 3b42617eb2..6329910854 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -80,47 +80,17 @@ else fi # Default values for running copy-code directly from host -repo_bindings="-v ${postprocessing_target}:/workspace" repo_workspace="/workspace" preprocessed_libraries_binding="${owlbot_cli_source_folder}" -# When running docker inside docker, we run into the issue of volume bindings -# being mapped from the host machine to the child container (instead of the -# parent container to child container) because we bind the `docker.sock` socket -# to the parent container (i.e. docker calls use the host's filesystem context) -# see https://serverfault.com/a/819371 -# We solve this by referencing environment variables that will be -# set to produce the correct volume mapping. -# -# The workflow is: to check if we are in a docker container (via passed env var) -# and use managed volumes (docker volume create) instead of bindings -# (-v /path:/other-path). The volume names are also received as env vars. - -if [[ -n "${RUNNING_IN_DOCKER}" ]]; then - set -u # temporarily fail on unset variables - repo_bindings="${REPO_BINDING_VOLUMES}" - set +u - library_name=$(echo "${postprocessing_target}" | rev | cut -d'/' -f1 | rev) - repo_workspace="/workspace/" - if [[ "${is_monorepo}" == "true" ]]; then - monorepo_name=$(echo "${postprocessing_target}" | rev | cut -d'/' -f2 | rev) - repo_workspace+="${monorepo_name}/" - fi - repo_workspace+="${library_name}" -fi +pushd "${postprocessing_target}" -docker run --rm \ - --user "$(id -u)":"$(id -g)" \ - ${repo_bindings} \ - -v "/tmp:/tmp" \ - -w "${repo_workspace}" \ - --env HOME=/tmp \ - gcr.io/cloud-devrel-public-resources/owlbot-cli@"${owlbot_cli_image_sha}" \ - copy-code \ +owl-bot copy-code \ --source-repo-commit-hash=none \ - --source-repo="${preprocessed_libraries_binding}" \ + --source-repo="${owlbot_cli_source_folder}" \ --config-file="${owlbot_yaml_relative_path}" + # clean the custom owlbot yaml if [[ "${is_monorepo}" == "true" ]]; then rm "${postprocessing_target}/.OwlBot.hermetic.yaml" @@ -128,6 +98,5 @@ fi # run the postprocessor echo 'running owl-bot post-processor' -pushd "${postprocessing_target}" bash "${scripts_root}/owlbot/bin/entrypoint.sh" "${scripts_root}" "${versions_file}" "${configuration_yaml_path}" popd # postprocessing_target From eca0d9208497fb832bffc9b603fef41a3cf8ea3e Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 15:39:23 +0000 Subject: [PATCH 09/36] fix synthtool installation --- .../library_generation.Dockerfile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 84aa8fee33..5f705c9c05 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -23,9 +23,20 @@ RUN apt-get update && apt-get install -y \ unzip openjdk-17-jdk rsync maven jq \ && apt-get clean +# use python 3.11 (the base image has several python versions; here we define the default one) +RUN rm $(which python3) +RUN ln -s $(which python3.11) /usr/local/bin/python +RUN ln -s $(which python3.11) /usr/local/bin/python3 +RUN python -m pip install --upgrade pip + # copy source code COPY library_generation /src +# install scripts as a python package +WORKDIR /src +RUN python -m pip install -r requirements.txt +RUN python -m pip install . + # install synthtool WORKDIR /tools RUN git clone https://github.com/googleapis/synthtool @@ -51,14 +62,6 @@ RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version -# use python 3.11 (the base image has several python versions; here we define the default one) -RUN rm $(which python3) -RUN ln -s $(which python3.11) /usr/local/bin/python -RUN ln -s $(which python3.11) /usr/local/bin/python3 -RUN python -m pip install --upgrade pip -WORKDIR /src -RUN python -m pip install -r requirements.txt -RUN python -m pip install . # set dummy git credentials for the empty commit used in postprocessing RUN git config --global user.email "cloud-java-bot@google.com" From 6aa85331aa56256fcea5b36b753288af94fed64b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 15:55:47 +0000 Subject: [PATCH 10/36] change permissions to script folder --- .../library_generation/library_generation.Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 5f705c9c05..3ca29b45e8 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -61,15 +61,15 @@ WORKDIR /tools/repo-automation-bots/packages/owl-bot RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version - +# allow users to access the script folders +RUN chmod -R 755 /src # set dummy git credentials for the empty commit used in postprocessing RUN git config --global user.email "cloud-java-bot@google.com" RUN git config --global user.name "Cloud Java Bot" WORKDIR /workspace -RUN chmod 750 /workspace -RUN chmod 750 /src/generate_repo.py +RUN chmod 755 /workspace # define runtime env vars ENV RUNNING_IN_DOCKER=true From 53c5deaa9485ad342d3eee9184b5fbba327b7e75 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 17:41:46 +0000 Subject: [PATCH 11/36] assume location of generation_config.yaml --- library_generation/generate_repo.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index a15cfb5f2a..2c78bc31b2 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -12,6 +12,7 @@ # 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 os import click as click import library_generation.utils.utilities as util from library_generation.generate_composed_library import generate_composed_library @@ -30,11 +31,12 @@ def main(ctx): @main.command() @click.option( "--generation-config-yaml", - required=True, + required=False, type=str, help=""" Path to generation_config.yaml that contains the metadata about - library generation + library generation. If not specified, it will be assumed to be found + at the root of --repository-path """, ) @click.option( @@ -72,6 +74,8 @@ def generate( target_library_names: str, repository_path: str, ): + if generation_config_yaml is None: + generation_config_yaml = os.path.join(repository_path, 'generation_config.yaml') config = from_yaml(generation_config_yaml) generate_from_yaml( config=config, From cc4309ba58e00b7c98554a1d4e9b39d66d2c2e6f Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 21:05:50 +0000 Subject: [PATCH 12/36] fix permissions --- .../library_generation.Dockerfile | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 3ca29b45e8..bb305e7786 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -17,10 +17,11 @@ FROM gcr.io/cloud-devrel-public-resources/python ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 +ENV HOME=/home # install OS tools RUN apt-get update && apt-get install -y \ - unzip openjdk-17-jdk rsync maven jq \ + unzip openjdk-17-jdk rsync maven jq less vim \ && apt-get clean # use python 3.11 (the base image has several python versions; here we define the default one) @@ -45,12 +46,13 @@ RUN git checkout "${SYNTHTOOL_COMMITTISH}" RUN python3 -m pip install --no-deps -e . RUN python3 -m pip install -r requirements.in -# install node -ENV NODE_VERSION 20.12.0 # Install nvm with node and npm +ENV NODE_VERSION 20.12.0 +WORKDIR /home RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash -RUN ls /root/.nvm -ENV PATH=${PATH}:/root/.nvm/versions/node/v${NODE_VERSION}/bin +RUN chmod 755 /home/.nvm +ENV NODE_PATH=/home/.nvm/versions/node/v${NODE_VERSION}/bin +ENV PATH=${PATH}:${NODE_PATH} RUN node --version RUN npm --version @@ -60,17 +62,23 @@ RUN git clone https://github.com/googleapis/repo-automation-bots WORKDIR /tools/repo-automation-bots/packages/owl-bot RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version +RUN chmod -R 755 ${NODE_PATH} +RUN ln -sf ${NODE_PATH}/* /usr/local/bin # allow users to access the script folders RUN chmod -R 755 /src # set dummy git credentials for the empty commit used in postprocessing -RUN git config --global user.email "cloud-java-bot@google.com" -RUN git config --global user.name "Cloud Java Bot" +# we use system so all users using the container will use this configuration +RUN git config --system user.email "cloud-java-bot@google.com" +RUN git config --system user.name "Cloud Java Bot" +RUN touch /home/.gitconfig -WORKDIR /workspace -RUN chmod 755 /workspace +# allow read-write for /home/.gitconfig and execution for binaries in /home/.nvm +RUN chmod -R 757 /home # define runtime env vars ENV RUNNING_IN_DOCKER=true -CMD [ "/src/generate_repo.py" ] + +WORKDIR /workspace +ENTRYPOINT [ "python", "/src/generate_repo.py", "generate" ] From 7a4b6b82038c5f9a11702f5ef91f4da1126456c5 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 21:17:34 +0000 Subject: [PATCH 13/36] fix path to config yaml --- library_generation/generate_repo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 2c78bc31b2..cf1c19772b 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -19,6 +19,7 @@ from library_generation.model.generation_config import GenerationConfig, from_yaml from library_generation.model.library_config import LibraryConfig from library_generation.utils.monorepo_postprocessor import monorepo_postprocessing +from pathlib import Path @click.group(invoke_without_command=False) @@ -75,7 +76,7 @@ def generate( repository_path: str, ): if generation_config_yaml is None: - generation_config_yaml = os.path.join(repository_path, 'generation_config.yaml') + generation_config_yaml = str(Path(os.path.join(repository_path, 'generation_config.yaml')).resolve()) config = from_yaml(generation_config_yaml) generate_from_yaml( config=config, From 4838d5b3b09b04c40ed31e93172f86f4ff29cf50 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 14:30:34 +0000 Subject: [PATCH 14/36] use entrypoint for docker image --- .../library_generation.Dockerfile | 2 +- library_generation/test/integration_tests.py | 46 ++++++------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index bb305e7786..881cee4f0a 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -81,4 +81,4 @@ RUN chmod -R 757 /home ENV RUNNING_IN_DOCKER=true WORKDIR /workspace -ENTRYPOINT [ "python", "/src/generate_repo.py", "generate" ] +ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ] diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 2c356d24a1..95c66ff84b 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -57,31 +57,25 @@ def test_entry_point_running_in_container(self): config_files = self.__get_config_files(config_dir) for repo, config_file in config_files: config = from_yaml(config_file) + repo_location=f"{output_dir}/{repo}" + config_location=f"{golden_dir}/../{repo}" # 1. pull repository repo_dest = self.__pull_repo_to( - Path(f"{output_dir}/{repo}"), repo, committish_map[repo] + Path(repo_location), repo, committish_map[repo] ) # 2. prepare golden files library_names = self.__get_library_names_from_config(config) self.__prepare_golden_files( config=config, library_names=library_names, repo_dest=repo_dest ) - # 3. bind repository and configuration to docker volumes - self.__bind_device_to_volumes( - volume_name=f"repo-{repo}", device_dir=f"{output_dir}/{repo}" - ) - self.__bind_device_to_volumes( - volume_name=f"config-{repo}", device_dir=f"{golden_dir}/../{repo}" - ) - repo_volumes = f"-v repo-{repo}:/workspace/{repo} -v config-{repo}:/workspace/config-{repo}" - # 4. run entry_point.py in docker container + # 3. run entry_point.py in docker container self.__run_entry_point_in_docker_container( - repo=repo, - repo_volumes=repo_volumes, + repo_location=repo_location, + config_location=config_location, baseline_config=baseline_config_name, current_config=current_config_name, ) - # 5. compare generation result with golden files + # 4. compare generation result with golden files print( "Generation finished successfully. " "Will now compare differences between generated and existing " @@ -241,8 +235,8 @@ def __bind_device_to_volumes(cls, volume_name: str, device_dir: str): @classmethod def __run_entry_point_in_docker_container( cls, - repo: str, - repo_volumes: str, + repo_location: str, + config_location: str, baseline_config: str, current_config: str, ): @@ -252,26 +246,14 @@ def __run_entry_point_in_docker_container( "run", "--rm", "-v", - f"repo-{repo}:/workspace/{repo}", - "-v", - f"config-{repo}:/workspace/config-{repo}", - "-v", - "/tmp:/tmp", + f"{repo_location}:/workspace/repo", "-v", - "/var/run/docker.sock:/var/run/docker.sock", - "-e", - "RUNNING_IN_DOCKER=true", - "-e", - f"REPO_BINDING_VOLUMES={repo_volumes}", + f"{config_location}:/workspace/config", "-w", - "/src", + "/workspace/repo", image_tag, - "python", - "/src/cli/entry_point.py", - "generate", - f"--baseline-generation-config=/workspace/config-{repo}/{baseline_config}", - f"--current-generation-config=/workspace/config-{repo}/{current_config}", - f"--repository-path=/workspace/{repo}", + f"--baseline-generation-config=/workspace/config/{baseline_config}", + f"--current-generation-config=/workspace/config/{current_config}", ] ) From 1b01713d3aea95d009366a8b0d518251496e1d06 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 14:31:03 +0000 Subject: [PATCH 15/36] format --- library_generation/generate_repo.py | 4 +++- library_generation/test/integration_tests.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index cf1c19772b..7a3689364f 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -76,7 +76,9 @@ def generate( repository_path: str, ): if generation_config_yaml is None: - generation_config_yaml = str(Path(os.path.join(repository_path, 'generation_config.yaml')).resolve()) + generation_config_yaml = str( + Path(os.path.join(repository_path, "generation_config.yaml")).resolve() + ) config = from_yaml(generation_config_yaml) generate_from_yaml( config=config, diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 95c66ff84b..4c0a0d37cb 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -57,8 +57,8 @@ def test_entry_point_running_in_container(self): config_files = self.__get_config_files(config_dir) for repo, config_file in config_files: config = from_yaml(config_file) - repo_location=f"{output_dir}/{repo}" - config_location=f"{golden_dir}/../{repo}" + repo_location = f"{output_dir}/{repo}" + config_location = f"{golden_dir}/../{repo}" # 1. pull repository repo_dest = self.__pull_repo_to( Path(repo_location), repo, committish_map[repo] From c1494613531591acec2fbb7a8862f32967c0254b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 15:07:59 +0000 Subject: [PATCH 16/36] finish development guide --- library_generation/DEVELOPMENT.md | 90 +++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index ce04ff5d63..4e161debc6 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -1,17 +1,101 @@ -# Local Development +# Linting + +When contributing, ensure your changes to python code have a valid +format. + +``` +python -m pip install black +black library_generation +``` + +# Running the integration tests + +The integration tests build the docker image declared in +`.cloudbuild/library_generation/library_generation.Dockerfile`, pull GAPIC +repositories, generate the libraries and compares the results with the source +code declared in a "golden branch" of the repo. + +It requires docker and python 3.x to be installed. + +``` +cd library_generation +python -m pip install . +python -m pip install -r requirements.txt +python -m unittest test/integration_tests.py +``` + +# Running the scripts in your local environment + +Although the scripts are designed to be run in a Docker container, you can also +run them directly. This section explains how to run the entrypoint script +(`library_generation/cli/entry_point.py`). + ## Installing prerequisites + +In order to run the generation scripts directly, there are a few tools we +need to install beforehand. + ### Install synthtool + +It requires python 3.x to be installed. +You will need to specify a committish of the synthtool repo in order to have +your generation results matching exactly what the docker image would produce. +You can achieve this by inspecting `SYNTHTOOL_COMMITISH` in +`.cloudbuild/library_generation/library_generation.Dockerfile`. + +```bash +# obtained from .cloudbuild/library_generation/library_generation.Dockerfile +export SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 +``` + ```bash git clone https://github.com/googleapis/synthtool cd synthtool -python3 -m pip install --require-hashes -r requirements.txt -python3 -m pip install --no-deps -e . +git checkout "${SYNTHTOOL_COMMITTISH}" +python -m pip install --require-hashes -r requirements.txt +python -m pip install --no-deps -e . python -m synthtool --version ``` + ### Install the owl-bot CLI + +Requires node.js to be installed. +Check this [installation guide](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script) +for NVM, Node.js's version manager. + +After you install it, you can install the owl-bot CLI with the following +commands: ```bash git clone https://github.com/googleapis/repo-automation-bots cd repo-automation-bots/packages/owl-bot npm i && npm run compile && npm link owl-bot copy-code --version ``` + +The key step is `npm link`, which will make the command available in you current +shell session. + +## Running the script +The entrypoint script (`library_generation/cli/entry_point.py`) allows you to +update the target repository with the latest changes starting from the +googleapis committish declared in `generation_config.yaml`. + +### Download the repo +For example, google-cloud-java +``` +git clone https://github.com/googleapis/google-cloud-java +export path_to_repo="$(pwd)/google-cloud-java" +``` + +### Install the scripts +``` +cd library_generation +python -m pip install . +``` + +### Run the script +``` +cd library_generation +python cli/entry_point.py --repository-path "${path_to_repo}" +``` + From 4ee16928b1290701a4b81b2f923ddb23842a1bfd Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 15:29:34 +0000 Subject: [PATCH 17/36] remove olwbot_cli usage --- library_generation/README.md | 1 - library_generation/generate_composed_library.py | 1 - library_generation/model/generation_config.py | 3 --- library_generation/postprocess_library.sh | 10 ++++------ .../test/generate_repo_unit_tests.py | 2 -- .../test/model/config_change_unit_tests.py | 2 -- .../baseline_generation_config.yaml | 4 +--- .../current_generation_config.yaml | 1 - .../java-bigtable/generation_config.yaml | 1 - .../test-config/config_without_owlbot.yaml | 9 --------- .../test-config/config_without_synthtool.yaml | 10 ---------- .../config_without_temp_excludes.yaml | 1 - .../resources/test-config/generation_config.yaml | 1 - library_generation/test/utilities_unit_tests.py | 6 ------ .../generation_config_comparator_unit_tests.py | 16 ---------------- 15 files changed, 5 insertions(+), 63 deletions(-) delete mode 100644 library_generation/test/resources/test-config/config_without_owlbot.yaml delete mode 100644 library_generation/test/resources/test-config/config_without_synthtool.yaml diff --git a/library_generation/README.md b/library_generation/README.md index 02775a4dee..52ebefcdd4 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -146,7 +146,6 @@ The GAPIC level parameters define how to generate a GAPIC library. gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 destination_path: google-cloud-java template_excludes: - ".github/*" diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index fdf708cd4b..757fa044e3 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -109,7 +109,6 @@ def generate_composed_library( "", versions_file, owlbot_cli_source_folder, - config.owlbot_cli_image, str(config.is_monorepo).lower(), config.path_to_yaml, ], diff --git a/library_generation/model/generation_config.py b/library_generation/model/generation_config.py index 03c2c2b7ec..d05925878d 100644 --- a/library_generation/model/generation_config.py +++ b/library_generation/model/generation_config.py @@ -29,7 +29,6 @@ def __init__( self, gapic_generator_version: str, googleapis_commitish: str, - owlbot_cli_image: str, template_excludes: List[str], path_to_yaml: str, libraries: List[LibraryConfig], @@ -38,7 +37,6 @@ def __init__( ): self.gapic_generator_version = gapic_generator_version self.googleapis_commitish = googleapis_commitish - self.owlbot_cli_image = owlbot_cli_image self.template_excludes = template_excludes self.path_to_yaml = path_to_yaml self.libraries = libraries @@ -115,7 +113,6 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: grpc_version=__optional(config, "grpc_version", None), protobuf_version=__optional(config, "protobuf_version", None), googleapis_commitish=__required(config, "googleapis_commitish"), - owlbot_cli_image=__required(config, "owlbot_cli_image"), template_excludes=__required(config, "template_excludes"), path_to_yaml=path_to_yaml, libraries=parsed_libraries, diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index 725afccd1e..f701c6ab4b 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -15,10 +15,9 @@ # 3 - versions_file: path to file containing versions to be applied to the poms # 4 - owlbot_cli_source_folder: alternative folder with a structure exactly like # googleapis-gen. It will be used instead of preprocessed_sources_path if -# 5 - owlbot_cli_image_sha: SHA of the image containing the OwlBot CLI -# 6 - is_monorepo: whether this library is a monorepo, which implies slightly +# 5 - is_monorepo: whether this library is a monorepo, which implies slightly # different logic -# 7 - configuration_yaml_path: path to the configuration yaml containing library +# 6 - configuration_yaml_path: path to the configuration yaml containing library # generation information for this library set -exo pipefail scripts_root=$(dirname "$(readlink -f "$0")") @@ -27,9 +26,8 @@ postprocessing_target=$1 preprocessed_sources_path=$2 versions_file=$3 owlbot_cli_source_folder=$4 -owlbot_cli_image_sha=$5 -is_monorepo=$6 -configuration_yaml_path=$7 +is_monorepo=$5 +configuration_yaml_path=$6 source "${scripts_root}"/utils/utilities.sh diff --git a/library_generation/test/generate_repo_unit_tests.py b/library_generation/test/generate_repo_unit_tests.py index db8cb4eb63..10deefa101 100644 --- a/library_generation/test/generate_repo_unit_tests.py +++ b/library_generation/test/generate_repo_unit_tests.py @@ -45,8 +45,6 @@ def __get_an_empty_generation_config() -> GenerationConfig: return GenerationConfig( gapic_generator_version="", googleapis_commitish="", - synthtool_commitish="", - owlbot_cli_image="", template_excludes=[], path_to_yaml="", libraries=[], diff --git a/library_generation/test/model/config_change_unit_tests.py b/library_generation/test/model/config_change_unit_tests.py index 5df6e8b021..6fe111db35 100644 --- a/library_generation/test/model/config_change_unit_tests.py +++ b/library_generation/test/model/config_change_unit_tests.py @@ -239,8 +239,6 @@ def __get_a_gen_config( return GenerationConfig( gapic_generator_version="", googleapis_commitish=googleapis_commitish, - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], path_to_yaml="", grpc_version="", diff --git a/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml index ad9eafb31e..ab2b9c3100 100644 --- a/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml @@ -1,8 +1,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: a17d4caf184b050d50cacf2b0d579ce72c31ce74 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 5e1fb2032fa44bc170677b38713023b4fec51a4e template_excludes: - ".github/*" - ".kokoro/*" @@ -55,4 +53,4 @@ libraries: api_description: Provides insights about your customers and their Assured Workloads based on your Sovereign Controls by Partners offering. GAPICs: - proto_path: google/cloud/cloudcontrolspartner/v1 - - proto_path: google/cloud/cloudcontrolspartner/v1beta \ No newline at end of file + - proto_path: google/cloud/cloudcontrolspartner/v1beta diff --git a/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml index 1e3be07725..d1d601b0a3 100644 --- a/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 4ce0ff67a3d4509be641cbe47a35844ddc1268fc -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 template_excludes: - ".github/*" - ".kokoro/*" diff --git a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml index 944ee954b7..3d9545ad6a 100644 --- a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml +++ b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 9868a57470a969ffa1d21194a5c05d7a6e4e98cc -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 template_excludes: - ".gitignore" - ".kokoro/presubmit/integration.cfg" diff --git a/library_generation/test/resources/test-config/config_without_owlbot.yaml b/library_generation/test/resources/test-config/config_without_owlbot.yaml deleted file mode 100644 index 7921f68bd2..0000000000 --- a/library_generation/test/resources/test-config/config_without_owlbot.yaml +++ /dev/null @@ -1,9 +0,0 @@ -gapic_generator_version: 2.34.0 -googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -libraries: - - api_shortname: apigeeconnect - name_pretty: Apigee Connect - api_description: "allows the Apigee hybrid management" - product_documentation: "https://cloud.google.com/apigee/docs/hybrid/v1.3/apigee-connect/" - GAPICs: - - proto_path: google/cloud/apigeeconnect/v1 diff --git a/library_generation/test/resources/test-config/config_without_synthtool.yaml b/library_generation/test/resources/test-config/config_without_synthtool.yaml deleted file mode 100644 index 8907f96bf7..0000000000 --- a/library_generation/test/resources/test-config/config_without_synthtool.yaml +++ /dev/null @@ -1,10 +0,0 @@ -gapic_generator_version: 2.34.0 -googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -libraries: - - api_shortname: apigeeconnect - name_pretty: Apigee Connect - api_description: "allows the Apigee hybrid management" - product_documentation: "https://cloud.google.com/apigee/docs/hybrid/v1.3/apigee-connect/" - GAPICs: - - proto_path: google/cloud/apigeeconnect/v1 diff --git a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml index 8907f96bf7..7921f68bd2 100644 --- a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml +++ b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml @@ -1,6 +1,5 @@ gapic_generator_version: 2.34.0 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 libraries: - api_shortname: apigeeconnect name_pretty: Apigee Connect diff --git a/library_generation/test/resources/test-config/generation_config.yaml b/library_generation/test/resources/test-config/generation_config.yaml index c2744c14b6..22dad91ca3 100644 --- a/library_generation/test/resources/test-config/generation_config.yaml +++ b/library_generation/test/resources/test-config/generation_config.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 template_excludes: - ".github/*" - ".kokoro/*" diff --git a/library_generation/test/utilities_unit_tests.py b/library_generation/test/utilities_unit_tests.py index 4076137265..487dec8b87 100644 --- a/library_generation/test/utilities_unit_tests.py +++ b/library_generation/test/utilities_unit_tests.py @@ -143,7 +143,6 @@ def test_eprint_valid_input_succeeds(self): "googleapis_commitish", f"{test_config_dir}/config_without_googleapis.yaml", ), - ("owlbot_cli_image", f"{test_config_dir}/config_without_owlbot.yaml"), ( "template_excludes", f"{test_config_dir}/config_without_temp_excludes.yaml", @@ -165,10 +164,6 @@ def test_from_yaml_succeeds(self): self.assertEqual( "1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish ) - self.assertEqual( - "sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409", - config.owlbot_cli_image, - ) self.assertEqual( [ ".github/*", @@ -477,7 +472,6 @@ def __get_a_gen_config( return GenerationConfig( gapic_generator_version="", googleapis_commitish="", - owlbot_cli_image="", template_excludes=[ ".github/*", ".kokoro/*", diff --git a/library_generation/test/utils/generation_config_comparator_unit_tests.py b/library_generation/test/utils/generation_config_comparator_unit_tests.py index 1c25854c1f..53d4092e60 100644 --- a/library_generation/test/utils/generation_config_comparator_unit_tests.py +++ b/library_generation/test/utils/generation_config_comparator_unit_tests.py @@ -39,7 +39,6 @@ def setUp(self) -> None: self.baseline_config = GenerationConfig( gapic_generator_version="", googleapis_commitish="", - owlbot_cli_image="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -49,7 +48,6 @@ def setUp(self) -> None: self.latest_config = GenerationConfig( gapic_generator_version="", googleapis_commitish="", - owlbot_cli_image="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -91,20 +89,6 @@ def test_compare_config_generator_update(self): self.assertEqual("gapic_generator_version", config_change.changed_param) self.assertEqual("1.2.4", config_change.current_value) - def test_compare_config_owlbot_cli_update(self): - self.baseline_config.owlbot_cli_image = "image_version_123" - self.latest_config.owlbot_cli_image = "image_version_456" - result = compare_config( - baseline_config=self.baseline_config, - current_config=self.latest_config, - ) - self.assertTrue( - len(result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE]) == 1 - ) - config_change = result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE][0] - self.assertEqual("owlbot_cli_image", config_change.changed_param) - self.assertEqual("image_version_456", config_change.current_value) - def test_compare_protobuf_update(self): self.baseline_config.protobuf_version = "3.25.2" self.latest_config.protobuf_version = "3.27.0" From e77bacc667a47e837c8847deee8db97a643469aa Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 17 Apr 2024 15:22:44 +0000 Subject: [PATCH 18/36] add entrypoint for docker image --- .cloudbuild/library_generation/entrypoint.sh | 8 ++++++++ .../library_generation.Dockerfile | 18 +++++++++--------- library_generation/generate_library.sh | 2 +- library_generation/postprocess_library.sh | 2 +- library_generation/test/integration_tests.py | 8 +++++++- 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 .cloudbuild/library_generation/entrypoint.sh diff --git a/.cloudbuild/library_generation/entrypoint.sh b/.cloudbuild/library_generation/entrypoint.sh new file mode 100644 index 0000000000..5350becc24 --- /dev/null +++ b/.cloudbuild/library_generation/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# wrapper script for the hermetic build cli entrypoint that sets environment +# variables that can be read by any user calling the container +set -ex +export HOME=/home +export MAVEN_HOME=/home/.m2 +python /src/cli/entry_point.py generate $@ + diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 881cee4f0a..f26ee13133 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -50,7 +50,7 @@ RUN python3 -m pip install -r requirements.in ENV NODE_VERSION 20.12.0 WORKDIR /home RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash -RUN chmod 755 /home/.nvm +RUN chmod o+rx /home/.nvm ENV NODE_PATH=/home/.nvm/versions/node/v${NODE_VERSION}/bin ENV PATH=${PATH}:${NODE_PATH} RUN node --version @@ -62,23 +62,23 @@ RUN git clone https://github.com/googleapis/repo-automation-bots WORKDIR /tools/repo-automation-bots/packages/owl-bot RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version -RUN chmod -R 755 ${NODE_PATH} +RUN chmod -R o+rx ${NODE_PATH} RUN ln -sf ${NODE_PATH}/* /usr/local/bin # allow users to access the script folders -RUN chmod -R 755 /src +RUN chmod -R o+rx /src # set dummy git credentials for the empty commit used in postprocessing # we use system so all users using the container will use this configuration RUN git config --system user.email "cloud-java-bot@google.com" RUN git config --system user.name "Cloud Java Bot" -RUN touch /home/.gitconfig -# allow read-write for /home/.gitconfig and execution for binaries in /home/.nvm -RUN chmod -R 757 /home +# allow read-write for /home and execution for binaries in /home/.nvm +RUN chmod -R a+rw /home +RUN chmod -R a+rx /home/.nvm -# define runtime env vars -ENV RUNNING_IN_DOCKER=true +COPY .cloudbuild/library_generation/entrypoint.sh /entrypoint.sh +RUN chmod o+rx /entrypoint.sh WORKDIR /workspace -ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ] +ENTRYPOINT [ "bash", "/entrypoint.sh" ] diff --git a/library_generation/generate_library.sh b/library_generation/generate_library.sh index a5d73ebec4..a7131e33e5 100755 --- a/library_generation/generate_library.sh +++ b/library_generation/generate_library.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail +set -eox pipefail # parse input parameters while [[ $# -gt 0 ]]; do diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index f701c6ab4b..106be3dd88 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -31,7 +31,7 @@ configuration_yaml_path=$6 source "${scripts_root}"/utils/utilities.sh -declare -a required_inputs=("postprocessing_target" "versions_file" "owlbot_cli_image_sha" "is_monorepo") +declare -a required_inputs=("postprocessing_target" "versions_file" "is_monorepo") for required_input in "${required_inputs[@]}"; do if [[ -z "${!required_input}" ]]; then echo "missing required ${required_input} argument, please specify one" diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 4c0a0d37cb..b6a036be2f 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -240,10 +240,16 @@ def __run_entry_point_in_docker_container( baseline_config: str, current_config: str, ): + # we use the calling user to prevent the mapped volumes from changing + # owners + user_id = shell_call("id -u") + group_id = shell_call("id -g") subprocess.check_call( [ "docker", "run", + "-u", + f'{user_id}:{group_id}', "--rm", "-v", f"{repo_location}:/workspace/repo", @@ -254,7 +260,7 @@ def __run_entry_point_in_docker_container( image_tag, f"--baseline-generation-config=/workspace/config/{baseline_config}", f"--current-generation-config=/workspace/config/{current_config}", - ] + ], ) @classmethod From 9120c94c17e44403397e4e915e776958cf5390c3 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 04:15:47 +0000 Subject: [PATCH 19/36] manually set HOME var in owlbot --- library_generation/owlbot/bin/entrypoint.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library_generation/owlbot/bin/entrypoint.sh b/library_generation/owlbot/bin/entrypoint.sh index e7eb91c179..1ecd13e5d0 100755 --- a/library_generation/owlbot/bin/entrypoint.sh +++ b/library_generation/owlbot/bin/entrypoint.sh @@ -79,7 +79,12 @@ echo "Fixing missing license headers..." python3 "${scripts_root}/owlbot/src/fix-license-headers.py" echo "...done" -# ensure formatting on all .java files in the repository +# Ensure formatting on all .java files in the repository. +# Here we manually set the user.home system variable. Unfortunately, Maven +# infers user.home involves the /etc/passwd file (confirmed empirically), +# instead of the presumable $HOME env var, which may not work properly +# when `docker run`ning with the -u flag because we may incur in users +# not registered in the container's passwd file echo "Reformatting source..." -mvn fmt:format -V --batch-mode --no-transfer-progress +mvn fmt:format -Duser.home="${HOME}" -V --batch-mode --no-transfer-progress echo "...done" From 427c564984bcdb463a2d9569ec6a0b718360448a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 19:09:20 +0000 Subject: [PATCH 20/36] post-merge cleanup --- .../test/generate_pr_description_unit_tests.py | 2 -- .../test/model/generation_config_unit_test.py | 11 ----------- 2 files changed, 13 deletions(-) diff --git a/library_generation/test/generate_pr_description_unit_tests.py b/library_generation/test/generate_pr_description_unit_tests.py index c633268aa4..3e3508155c 100644 --- a/library_generation/test/generate_pr_description_unit_tests.py +++ b/library_generation/test/generate_pr_description_unit_tests.py @@ -61,8 +61,6 @@ def test_generate_pr_description_with_same_googleapis_commits(self): gapic_generator_version="", googleapis_commitish=commit_sha, libraries_bom_version="", - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], grpc_version="", protobuf_version="", diff --git a/library_generation/test/model/generation_config_unit_test.py b/library_generation/test/model/generation_config_unit_test.py index 08fea21523..40cd27f3f6 100644 --- a/library_generation/test/model/generation_config_unit_test.py +++ b/library_generation/test/model/generation_config_unit_test.py @@ -46,13 +46,6 @@ def test_from_yaml_succeeds(self): "1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish ) self.assertEqual("26.37.0", config.libraris_bom_version) - self.assertEqual( - "sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409", - config.owlbot_cli_image, - ) - self.assertEqual( - "6612ab8f3afcd5e292aecd647f0fa68812c9f5b5", config.synthtool_commitish - ) self.assertEqual( [ ".github/*", @@ -115,8 +108,6 @@ def test_is_monorepo_with_one_library_returns_false(self): gapic_generator_version="", googleapis_commitish="", libraries_bom_version="", - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], libraries=[library_1], ) @@ -127,8 +118,6 @@ def test_is_monorepo_with_two_libraries_returns_true(self): gapic_generator_version="", googleapis_commitish="", libraries_bom_version="", - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], libraries=[library_1, library_2], ) From 7b79763230404ca544fdff348290fedd8a03903b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 21:30:58 +0000 Subject: [PATCH 21/36] fix parameters --- library_generation/test/integration_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 1195a0a373..40883c5192 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -258,8 +258,8 @@ def __run_entry_point_in_docker_container( "-w", "/workspace/repo", image_tag, - f"--baseline-generation-config=/workspace/config/{baseline_config}", - f"--current-generation-config=/workspace/config/{current_config}", + f"--baseline-generation-config-path=/workspace/config/{baseline_config}", + f"--current-generation-config-path=/workspace/config/{current_config}", ], ) From 240742a42ec51fe8c3aefb6d373f84c67c5a443a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 21:31:36 +0000 Subject: [PATCH 22/36] fix synthtool sha --- .cloudbuild/library_generation/library_generation.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index f26ee13133..512ba59a5a 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -15,7 +15,7 @@ # build from the root of this repo: FROM gcr.io/cloud-devrel-public-resources/python -ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 +ARG SYNTHTOOL_COMMITTISH=63cc541da2c45fcfca2136c43e638da1fbae174d ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 ENV HOME=/home From 8498f2c27714c233dd4235bd5429e6814d7a930d Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 15:54:32 +0000 Subject: [PATCH 23/36] fix entrypoint --- .cloudbuild/library_generation/library_generation.Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 512ba59a5a..73861c316f 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -77,8 +77,5 @@ RUN git config --system user.name "Cloud Java Bot" RUN chmod -R a+rw /home RUN chmod -R a+rx /home/.nvm -COPY .cloudbuild/library_generation/entrypoint.sh /entrypoint.sh -RUN chmod o+rx /entrypoint.sh - WORKDIR /workspace -ENTRYPOINT [ "bash", "/entrypoint.sh" ] +ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ] From 2faf45dc0e11bf877fcfffb72764a946e4e5ccd1 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:35:36 +0000 Subject: [PATCH 24/36] lint --- library_generation/test/integration_tests.py | 2 +- .../test/resources/goldens/owlbot-golden.py | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index b74d42b907..030a73571d 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -264,7 +264,7 @@ def __run_entry_point_in_docker_container( "docker", "run", "-u", - f'{user_id}:{group_id}', + f"{user_id}:{group_id}", "--rm", "-v", f"{repo_location}:/workspace/repo", diff --git a/library_generation/test/resources/goldens/owlbot-golden.py b/library_generation/test/resources/goldens/owlbot-golden.py index 2ba11e6bba..7559eaf034 100644 --- a/library_generation/test/resources/goldens/owlbot-golden.py +++ b/library_generation/test/resources/goldens/owlbot-golden.py @@ -21,16 +21,19 @@ s.move(library) s.remove_staging_dirs() -java.common_templates(monorepo=True, excludes=[ - ".github/*", - ".kokoro/*", - "samples/*", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.md", - "LICENSE", - "SECURITY.md", - "java.header", - "license-checks.xml", - "renovate.json", - ".gitignore" -]) \ No newline at end of file +java.common_templates( + monorepo=True, + excludes=[ + ".github/*", + ".kokoro/*", + "samples/*", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.md", + "LICENSE", + "SECURITY.md", + "java.header", + "license-checks.xml", + "renovate.json", + ".gitignore", + ], +) From 7ce954879d07faaab980591cc58cece009d8b993 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:36:21 +0000 Subject: [PATCH 25/36] remove unused entrypoint file --- .cloudbuild/library_generation/entrypoint.sh | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .cloudbuild/library_generation/entrypoint.sh diff --git a/.cloudbuild/library_generation/entrypoint.sh b/.cloudbuild/library_generation/entrypoint.sh deleted file mode 100644 index 5350becc24..0000000000 --- a/.cloudbuild/library_generation/entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# wrapper script for the hermetic build cli entrypoint that sets environment -# variables that can be read by any user calling the container -set -ex -export HOME=/home -export MAVEN_HOME=/home/.m2 -python /src/cli/entry_point.py generate $@ - From 8474452e4a66127faadf207a4db8be805e937646 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:37:02 +0000 Subject: [PATCH 26/36] remove owlbot CLI from readmne --- library_generation/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/library_generation/README.md b/library_generation/README.md index b4978812f8..cded4bf54a 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -98,7 +98,6 @@ They are shared by library level parameters. | grpc_version | No | inferred from the generator if not specified | | googleapis-commitish | Yes | | | libraries_bom_version | Yes | | -| owlbot-cli-image | Yes | | | template_excludes | Yes | | ### Library level parameters From b58e990d9f570a2bd416965ae64d6e2c7a137ae7 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:37:46 +0000 Subject: [PATCH 27/36] restore xtrace --- library_generation/generate_library.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/generate_library.sh b/library_generation/generate_library.sh index a7131e33e5..a5d73ebec4 100755 --- a/library_generation/generate_library.sh +++ b/library_generation/generate_library.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eox pipefail +set -eo pipefail # parse input parameters while [[ $# -gt 0 ]]; do From 00cb2a7e6296f49ea2d7c45f1bf56279a71c54aa Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:38:54 +0000 Subject: [PATCH 28/36] correct comment --- library_generation/owlbot/bin/entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library_generation/owlbot/bin/entrypoint.sh b/library_generation/owlbot/bin/entrypoint.sh index 056a1d14ab..789737b2a5 100755 --- a/library_generation/owlbot/bin/entrypoint.sh +++ b/library_generation/owlbot/bin/entrypoint.sh @@ -72,10 +72,10 @@ echo "...done" # Ensure formatting on all .java files in the repository. # Here we manually set the user.home system variable. Unfortunately, Maven -# infers user.home involves the /etc/passwd file (confirmed empirically), +# user.home inference involves the /etc/passwd file (confirmed empirically), # instead of the presumable $HOME env var, which may not work properly # when `docker run`ning with the -u flag because we may incur in users -# not registered in the container's passwd file +# not registered in the container's /etc/passwd file echo "Reformatting source..." mvn fmt:format -Duser.home="${HOME}" -V --batch-mode --no-transfer-progress echo "...done" From b27a57ee036638037884bd124a1a20d33442a313 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:41:19 +0000 Subject: [PATCH 29/36] remove test helper --- library_generation/test/integration_tests.py | 30 -------------------- 1 file changed, 30 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 030a73571d..6c4704905b 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -217,36 +217,6 @@ def __prepare_golden_files( else: copy_tree(f"{repo_dest}", f"{golden_dir}/{library_name}") - @classmethod - def __bind_device_to_volumes(cls, volume_name: str, device_dir: str): - # We use a volume to hold the repositories used in the integration - # tests. This is because the test container creates a child container - # using the host machine's docker socket, meaning that we can only - # reference volumes created from within the host machine (i.e. the - # machine running this script). - # - # To summarize, we create a special volume that can be referenced both - # in the main container and in any child containers created by this one. - - # use subprocess.run because we don't care about the return value (we - # want to remove the volume in any case). - subprocess.run(["docker", "volume", "rm", volume_name]) - subprocess.check_call( - [ - "docker", - "volume", - "create", - "--name", - volume_name, - "--opt", - "type=none", - "--opt", - f"device={device_dir}", - "--opt", - "o=bind", - ] - ) - @classmethod def __run_entry_point_in_docker_container( cls, From 6c6432a7b3eac9b3c22acc2e409e82b7add671e4 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:42:55 +0000 Subject: [PATCH 30/36] checkout owlbot cli committish --- .cloudbuild/library_generation/library_generation.Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 73861c316f..bfdfeba1d8 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -60,6 +60,7 @@ RUN npm --version WORKDIR /tools RUN git clone https://github.com/googleapis/repo-automation-bots WORKDIR /tools/repo-automation-bots/packages/owl-bot +RUN git checkout "${OWLBOT_CLI_COMMITTISH}" RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version RUN chmod -R o+rx ${NODE_PATH} From eca8c62b1cc01d34932edaf8bd6190703bb99648 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:46:11 +0000 Subject: [PATCH 31/36] remove owlbot config --- .../resources/test-config/config_without_owlbot.yaml | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 library_generation/test/resources/test-config/config_without_owlbot.yaml diff --git a/library_generation/test/resources/test-config/config_without_owlbot.yaml b/library_generation/test/resources/test-config/config_without_owlbot.yaml deleted file mode 100644 index 0d1bb7deea..0000000000 --- a/library_generation/test/resources/test-config/config_without_owlbot.yaml +++ /dev/null @@ -1,10 +0,0 @@ -gapic_generator_version: 2.34.0 -googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -libraries_bom_version: 26.37.0 -libraries: - - api_shortname: apigeeconnect - name_pretty: Apigee Connect - api_description: "allows the Apigee hybrid management" - product_documentation: "https://cloud.google.com/apigee/docs/hybrid/v1.3/apigee-connect/" - GAPICs: - - proto_path: google/cloud/apigeeconnect/v1 From 0041c6b08a4e4a2fad75f010e52c92f0b8cb7778 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:51:57 +0000 Subject: [PATCH 32/36] fix golden file --- .../test/resources/goldens/owlbot-golden.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/library_generation/test/resources/goldens/owlbot-golden.py b/library_generation/test/resources/goldens/owlbot-golden.py index 7559eaf034..2ba11e6bba 100644 --- a/library_generation/test/resources/goldens/owlbot-golden.py +++ b/library_generation/test/resources/goldens/owlbot-golden.py @@ -21,19 +21,16 @@ s.move(library) s.remove_staging_dirs() -java.common_templates( - monorepo=True, - excludes=[ - ".github/*", - ".kokoro/*", - "samples/*", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.md", - "LICENSE", - "SECURITY.md", - "java.header", - "license-checks.xml", - "renovate.json", - ".gitignore", - ], -) +java.common_templates(monorepo=True, excludes=[ + ".github/*", + ".kokoro/*", + "samples/*", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.md", + "LICENSE", + "SECURITY.md", + "java.header", + "license-checks.xml", + "renovate.json", + ".gitignore" +]) \ No newline at end of file From 7ec0f4cdb318278abe017bb416ad2abba6f868a8 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Mon, 29 Apr 2024 18:16:08 -0400 Subject: [PATCH 33/36] Update library_generation/DEVELOPMENT.md Co-authored-by: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> --- library_generation/DEVELOPMENT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 4e161debc6..25382ccad6 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -96,6 +96,6 @@ python -m pip install . ### Run the script ``` cd library_generation -python cli/entry_point.py --repository-path "${path_to_repo}" +python cli/entry_point.py generate --repository-path="${path_to_repo}" ``` From 4399bfe4661c6aec900fe484b07fb018c4b7b641 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 29 Apr 2024 23:28:54 +0000 Subject: [PATCH 34/36] docker instructions, pwd blurb, unit tests instructions --- library_generation/DEVELOPMENT.md | 57 ++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 4e161debc6..ee108cf330 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -1,3 +1,7 @@ +> [!IMPORTANT] +> All examples assume you are inside the `library_generation` folder + + # Linting When contributing, ensure your changes to python code have a valid @@ -5,7 +9,7 @@ format. ``` python -m pip install black -black library_generation +black . ``` # Running the integration tests @@ -18,12 +22,26 @@ code declared in a "golden branch" of the repo. It requires docker and python 3.x to be installed. ``` -cd library_generation python -m pip install . python -m pip install -r requirements.txt python -m unittest test/integration_tests.py ``` +# Running the unit tests + +The unit tests of the hermetic build scripts are contained in several scripts, +corresponding to a specific component. Every unit test script ends with +`unit_tests.py`. To avoid them specifying them +individually, we can use the following command: + +```bash +python -m unittest discover -s test/ -p "*unit_tests.py" +``` + +> [!NOTE] +> The output of this command may look erratic during the first 30 seconds. +> This is normal. After the tests are done, an "OK" message should be shown. + # Running the scripts in your local environment Although the scripts are designed to be run in a Docker container, you can also @@ -89,13 +107,44 @@ export path_to_repo="$(pwd)/google-cloud-java" ### Install the scripts ``` -cd library_generation python -m pip install . ``` ### Run the script ``` -cd library_generation python cli/entry_point.py --repository-path "${path_to_repo}" ``` + +# Running the scripts using the docker container image +This is convenient in order to avoid installing the dependencies manually. + +> [!IMPORTANT] +> From now, the examples assume you are in the root of your sdk-platform-java +> folder + +## Build the docker image +```bash +docker build --file .cloudbuild/library_generation/library_generation.Dockerfile --iidfile image-id . +``` + +This will create an `image-id` file at the root of the repo with the hash ID of +the image. + +## Run the docker image +The docker image will perform changes on its internal `/workspace` folder, to which you +need to map a folder on your host machine (i.e. map your downloaded repo to this +folder). + +To run the docker container on the google-cloud-java repo, you must run: +```bash +docker run -u "$(id -u)":"$(id -g)" -v/path/to/google-cloud-java:/workspace $(cat image-id) +``` + + * `-u "$(id -u)":"$(id -g)"` makes docker run the container impersonating + yourself. This avoids folder ownership changes since it runs as root by + default. + * `-v/path/to/google-cloud-java:/workspace` maps the host machine's + google-cloud-java folder to the /workspace folder. The image is configured to + perform changes in this directory + * `$(cat image-id)` obtains the image ID created in the build step From 1df1aa158ace81ab1b79ccfce28c622366c846e0 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 30 Apr 2024 15:19:17 +0000 Subject: [PATCH 35/36] restore generate repo --- library_generation/generate_repo.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 42a4e24bf7..9a97e3555b 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -12,14 +12,12 @@ # 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 os import click as click import library_generation.utils.utilities as util from library_generation.generate_composed_library import generate_composed_library from library_generation.model.generation_config import GenerationConfig, from_yaml from library_generation.model.library_config import LibraryConfig from library_generation.utils.monorepo_postprocessor import monorepo_postprocessing -from pathlib import Path @click.group(invoke_without_command=False) @@ -32,12 +30,11 @@ def main(ctx): @main.command() @click.option( "--generation-config-yaml", - required=False, + required=True, type=str, help=""" Path to generation_config.yaml that contains the metadata about - library generation. If not specified, it will be assumed to be found - at the root of --repository-path + library generation """, ) @click.option( @@ -75,10 +72,6 @@ def generate( target_library_names: str, repository_path: str, ): - if generation_config_yaml is None: - generation_config_yaml = str( - Path(os.path.join(repository_path, "generation_config.yaml")).resolve() - ) config = from_yaml(generation_config_yaml) generate_from_yaml( config_path=generation_config_yaml, From bf9593813dfe5f70afa536b6764c619af45914f2 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 30 Apr 2024 19:54:10 +0000 Subject: [PATCH 36/36] move text editor installation as a readme note --- .../library_generation.Dockerfile | 2 +- library_generation/DEVELOPMENT.md | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index bfdfeba1d8..f6ef6f1609 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -21,7 +21,7 @@ ENV HOME=/home # install OS tools RUN apt-get update && apt-get install -y \ - unzip openjdk-17-jdk rsync maven jq less vim \ + unzip openjdk-17-jdk rsync maven jq \ && apt-get clean # use python 3.11 (the base image has several python versions; here we define the default one) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 4b2b4d79c9..cede089ae9 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -148,3 +148,24 @@ docker run -u "$(id -u)":"$(id -g)" -v/path/to/google-cloud-java:/workspace $(c google-cloud-java folder to the /workspace folder. The image is configured to perform changes in this directory * `$(cat image-id)` obtains the image ID created in the build step + +## Debug the created containers +If you are working on changing the way the containers are created, you may want +to inspect the containers to check the setup. It would be convenient in such +case to have a text editor/viewer available. You can achieve this by modifying +the Dockerfile as follows: + +```docker +# install OS tools +RUN apt-get update && apt-get install -y \ + unzip openjdk-17-jdk rsync maven jq less vim \ + && apt-get clean +``` + +We add `less` and `vim` as text tools for further inspection. + +You can also run a shell in a new container by running: + +```bash +docker run --rm -it -u=$(id -u):$(id -g) -v/path/to/google-cloud-java:/workspace --entrypoint="bash" $(cat image-id) +```