Important
All examples assume you are inside the repository root folder.
When contributing, ensure your changes to python code have a valid format.
python -m pip install black
black {source_file_or_directory}
python -m pip install --require-hashes -r hermetic_build/common/requirements.txt
python -m pip install hermetic_build/common
python -m pip install --require-hashes -r hermetic_build/library_generation/requirements.txt
python -m pip install hermetic_build/library_generation
python -m pip install --require-hashes -r hermetic_build/release_note_generation/requirements.txt
python -m pip install hermetic_build/release_note_generationThe integration tests build the docker image declared in
.cloudbuild/library_generation/library_generation.Dockerfile, pull API
definitions and GAPIC repositories, generate the libraries and compare the
results with the source code declared in a "golden branch" of the repo.
The integration tests are running in Cloud Build rather than GitHub workflow because the workflow doesn't have permission to pull images from Airlock.
The Cloud Build job is defined in .cloudbuild/library_generation/cloudbuild-library-generation-integration-test.yaml and runs in every pull request.
There is one unit test file per component.
Every unit test script ends with unit_tests.py.
To avoid specifying them individually, we can use the following command:
python -m unittest discover -s hermetic_build -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.
Although the scripts are designed to run in a Docker container, you can also
run them directly.
This section explains how to run the entrypoint script
(hermetic_build/library_generation/cli/entry_point.py).
Located in ${HOME}/.library_generation, this folder is assumed by the scripts
to contain certain tools.
Developers must make sure this folder is properly configured before running the
scripts locally.
Note that this relies on the HOME environment variable which is always defined
as per POSIX env var definition.
-
Run the following command to install gapic-generator-java.
mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
This will generate a jar located in
~/.m2/repository/com/google/api/gapic-generator-java/{version}/gapic-generator-java-{version}.jar -
Move the jar into its well-known location.
mv /path/to/jar "${HOME}/.library_generation/gapic-generator-java.jar"
-
Download protobuf compiler from GitHub releases.
-
Move the folder into its well-know location.
unzip /path/to/zipfile -d "${HOME}/.library_generation/"
-
Download GRPC plugin from Maven Central.
-
Move the folder into its well-know location.
mv /path/to/protoc-gen-grpc-java.exe "${HOME}/.library_generation/protoc-gen-grpc-java.exe"
-
Download google-java-format-{version}-all-deps.jar from Maven Central or GitHub releases.
-
Move the jar into its well-known location.
mv /path/to/jar "${HOME}/.library_generation/google-java-format.jar"
In order to run the generation scripts directly, there are a few tools we need to install beforehand.
This requires node.js to be installed. Check this installation guide for NVM, Node.js's version manager.
After you install it, you can install the owl-bot CLI with the following commands:
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 --versionThe key step is npm link, which will make the command available in you current
shell session.
If you get a permission denied error when running the command owl-bot, try
relinking owl-bot by running npm unlink -g and re-running the steps above.
The entrypoint script (hermetic_build/library_generation/cli/entry_point.py)
allows you to generate a GAPIC repository with a given api definition (proto,
service yaml).
For example, from googleapis
git clone https://github.com/googleapis/googleapis
export api_definitions_path="$(pwd)/googleapis"For example, google-cloud-java
git clone https://github.com/googleapis/google-cloud-java
export path_to_repo="$(pwd)/google-cloud-java"You can skip this step if you've installed the packages in Install package dependencies.
Use the --editable flag for your changes to take effect as soon as you modify any file inside
the package.
python -m pip install --require-hashes -r hermetic_build/common/requirements.txt
python -m pip install --editable hermetic_build/common
python -m pip install --require-hashes -r hermetic_build/library_generation/requirements.txt
python -m pip install --editable hermetic_build/library_generationpython hermetic_build/library_generation/cli/entry_point.py generate \
--repository-path="${path_to_repo}" \
--api-definitions-path="${api_definitions_path}"-
Run the following command to build the image from source
DOCKER_BUILDKIT=1 docker build \ -f .cloudbuild/library_generation/library_generation.Dockerfile \ -t local:image-tag \ .Please note that the build only works when using the new Docker BuildKit (enabled through the
DOCKER_BUILDKITvariable). -
Set the version of gapic-generator-java
export LOCAL_GENERATOR_VERSION=$(mvn \ org.apache.maven.plugins:maven-help-plugin:evaluate \ -Dexpression=project.version \ -pl sdk-platform-java/gapic-generator-java \ -DforceStdout \ -q)
-
Clone the googleapis repository (API definitions)
cd google-cloud-java git clone https://github.com/googleapis/googleapis -
Run the image
# Assume you want to generate the library in the current working directory # and the generation configuration is in the same directory. docker run \ --rm \ --quiet \ -u "$(id -u):$(id -g)" \ -v "$(pwd):/workspace" \ -v "$(pwd)/googleapis:/googleapis" \ -e GENERATOR_VERSION="${LOCAL_GENERATOR_VERSION}" \ local:image-tag \ --generation-config-path=/workspace/generation_config.yaml \ --library-names=translate \ --repository-path=/workspace \ --api-definitions-path=/googleapis
Especially on local setups, consider adding the xtrace (set -x) flag to
hermetic_build/library_generation/generate_library.shhermetic_build/library_generation/utils/utilities.sh
This will allow you to observe how the tools you prepared in ~/.library_generation are being used.
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:
# install OS tools
RUN apk update && apk add \
unzip curl rsync openjdk11 jq bash nodejs npm git less vimWe add less and vim as text tools for further inspection.
You can also run a shell in a new container by running:
docker run \
--rm \
-it \
-u $(id -u):$(id -g) \
-v /path/to/google-cloud-java:/workspace \
--entrypoint="bash" \
$(cat image-id)