-
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 62 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" | ||
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. 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 |
---|---|---|
|
@@ -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 | ||
diegomarquezp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
chmod 755 ./scripts/generate-showcase.sh | ||
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 |
---|---|---|
|
@@ -48,32 +48,36 @@ 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 | ||
## Assumptions made by the scripts | ||
### The Hermetic Build's well-known folder | ||
Located in `${HOME}/.library_generation`, this folder is assumed by the scripts | ||
to contain the generator JAR. Please note that this is a recent feature and only | ||
this jar is expected to be there. Soon enough, more binaries such as the gRPC | ||
and protoc plugins will also be stored here. Developers must make sure | ||
this folder is properly configured before running the scripts locally. | ||
Note that this relies on the `HOME` en var which is always | ||
JoeWang1127 marked this conversation as resolved.
Show resolved
Hide resolved
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. nit: one sentence per line. 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. I found this article that confirms this is a good practice. I reformatted the file. |
||
defined as per | ||
[POSIX env var definition](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html). | ||
|
||
In order to run the generation scripts directly, there are a few tools we | ||
need to install beforehand. | ||
#### Put the gapic-generator-java jar in its well-known location | ||
|
||
### Install synthtool | ||
Run `cd sdk-platform-java && mvn install -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` | ||
|
||
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`. | ||
Then `mv` the jar into the well-known location of the jar. The | ||
JoeWang1127 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
generation scripts will assume the jar is there. | ||
|
||
```bash | ||
# obtained from .cloudbuild/library_generation/library_generation.Dockerfile | ||
export SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 | ||
```shell | ||
mv /path/to/jar "${HOME}/.library_generation/gapic-generator-java.jar" | ||
``` | ||
|
||
```bash | ||
git clone https://github.com/googleapis/synthtool | ||
cd synthtool | ||
git checkout "${SYNTHTOOL_COMMITTISH}" | ||
python -m pip install --require-hashes -r requirements.txt | ||
python -m pip install --no-deps -e . | ||
python -m synthtool --version | ||
``` | ||
|
||
|
||
## Installing prerequisites | ||
|
||
In order to run the generation scripts directly, there are a few tools we | ||
need to install beforehand. | ||
|
||
### Install the owl-bot CLI | ||
|
||
|
@@ -93,6 +97,7 @@ 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 | ||
|
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 |
Uh oh!
There was an error while loading. Please reload this page.