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 protoc into the hermetic build docker image #2707

Merged
merged 66 commits into from
May 23, 2024

Conversation

diegomarquezp
Copy link
Contributor

@diegomarquezp diegomarquezp commented Apr 30, 2024

Does the config work with renovate bot?

Yes. After a local run using LOG_LEVEL=debug npx --yes --package renovate -- renovate --platform=local &> renovate.out, we obtained a dependency update in the logs:

           {
             "deps": [
               {     
                 "depName": "protocolbuffers/protobuf",
                 "currentValue": "25.2",
                 "datasource": "github-releases",
                 "extractVersion": "^v(?<version>.*)$",
                 "replaceString": "ARG PROTOC_VERSION=25.2\n",
                 "updates": [
                   {     
                     "bucket": "non-major",
                     "newVersion": "25.3",
                     "newValue": "25.3",
                     "releaseTimestamp": "2024-02-15T23:20:43.000Z",
                     "newMajor": 25,
                     "newMinor": 3,
                     "updateType": "minor",
                     "branchName": "renovate/protocolbuffers-protobuf-25.x"
                   },    
                   {     
                     "bucket": "major",
                     "newVersion": "26.1",
                     "newValue": "26.1",
                     "releaseTimestamp": "2024-03-27T20:28:47.000Z",
                     "newMajor": 26,
                     "newMinor": 1,
                     "updateType": "major",
                     "branchName": "renovate/protocolbuffers-protobuf-26.x"
                   }
                 ],
                 "packageName": "protocolbuffers/protobuf",
                 "versioning": "semver-coerced",
                 "warnings": [],
                 "sourceUrl": "https://github.com/protocolbuffers/protobuf",
                 "registryUrl": "https://github.com",
                 "currentVersion": "25.2",
                 "currentVersionTimestamp": "2024-01-09T23:52:55.000Z",
                 "isSingleVersion": true, 
                 "fixedVersion": "25.2"
               }
             ],

However, we disabled the setting for now. This log entry confirms it.
DEBUG: Dependency: protocolbuffers/protobuf, is disabled (repository=local)

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels May 14, 2024
@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is a test resource, could you remove all unused part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, it slipped into my commits!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@@ -157,7 +161,22 @@ download_generator_artifact() {
download_protoc() {
local protoc_version=$1
local os_architecture=$2
if [ ! -d "protoc-${protoc_version}" ]; then

protoc_dirname="protoc-${protoc_version}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a comment specifying the the protoc version priority?

{
"customType": "regex",
"fileMatch": [
"^\\.cloudbuild/library_generation/library_generation\\.Dockerfile$"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually we probably don't want to let renovate bot to automatically update protoc. Not before we can update the whole repo(java-comon-protos, java-iam, test files in gapic-generator-java) along side the protoc update. Because the new protoc version may not work with the current protos or the newly generated code may not work with the generator.


# install protobuf
WORKDIR /protoc
RUN ls /src
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 just for troubleshooting purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. I removed it

# if the specified protoc_version matches the one baked in the docker
# container, we just copy it into the output folder
mkdir -p "${output_folder}/${protoc_dirname}"
cp -r "${DOCKER_PROTOC_LOCATION}/${protoc_dirname}" \
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 use the protoc location specified in Dockerfile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. We now explicitly export the protoc_path variable to simply point to this location instead of copying it.

@@ -157,7 +161,22 @@ download_generator_artifact() {
download_protoc() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general, I feel like we may not need any changes in download_protoc. Ideally this function can stay as it is and we can add logics before calling it, for example

if [[ "${protoc_version}" != "${DOCKER_PROTOC_VERSION}" ]]; then
  download_protoc "${protoc_version}" "${os_architecture}"
fi

But I think this requires us to reuse the proto location specified in Dockerfile.

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 left download_protoc almost untouched and left the DOCKER_PROTOC_VERSION handling in download_tools (one level up in the call hierarchy).

if [[ -n "${DOCKER_PROTOC_VERSION}" ]]; then
>&2 echo "Using protoc version baked into the container: ${DOCKER_PROTOC_VERSION}"
echo "${DOCKER_PROTOC_VERSION}"
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we can return this function early?

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 became obsolete as we moved this if statement outside of download_protoc

Removed.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels May 22, 2024
@@ -308,6 +304,3 @@ def __recursive_diff_files(
sub_dcmp, diff_files, left_only, right_only, dirname + sub_dirname + "/"
)

@classmethod
def __remove_docker_image(cls):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the GitHub runner cleans itself up after running the ITs and we usually want to troubleshoot locally via this integration test, it may be more convenient to not have to build the image from scratch every time when debugging.

@@ -15,24 +15,35 @@
# build from the root of this repo:
FROM gcr.io/cloud-devrel-public-resources/python

ARG SYNTHTOOL_COMMITTISH=a2c9b4a5da2d7f583c8a1869fd2843c206145834
SHELL [ "/bin/bash", "-c" ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Anything requires us to change the default shell to bash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The nvm installation script assumes the environment is bash based. Using sh makes the following line to have no effects.

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

@diegomarquezp diegomarquezp enabled auto-merge (squash) May 23, 2024 14:10
Copy link

sonarcloud bot commented May 23, 2024

Please retry analysis of this Pull-Request directly on SonarCloud

Copy link

sonarcloud bot commented May 23, 2024

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@diegomarquezp diegomarquezp merged commit cf44b07 into main May 23, 2024
49 checks passed
@diegomarquezp diegomarquezp deleted the bake-protoc-hermetic-build branch May 23, 2024 14:23
lqiu96 pushed a commit that referenced this pull request May 23, 2024
### Does the config work with renovate bot?
Yes. After a local run using `LOG_LEVEL=debug npx --yes --package
renovate -- renovate --platform=local &> renovate.out`, we obtained a
dependency update in the logs:
```
           {
             "deps": [
               {     
                 "depName": "protocolbuffers/protobuf",
                 "currentValue": "25.2",
                 "datasource": "github-releases",
                 "extractVersion": "^v(?<version>.*)$",
                 "replaceString": "ARG PROTOC_VERSION=25.2\n",
                 "updates": [
                   {     
                     "bucket": "non-major",
                     "newVersion": "25.3",
                     "newValue": "25.3",
                     "releaseTimestamp": "2024-02-15T23:20:43.000Z",
                     "newMajor": 25,
                     "newMinor": 3,
                     "updateType": "minor",
                     "branchName": "renovate/protocolbuffers-protobuf-25.x"
                   },    
                   {     
                     "bucket": "major",
                     "newVersion": "26.1",
                     "newValue": "26.1",
                     "releaseTimestamp": "2024-03-27T20:28:47.000Z",
                     "newMajor": 26,
                     "newMinor": 1,
                     "updateType": "major",
                     "branchName": "renovate/protocolbuffers-protobuf-26.x"
                   }
                 ],
                 "packageName": "protocolbuffers/protobuf",
                 "versioning": "semver-coerced",
                 "warnings": [],
                 "sourceUrl": "https://github.com/protocolbuffers/protobuf",
                 "registryUrl": "https://github.com",
                 "currentVersion": "25.2",
                 "currentVersionTimestamp": "2024-01-09T23:52:55.000Z",
                 "isSingleVersion": true, 
                 "fixedVersion": "25.2"
               }
             ],

```

However, we disabled the setting for now. This log entry confirms it.
`DEBUG: Dependency: protocolbuffers/protobuf, is disabled
(repository=local)`

---------

Co-authored-by: Joe Wang <106995533+JoeWang1127@users.noreply.github.com>
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.

None yet

3 participants