-
Notifications
You must be signed in to change notification settings - Fork 69
feat: bake gapic-generator-java into the hermetic build docker image #3067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8de1c01
15b2fc5
0a95554
034edf9
9795e23
89fc562
1f2ea9e
8af8bec
b5e49dd
1649403
34c5355
651af1e
4ef977b
6e20135
a5c18b2
89e16c1
1cf63ea
74b36d3
e582817
82e6b8e
3f0dc7f
b599d6f
ddb4ff9
6d35e7f
d08e739
eea978d
cdb137e
9b50a73
4ac8caf
4a57a7d
1164694
5a4cfdc
a9257fe
ab7a684
ddaeaf1
62b281d
e0de3c9
1bc545a
9022ba0
6f1e200
bd71775
0e90ddc
25f2d7f
902f656
a06cd0b
7194148
41ab2da
1301b0f
c4933ea
6379c0d
16435c4
1b4a8cc
8e0ddcc
81f6748
35ad97e
32e9af3
d6844ce
d776b32
1de293f
1895792
7d805e2
1eec008
935534e
b01717a
5fb1be8
38b53a2
87b7425
e639d2c
7dd0f3e
6a4f446
b524768
01d8fa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,26 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # install gapic-generator-java in a separate layer so we don't overload the image | ||
| # with the transferred source code and jars | ||
| FROM gcr.io/cloud-devrel-public-resources/java21 AS ggj-build | ||
|
|
||
| WORKDIR /sdk-platform-java | ||
| COPY . . | ||
| # {x-version-update-start:gapic-generator-java:current} | ||
| ENV DOCKER_GAPIC_GENERATOR_VERSION="2.44.1-SNAPSHOT" | ||
| # {x-version-update-end:gapic-generator-java:current} | ||
|
|
||
| RUN mvn install -DskipTests -Dclirr.skip -Dcheckstyle.skip | ||
| RUN cp "/root/.m2/repository/com/google/api/gapic-generator-java/${DOCKER_GAPIC_GENERATOR_VERSION}/gapic-generator-java-${DOCKER_GAPIC_GENERATOR_VERSION}.jar" \ | ||
| "./gapic-generator-java.jar" | ||
|
|
||
| # build from the root of this repo: | ||
| FROM gcr.io/cloud-devrel-public-resources/python | ||
JoeWang1127 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| SHELL [ "/bin/bash", "-c" ] | ||
|
|
||
|
|
||
| ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 | ||
| ARG PROTOC_VERSION=25.4 | ||
| ARG GRPC_VERSION=1.66.0 | ||
|
|
@@ -47,7 +62,15 @@ RUN source /src/utils/utilities.sh \ | |
| ENV DOCKER_GRPC_LOCATION="/grpc/protoc-gen-grpc-java-${GRPC_VERSION}-${OS_ARCHITECTURE}.exe" | ||
| ENV DOCKER_GRPC_VERSION="${GRPC_VERSION}" | ||
|
|
||
| # use python 3.11 (the base image has several python versions; here we define the default one) | ||
|
|
||
| # Here we transfer gapic-generator-java from the previous stage. | ||
| # Note that the destination is a well-known location that will be assumed at runtime | ||
| # We hard-code the location string to avoid making it configurable (via ARG) as | ||
| # well as to avoid it making it overridable at runtime (via ENV). | ||
| COPY --from=ggj-build "/sdk-platform-java/gapic-generator-java.jar" "${HOME}/.library_generation/gapic-generator-java.jar" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A future improvement: only include necessary files in the final image.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we want to get rid of the source files (owlbot cli, sdk-platform, etc) by building in this stage then only copying the binaries. This is part of the image cleanup task. |
||
| RUN chmod 755 "${HOME}/.library_generation/gapic-generator-java.jar" | ||
|
|
||
| # 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,5 @@ target/ | |
| **/*egg-info/ | ||
| **/build/ | ||
| **/dist/ | ||
| library_generation/**/*.jar | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,8 @@ git clone "https://github.com/GoogleCloudPlatform/spring-cloud-gcp.git" --depth= | |
| update_all_poms_dependency "spring-cloud-gcp" "gapic-generator-java-bom" "${GAPIC_GENERATOR_VERSION}" | ||
|
|
||
| # Install spring-cloud-gcp modules | ||
| pushd spring-cloud-gcp/spring-cloud-generator | ||
| ../mvnw \ | ||
| pushd spring-cloud-gcp | ||
| ./mvnw \ | ||
| -U \ | ||
| --batch-mode \ | ||
| --no-transfer-progress \ | ||
|
|
@@ -47,10 +47,16 @@ pushd spring-cloud-gcp/spring-cloud-generator | |
|
|
||
|
|
||
| # Generate showcase autoconfig | ||
| pushd spring-cloud-generator | ||
| # The script is not executable for non-owners. Here we manually chmod it. | ||
| # TODO(diegomarquezp): remove this line after | ||
| # https://github.com/GoogleCloudPlatform/spring-cloud-gcp/pull/3183 is merged and released. | ||
| chmod 755 ./scripts/generate-showcase.sh | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blakeli0 @JoeWang1127 I fixed the spring check in this PR as well since I thought it's small enough. There is a TODO to be solved next week, once GoogleCloudPlatform/spring-cloud-gcp#3183 is merged |
||
| ./scripts/generate-showcase.sh | ||
| pushd showcase/showcase-spring-starter | ||
| mvn verify | ||
| popd # showcase/showcase-spring-starter | ||
|
|
||
| popd # spring-cloud-gcp/spring-cloud-generator | ||
| popd # spring-cloud-generator | ||
| popd # spring-cloud-gcp | ||
| popd # gapic-generator-java/target | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e | ||
| wrapper_dir=$(dirname "$(realpath "${BASH_SOURCE[0]}")") | ||
| source "${wrapper_dir}/utils/utilities.sh" | ||
|
|
||
| # Wrap gapic-generator-java.jar because protoc requires the plugin to be executable. | ||
| exec java -classpath "gapic-generator-java-${gapic_generator_version}.jar" com.google.api.generator.Main | ||
| exec java -classpath "$(get_gapic_generator_location)" com.google.api.generator.Main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import subprocess | ||
| import unittest | ||
| import os | ||
| from library_generation.utils.utilities import ( | ||
| run_process_and_print_output as bash_call, | ||
| run_process_and_get_output_string as get_bash_call_output, | ||
| ) | ||
|
|
||
| script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
|
||
|
|
||
| class GenerateLibraryUnitTests(unittest.TestCase): | ||
| """ | ||
| Confirms the correct behavior of `library_generation/utils/utilities.sh`. | ||
|
|
||
| Note that there is an already existing, shell-based, test suite for | ||
| generate_library.sh, but these tests will soon be transferred to this one as | ||
| an effort to unify the implementation of the Hermetic Build scripts as | ||
| python-only. New tests for `utilities.sh` should be added in this file. | ||
| """ | ||
|
|
||
| TEST_ARCHITECTURE = "linux-x86_64" | ||
|
|
||
| def setUp(self): | ||
| # we create a simulated home folder that has a fake generator jar | ||
| # in its well-known location | ||
| self.simulated_home = get_bash_call_output("mktemp -d") | ||
| bash_call(f"mkdir {self.simulated_home}/.library_generation") | ||
| bash_call( | ||
| f"touch {self.simulated_home}/.library_generation/gapic-generator-java.jar" | ||
| ) | ||
|
|
||
| # We create a per-test directory where all output files will be created into. | ||
| # Each folder will be deleted after its corresponding test finishes. | ||
| test_dir = get_bash_call_output("mktemp -d") | ||
| self.output_folder = self._run_command_and_get_sdout( | ||
| "get_output_folder", | ||
| cwd=test_dir, | ||
| ) | ||
| bash_call(f"mkdir {self.output_folder}") | ||
|
|
||
| def tearDown(self): | ||
| bash_call(f"rm -rdf {self.simulated_home}") | ||
|
|
||
| def _run_command(self, command, **kwargs): | ||
| env = os.environ.copy() | ||
| env["HOME"] = self.simulated_home | ||
| if "cwd" not in kwargs: | ||
| kwargs["cwd"] = self.output_folder | ||
| return bash_call( | ||
| [ | ||
| "bash", | ||
| "-exc", | ||
| f"source {script_dir}/../utils/utilities.sh " + f"&& {command}", | ||
| ], | ||
| exit_on_fail=False, | ||
| env=env, | ||
| **kwargs, | ||
| ) | ||
|
|
||
| def _run_command_and_get_sdout(self, command, **kwargs): | ||
| return self._run_command( | ||
| command, stderr=subprocess.PIPE, **kwargs | ||
| ).stdout.decode()[:-1] | ||
|
|
||
| def test_get_grpc_version_with_no_env_var_fails(self): | ||
| # the absence of DOCKER_GRPC_VERSION will make this function to fail | ||
| result = self._run_command("get_grpc_version") | ||
| self.assertEquals(1, result.returncode) | ||
| self.assertRegex(result.stdout.decode(), "DOCKER_GRPC_VERSION is not set") | ||
|
|
||
| def test_get_protoc_version_with_no_env_var_fails(self): | ||
| # the absence of DOCKER_PROTOC_VERSION will make this function to fail | ||
| result = self._run_command("get_protoc_version") | ||
| self.assertEquals(1, result.returncode) | ||
| self.assertRegex(result.stdout.decode(), "DOCKER_PROTOC_VERSION is not set") | ||
|
|
||
| def test_download_tools_without_baked_generator_fails(self): | ||
| # This test has the same structure as | ||
| # download_tools_succeed_with_baked_protoc, but meant for | ||
| # gapic-generator-java. | ||
|
|
||
| test_protoc_version = "1.64.0" | ||
| test_grpc_version = "1.64.0" | ||
| jar_location = ( | ||
| f"{self.simulated_home}/.library_generation/gapic-generator-java.jar" | ||
| ) | ||
| # we expect the function to fail because the generator jar is not found in | ||
| # its well-known location. To achieve this, we temporarily remove the fake | ||
| # generator jar | ||
| bash_call(f"rm {jar_location}") | ||
| result = self._run_command( | ||
| f"download_tools {test_protoc_version} {test_grpc_version} {self.TEST_ARCHITECTURE}" | ||
| ) | ||
| self.assertEquals(1, result.returncode) | ||
| self.assertRegex(result.stdout.decode(), "Please configure your environment") |
Uh oh!
There was an error while loading. Please reload this page.