forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
134 lines (110 loc) · 4.41 KB
/
Copy pathDockerfile
File metadata and controls
134 lines (110 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --- Builder Stage ---
# This stage installs all build dependencies and compiles all Python versions.
FROM marketplace.gcr.io/google/ubuntu2404 AS builder
# TODO(https://github.com/googleapis/librarian/issues/901): Install the necssary dependencies and build tools.
RUN apt-get update && \
apt-get install -y --no-install-recommends \
# Essential for compiling C code
build-essential \
# For downloading secure files
git \
wget \
ca-certificates \
# For running bazelisk commands
openjdk-17-jdk \
zip \
unzip \
# To avoid bazel error
# "python interpreter `python3` not found in PATH"
python3-dev \
# --- Critical libraries for a complete Python build ---
libssl-dev \
zlib1g-dev \
libbz2-dev \
libffi-dev \
libsqlite3-dev \
libreadline-dev \
# ------------------------------------------------------
&& apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
FROM builder AS python
# Install multiple Python versions from source. `make altinstall` is used to
# prevent replacing the system's default python binary.
RUN for PYTHON_VERSION in 3.9.23 3.13.5; do \
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
tar -xvf Python-${PYTHON_VERSION}.tgz && \
cd Python-${PYTHON_VERSION} && \
./configure --enable-optimizations --prefix=/usr/local && \
make -j$(nproc) && \
make altinstall && \
cd / && \
rm -rf Python-${PYTHON_VERSION}* \
; done
# Install pip for each python version
RUN wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' && \
for PYTHON_VERSION in 3.9 3.13; do \
python${PYTHON_VERSION} /tmp/get-pip.py; \
done && \
rm /tmp/get-pip.py
FROM builder AS bazelisk
ENV BAZELISK_VERSION=v1.26.0
# Install Bazelisk
RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_VERSION}/bazelisk-linux-amd64 -O /usr/local/bin/bazelisk && \
chmod +x /usr/local/bin/bazelisk
ENV HOME=/bazel \
USER=bazel
FROM bazelisk AS bazelisk-cache
RUN git clone https://github.com/googleapis/googleapis.git \
&& cd googleapis \
&& bazelisk build //google/example/library/v1:example-library-v1-py
# && bazelisk build //google/cloud/language/v1:language-v1-py
RUN tar -czf /bazel-cache.tar.gz /bazel/.cache/bazel
FROM bazelisk
RUN apt-get update && \
apt-get install -y --no-install-recommends \
# To avoid bazel error
# "python interpreter `python3` not found in PATH"
python3-dev \
&& apt-get clean
# Copy all Python interpreters, their pip executables, and their standard libraries from the builder.
COPY --from=python /usr/local/bin/python3.9 /usr/local/bin/
COPY --from=python /usr/local/lib/python3.9 /usr/local/lib/python3.9
COPY --from=bazelisk /usr/local/include/python3.9 /usr/local/include/python3.9
COPY --from=python /usr/local/bin/python3.13 /usr/local/bin/
COPY --from=python /usr/local/lib/python3.13 /usr/local/lib/python3.13
COPY --from=bazelisk /usr/local/include/python3.9 /usr/local/include/python3.9
# Copy the bazelisk executable from the builder.
# COPY --from=bazelisk /usr/local/bin/bazelisk /usr/local/bin/
COPY --from=bazelisk-cache /bazel-cache.tar.gz /bazel-cache.tar.gz
RUN mkdir /bazel && chmod 777 /bazel
# Create a virtual env and set the Path to fix the missing nox error
# when running the post processor changes.
RUN /usr/local/bin/python3.9 -m venv bazel_env
RUN . bazel_env/bin/activate
ENV PATH=/app/bazel_env/bin:$PATH
RUN git clone --depth 1 https://github.com/googleapis/synthtool.git /tmp/synthtool && \
bazel_env/bin/python3.9 -m pip install /tmp/synthtool nox && \
rm -rf /tmp/synthtool
WORKDIR /app
# Copy the CLI script into the container.
COPY .generator/cli.py .
COPY .generator/run.sh .
RUN chmod a+rx ./cli.py
RUN chmod -R 777 /bazel
ENV HOME=/bazel \
USER=bazel
ENTRYPOINT ["./run.sh"]