Skip to content

Commit 27b181b

Browse files
committed
chore: create a new dockerfile
1 parent c334a0c commit 27b181b

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
FROM us-docker.pkg.dev/artifact-foundry-prod/docker-3p-trusted/[email protected] AS ggj-build
19+
20+
WORKDIR /sdk-platform-java
21+
COPY . .
22+
# {x-version-update-start:gapic-generator-java:current}
23+
ENV DOCKER_GAPIC_GENERATOR_VERSION="2.51.1-SNAPSHOT"
24+
# {x-version-update-end}
25+
26+
RUN mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
27+
RUN cp "/root/.m2/repository/com/google/api/gapic-generator-java/${DOCKER_GAPIC_GENERATOR_VERSION}/gapic-generator-java-${DOCKER_GAPIC_GENERATOR_VERSION}.jar" \
28+
"./gapic-generator-java.jar"
29+
30+
FROM us-docker.pkg.dev/artifact-foundry-prod/docker-3p-trusted/alpine@sha256:647a509e17306d117943c7f91de542d7fb048133f59c72dff7893cffd1836e11 as glibc-compat
31+
32+
RUN apk add git sudo
33+
# This SHA is the latest known-to-work version of this binary compatibility tool
34+
ARG GLIB_MUS_SHA=e94aca542e3ab08b42aa0b0d6e72478b935bb8e8
35+
WORKDIR /home
36+
37+
# Install compatibility layer to run glibc-based programs (such as the
38+
# grpc plugin).
39+
# Alpine, by default, only supports musl-based binaries, and there is no public
40+
# downloadable distribution of the grpc plugin that is Alpine (musl) compatible.
41+
# This is one of the recommended approaches to ensure glibc-compatibility
42+
# as per https://wiki.alpinelinux.org/wiki/Running_glibc_programs
43+
RUN git clone https://gitlab.com/manoel-linux1/GlibMus-HQ.git
44+
WORKDIR /home/GlibMus-HQ
45+
# We lock the tool to the latest known-to-work version
46+
RUN git checkout "${GLIB_MUS_SHA}"
47+
RUN chmod a+x compile-x86_64-alpine-linux.sh
48+
RUN sh compile-x86_64-alpine-linux.sh
49+
50+
FROM us-docker.pkg.dev/artifact-foundry-prod/docker-3p-trusted/[email protected] as final
51+
52+
ARG OWLBOT_CLI_COMMITTISH=8b7d94b4a8ad0345aeefd6a7ec9c5afcbeb8e2d7
53+
ARG PROTOC_VERSION=25.5
54+
ARG GRPC_VERSION=1.69.0
55+
ARG JAVA_FORMAT_VERSION=1.7
56+
ENV HOME=/home
57+
ENV OS_ARCHITECTURE="linux-x86_64"
58+
59+
# install OS tools
60+
RUN apk update && apk add unzip curl rsync openjdk11 jq bash nodejs npm git
61+
62+
SHELL [ "/bin/bash", "-c" ]
63+
64+
# Copy glibc shared objects to enable execution of the grpc plugin.
65+
# This list was obtained via `libtree -pvvv /grpc/*` in the final container as
66+
# well as inspecting the modifications done by compile-x86_64-alpine-linux.sh
67+
# in the glibc-compat stage using the `dive` command.
68+
COPY --from=glibc-compat /etc/libgcc* /etc/
69+
COPY --from=glibc-compat /lib64/ld-linux-x86-64.so.2 /lib64/
70+
COPY --from=glibc-compat /lib/GLIBCFAKE.so.0 /lib/
71+
COPY --from=glibc-compat /lib/ld-linux-x86-64.so.2 /lib/
72+
COPY --from=glibc-compat /lib/libpthread* /lib/
73+
COPY --from=glibc-compat /lib/libucontext* /lib/
74+
COPY --from=glibc-compat /lib/libc.* /lib/
75+
COPY --from=glibc-compat /usr/lib/libgcc* /usr/lib/
76+
COPY --from=glibc-compat /usr/lib/libstdc* /usr/lib/
77+
COPY --from=glibc-compat /usr/lib/libobstack* /usr/lib/
78+
COPY --from=glibc-compat /lib/libm.so.6 /usr/lib/
79+
COPY --from=glibc-compat /usr/lib/libucontext.so.1 /usr/lib/
80+
81+
82+
# copy source code
83+
COPY hermetic_build/common /src/common
84+
COPY hermetic_build/library_generation /src/library_generation
85+
86+
# install protoc
87+
WORKDIR /protoc
88+
RUN source /src/library_generation/utils/utilities.sh \
89+
&& download_protoc "${PROTOC_VERSION}" "${OS_ARCHITECTURE}"
90+
# we indicate protoc is available in the container via env vars
91+
ENV DOCKER_PROTOC_LOCATION=/protoc/bin
92+
ENV DOCKER_PROTOC_VERSION="${PROTOC_VERSION}"
93+
94+
# install grpc
95+
WORKDIR /grpc
96+
RUN source /src/library_generation/utils/utilities.sh \
97+
&& download_grpc_plugin "${GRPC_VERSION}" "${OS_ARCHITECTURE}"
98+
# similar to protoc, we indicate grpc is available in the container via env vars
99+
ENV DOCKER_GRPC_LOCATION="/grpc/protoc-gen-grpc-java.exe"
100+
101+
# Here we transfer gapic-generator-java from the previous stage.
102+
# Note that the destination is a well-known location that will be assumed at runtime
103+
# We hard-code the location string to avoid making it configurable (via ARG) as
104+
# well as to avoid it making it overridable at runtime (via ENV).
105+
COPY --from=ggj-build "/sdk-platform-java/gapic-generator-java.jar" "${HOME}/.library_generation/gapic-generator-java.jar"
106+
RUN chmod 755 "${HOME}/.library_generation/gapic-generator-java.jar"
107+
ENV GAPIC_GENERATOR_LOCATION="${HOME}/.library_generation/gapic-generator-java.jar"
108+
109+
RUN python -m pip install --upgrade pip
110+
111+
# install main scripts as a python package
112+
WORKDIR /
113+
RUN python -m pip install --require-hashes -r src/common/requirements.txt
114+
RUN python -m pip install src/common
115+
RUN python -m pip install --require-hashes -r src/library_generation/requirements.txt
116+
RUN python -m pip install src/library_generation
117+
118+
# install the owl-bot CLI
119+
WORKDIR /tools
120+
RUN git clone https://github.com/googleapis/repo-automation-bots
121+
WORKDIR /tools/repo-automation-bots/packages/owl-bot
122+
RUN git checkout "${OWLBOT_CLI_COMMITTISH}"
123+
RUN npm i && npm run compile && npm link
124+
RUN owl-bot copy-code --version
125+
RUN chmod o+rx $(which owl-bot)
126+
RUN apk del -r npm && apk cache clean
127+
128+
# download the Java formatter
129+
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 \
130+
"${HOME}"/.library_generation/google-java-format.jar
131+
RUN chmod 755 "${HOME}"/.library_generation/google-java-format.jar
132+
ENV JAVA_FORMATTER_LOCATION="${HOME}/.library_generation/google-java-format.jar"
133+
134+
# allow users to access the script folders
135+
RUN chmod -R o+rx /src
136+
137+
# set dummy git credentials for the empty commit used in postprocessing
138+
# we use system so all users using the container will use this configuration
139+
RUN git config --system user.email "[email protected]"
140+
RUN git config --system user.name "Cloud Java Bot"
141+
142+
# allow read-write for /home and execution for binaries in /home/.nvm
143+
RUN chmod -R a+rw /home
144+
145+
WORKDIR /workspace
146+
ENTRYPOINT [ "python", "/src/library_generation/cli/entry_point.py", "generate" ]

0 commit comments

Comments
 (0)