Skip to content
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

chore: bake the grpc plugin in the hermetic library generation image #3045

Merged
merged 7 commits into from
Jul 25, 2024

Conversation

diegomarquezp
Copy link
Contributor

This PR bakes the gRPC plugin in the hermetic library generation image.
The approach is very similar to #2707

  • The docker image will have a configurable ARG for the gRPC plugin
  • The docker image will download the gRPC plugin at the version specified in the previous point
  • The docker image will set the variables DOCKER_GRPC_VERSION and DOCKER_GRPC_LOCATION
  • generate_library.sh will now be able to avoid downloading the gRPC plugin if the computed plugin version is the same as DOCKER_GRPC_VERSION (all this via utilities.sh).

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Jul 11, 2024
@@ -282,7 +315,7 @@ get_proto_path_from_preprocessed_sources() {
pushd "${sources}" > /dev/null
local proto_library=$(find . -maxdepth 1 -type d -name 'proto-*' | sed 's/\.\///')
local found_libraries=$(echo "${proto_library}" | wc -l)
if [ -z ${proto_library} ]; then
if [[ -z ${proto_library} ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the shell unit tests were expecting the binary brackets because proto_library could be expanded to a string with spaces.

+ '[' -z proto-2 proto-1 ']'
/usr/local/google/home/diegomarquezp/google/sdk-platform-java/library_generation/test/../utils/utilities.sh: line 318: [: proto-2: binary operator expected

@diegomarquezp diegomarquezp marked this pull request as ready for review July 11, 2024 13:54
library_generation/utils/utilities.sh Outdated Show resolved Hide resolved
fi
echo "$(pwd)/${grpc_filename}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a debug log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's the return statement of the function. Many functions in utilities.sh are made this way. The way we use is variable=$(my_function "arg1" "arg2"). The only possible return values for return are integers from 0 to 255 (and consumed via $?) so it's not useful.

# we indicate protoc is available in the container via env vars
ENV DOCKER_PROTOC_LOCATION=/protoc
ENV DOCKER_PROTOC_VERSION="${PROTOC_VERSION}"

# install grpc
WORKDIR /grpc
RUN source /src/utils/utilities.sh \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source /src/utils/utilities.sh is not needed anymore. We should probably split

RUN source /src/utils/utilities.sh \
	&& download_protoc "${PROTOC_VERSION}" "${OS_ARCHITECTURE}"

to

RUN source /src/utils/utilities.sh
RUN download_protoc "${PROTOC_VERSION}" "${OS_ARCHITECTURE}"

Then here we can just do

RUN download_grpc_plugin "${GRPC_VERSION}" "${OS_ARCHITECTURE}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I considered initially when working on the Dockerfile. The effects of source are contained in the RUN statement only, because it is translated into /bin/sh -c "source script.sh" (see SO)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, that's good to know!

@@ -19,7 +19,9 @@ SHELL [ "/bin/bash", "-c" ]

ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550
ARG PROTOC_VERSION=25.3
ARG GRPC_VERSION=1.62.2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we configure this with renovate bot, and group it with other grpc update? e.g. There is an existing PR that updates gRPC to the latest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
"customType": "regex",
"fileMatch": [
"^gax-java/dependencies\\.properties$",
"^\\.cloudbuild/library_generation/library_generation\\.Dockerfile$"
],
"matchStrings": [
"version\\.io_grpc=(?<currentValue>.+?)\\n",
"ARG GRPC_VERSION=[\"']?(?<currentValue>.+?)[\"']?\\s+"
],
"depNameTemplate": "io.grpc:grpc-core",
"datasourceTemplate": "maven"
},

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version can be updated to 1.65.1 now since this PR is merged..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@blakeli0 blakeli0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can still pass grpc_version from generation_config.yaml, I guess that would still override the baked in grpc version and the default grpc version from the pom?

@diegomarquezp
Copy link
Contributor Author

We can still pass grpc_version from generation_config.yaml, I guess that would still override the baked in grpc version and the default grpc version from the pom?

@blakeli0 Yes, if --grpc_version is not passed via the config yaml, then it will infer it via utilities.sh/get_protoc_version.

if [ -z "${grpc_version}" ]; then
grpc_version=$(get_grpc_version "${gapic_generator_version}")
fi

def __construct_tooling_arg(config: GenerationConfig) -> List[str]:
"""
Construct arguments of tooling versions used in generate_library.sh
:param config: the generation config
:return: arguments containing tooling versions
"""
arguments = []
arguments += util.create_argument("gapic_generator_version", config)
arguments += util.create_argument("grpc_version", config)
arguments += util.create_argument("protoc_version", config)

def create_argument(arg_key: str, arg_container: object) -> List[str]:
"""
Generates a list of two elements [argument, value], or returns
an empty array if arg_val is None
"""
arg_val = getattr(arg_container, arg_key, None)
if arg_val is not None:
return [f"--{arg_key}", f"{arg_val}"]
return []

Copy link

sonarcloud bot commented Jul 25, 2024

Copy link

sonarcloud bot commented Jul 25, 2024

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@diegomarquezp diegomarquezp merged commit 4bbb8ac into main Jul 25, 2024
48 of 50 checks passed
@diegomarquezp diegomarquezp deleted the bake-grpc-hermetic-build branch July 25, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants