Skip to content

Commit ae493f0

Browse files
authored
chore: create a new Dockerfile (#3474)
In this PR: - Create a Dockerfile to use recommended OS image from Airlock. b/384540059
1 parent c334a0c commit ae493f0

File tree

2 files changed

+150
-1
lines changed

2 files changed

+150
-1
lines changed

.cloudbuild/library_generation/cloudbuild-library-generation-push-prod.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ steps:
2727
"-t", "${_SHA_IMAGE_ID}",
2828
"-t", "${_LATEST_IMAGE_ID}",
2929
"-t", "${_VERSIONED_IMAGE_ID}",
30-
"--file", ".cloudbuild/library_generation/library_generation.Dockerfile", "."]
30+
"-f", ".cloudbuild/library_generation/library_generation_airlock.Dockerfile",
31+
"."
32+
]
3133
id: library-generation-build
3234
waitFor: ["-"]
3335
env:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# install gapic-generator-java in a separate layer so we don't overload the image
16+
# with the transferred source code and jars
17+
18+
# 3.9.9-eclipse-temurin-11-alpine
19+
FROM us-docker.pkg.dev/artifact-foundry-prod/docker-3p-trusted/maven@sha256:d3f04985c6a68415e36c0a6468d0f8316f27d4dbee77bc459257ba444224bd9f AS ggj-build
20+
21+
WORKDIR /sdk-platform-java
22+
COPY . .
23+
# {x-version-update-start:gapic-generator-java:current}
24+
ENV DOCKER_GAPIC_GENERATOR_VERSION="2.51.1-SNAPSHOT"
25+
# {x-version-update-end}
26+
27+
RUN mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
28+
RUN cp "/root/.m2/repository/com/google/api/gapic-generator-java/${DOCKER_GAPIC_GENERATOR_VERSION}/gapic-generator-java-${DOCKER_GAPIC_GENERATOR_VERSION}.jar" \
29+
"./gapic-generator-java.jar"
30+
31+
# 3.20.1
32+
FROM us-docker.pkg.dev/artifact-foundry-prod/docker-3p-trusted/alpine@sha256:dabf91b69c191a1a0a1628fd6bdd029c0c4018041c7f052870bb13c5a222ae76 as glibc-compat
33+
34+
RUN apk update && apk add git sudo
35+
# This SHA is the latest known-to-work version of this binary compatibility tool
36+
ARG GLIB_MUS_SHA=e94aca542e3ab08b42aa0b0d6e72478b935bb8e8
37+
WORKDIR /home
38+
39+
# Install compatibility layer to run glibc-based programs (such as the
40+
# grpc plugin).
41+
# Alpine, by default, only supports musl-based binaries, and there is no public
42+
# downloadable distribution of the grpc plugin that is Alpine (musl) compatible.
43+
# This is one of the recommended approaches to ensure glibc-compatibility
44+
# as per https://wiki.alpinelinux.org/wiki/Running_glibc_programs
45+
RUN git clone https://gitlab.com/manoel-linux1/GlibMus-HQ.git
46+
WORKDIR /home/GlibMus-HQ
47+
# We lock the tool to the latest known-to-work version
48+
RUN git checkout "${GLIB_MUS_SHA}"
49+
RUN chmod a+x compile-x86_64-alpine-linux.sh
50+
RUN sh compile-x86_64-alpine-linux.sh
51+
52+
# 3.12.7-alpine3.20
53+
FROM us-docker.pkg.dev/artifact-foundry-prod/docker-3p-trusted/python@sha256:b83d5ec7274bee17d2f4bd0bfbb082f156241e4513f0a37c70500e1763b1d90d as final
54+
55+
ARG OWLBOT_CLI_COMMITTISH=8b7d94b4a8ad0345aeefd6a7ec9c5afcbeb8e2d7
56+
ARG PROTOC_VERSION=25.5
57+
ARG GRPC_VERSION=1.69.0
58+
ARG JAVA_FORMAT_VERSION=1.7
59+
ENV HOME=/home
60+
ENV OS_ARCHITECTURE="linux-x86_64"
61+
62+
# install OS tools
63+
RUN apk update && apk add unzip curl rsync openjdk11 jq bash nodejs npm git
64+
65+
SHELL [ "/bin/bash", "-c" ]
66+
67+
# Copy glibc shared objects to enable execution of the grpc plugin.
68+
# This list was obtained via `libtree -pvvv /grpc/*` in the final container as
69+
# well as inspecting the modifications done by compile-x86_64-alpine-linux.sh
70+
# in the glibc-compat stage using the `dive` command.
71+
COPY --from=glibc-compat /etc/libgcc* /etc/
72+
COPY --from=glibc-compat /lib64/ld-linux-x86-64.so.2 /lib64/
73+
COPY --from=glibc-compat /lib/GLIBCFAKE.so.0 /lib/
74+
COPY --from=glibc-compat /lib/ld-linux-x86-64.so.2 /lib/
75+
COPY --from=glibc-compat /lib/libpthread* /lib/
76+
COPY --from=glibc-compat /lib/libucontext* /lib/
77+
COPY --from=glibc-compat /lib/libc.* /lib/
78+
COPY --from=glibc-compat /usr/lib/libgcc* /usr/lib/
79+
COPY --from=glibc-compat /usr/lib/libstdc* /usr/lib/
80+
COPY --from=glibc-compat /usr/lib/libobstack* /usr/lib/
81+
82+
83+
# copy source code
84+
COPY hermetic_build/common /src/common
85+
COPY hermetic_build/library_generation /src/library_generation
86+
87+
# install protoc
88+
WORKDIR /protoc
89+
RUN source /src/library_generation/utils/utilities.sh \
90+
&& download_protoc "${PROTOC_VERSION}" "${OS_ARCHITECTURE}"
91+
# we indicate protoc is available in the container via env vars
92+
ENV DOCKER_PROTOC_LOCATION=/protoc/bin
93+
ENV DOCKER_PROTOC_VERSION="${PROTOC_VERSION}"
94+
95+
# install grpc
96+
WORKDIR /grpc
97+
RUN source /src/library_generation/utils/utilities.sh \
98+
&& download_grpc_plugin "${GRPC_VERSION}" "${OS_ARCHITECTURE}"
99+
# similar to protoc, we indicate grpc is available in the container via env vars
100+
ENV DOCKER_GRPC_LOCATION="/grpc/protoc-gen-grpc-java.exe"
101+
102+
# Here we transfer gapic-generator-java from the previous stage.
103+
# Note that the destination is a well-known location that will be assumed at runtime
104+
# We hard-code the location string to avoid making it configurable (via ARG) as
105+
# well as to avoid it making it overridable at runtime (via ENV).
106+
COPY --from=ggj-build "/sdk-platform-java/gapic-generator-java.jar" "${HOME}/.library_generation/gapic-generator-java.jar"
107+
RUN chmod 755 "${HOME}/.library_generation/gapic-generator-java.jar"
108+
ENV GAPIC_GENERATOR_LOCATION="${HOME}/.library_generation/gapic-generator-java.jar"
109+
110+
RUN python -m pip install --upgrade pip
111+
112+
# install main scripts as a python package
113+
WORKDIR /
114+
RUN python -m pip install --require-hashes -r src/common/requirements.txt
115+
RUN python -m pip install src/common
116+
RUN python -m pip install --require-hashes -r src/library_generation/requirements.txt
117+
RUN python -m pip install src/library_generation
118+
119+
# install the owl-bot CLI
120+
WORKDIR /tools
121+
RUN git clone https://github.com/googleapis/repo-automation-bots
122+
WORKDIR /tools/repo-automation-bots/packages/owl-bot
123+
RUN git checkout "${OWLBOT_CLI_COMMITTISH}"
124+
RUN npm i && npm run compile && npm link
125+
RUN owl-bot copy-code --version
126+
RUN chmod o+rx $(which owl-bot)
127+
RUN apk del -r npm && apk cache clean
128+
129+
# download the Java formatter
130+
ADD https://maven-central.storage-download.googleapis.com/maven2/com/google/googlejavaformat/google-java-format/${JAVA_FORMAT_VERSION}/google-java-format-${JAVA_FORMAT_VERSION}-all-deps.jar \
131+
"${HOME}"/.library_generation/google-java-format.jar
132+
RUN chmod 755 "${HOME}"/.library_generation/google-java-format.jar
133+
ENV JAVA_FORMATTER_LOCATION="${HOME}/.library_generation/google-java-format.jar"
134+
135+
# allow users to access the script folders
136+
RUN chmod -R o+rx /src
137+
138+
# set dummy git credentials for the empty commit used in postprocessing
139+
# we use system so all users using the container will use this configuration
140+
RUN git config --system user.email "[email protected]"
141+
RUN git config --system user.name "Cloud Java Bot"
142+
143+
# allow read-write for /home and execution for binaries in /home/.nvm
144+
RUN chmod -R a+rw /home
145+
146+
WORKDIR /workspace
147+
ENTRYPOINT [ "python", "/src/library_generation/cli/entry_point.py", "generate" ]

0 commit comments

Comments
 (0)