Skip to content

Commit 1752b90

Browse files
authored
chore: update NodeJS post-processor to use MOSS approved images and update node version for tests (#2093)
* chore: update post-processor to use MOSS approved images * update dockerfile * remove all hyphens * Update Dockerfile * install python from apt-get * Update container_test.yaml * Update container_test.yaml * install node from apt-get * Update container_test.yaml * Update Dockerfile
1 parent 906b162 commit 1752b90

File tree

4 files changed

+113
-44
lines changed

4 files changed

+113
-44
lines changed

docker/owlbot/nodejs/Dockerfile

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,79 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Version 0.3.0
16-
1715
# build from the root of this repo:
1816
# docker build -t gcr.io/repo-automation-bots/owlbot-nodejs -f docker/owlbot/nodejs/Dockerfile .
19-
FROM python:3.10.16-bookworm
17+
FROM marketplace.gcr.io/google/debian12:latest
2018
WORKDIR /
2119

20+
## Install Essential Tools, Python 3.11, and xz-utils
21+
22+
# Install necessary tools, the default Python 3 (which is 3.11 on Debian 12),
23+
# python3-venv for virtual environments, and xz-utils for Node.js archives.
2224
RUN apt-get update && \
23-
apt-get upgrade -y
25+
apt-get install -y --no-install-recommends \
26+
ca-certificates \
27+
git \
28+
python3 \
29+
python3-pip \
30+
python3-venv \
31+
curl \
32+
xz-utils && \
33+
rm -rf /var/lib/apt/lists/*
34+
35+
# Verify Python installation and ensure pip is available.
36+
# 'python3' command will now point to Python 3.11.
37+
RUN python3 --version
38+
RUN python3 -m pip --version
39+
40+
41+
## Install Node.js from apt-get
2442

25-
###################### Install nodejs.
26-
RUN curl https://nodejs.org/dist/v18.20.8/node-v18.20.8-linux-x64.tar.xz > /tmp/nodejs.tar.xz
27-
RUN tar -C /usr/local --strip-components=1 -xJf /tmp/nodejs.tar.xz
28-
RUN rm -f /tmp/nodejs.tar.xz
29-
ENV PATH "$PATH:/usr/local/bin"
43+
# Add NodeSource APT repository for Node.js v18
44+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
45+
apt-get install -y nodejs && \
46+
rm -rf /var/lib/apt/lists/*
3047

31-
###################### Install synthtool's requirements.
48+
# Verify Node.js and npm installations
49+
RUN node --version
50+
RUN npm --version
51+
52+
## Install Synthtool and Dependencies
53+
54+
# Create a Python virtual environment for synthtool dependencies.
55+
# This isolates your Python packages from the system Python.
56+
ENV VIRTUAL_ENV=/opt/venv/synthtool
57+
RUN python3 -m venv $VIRTUAL_ENV
58+
# Add the virtual environment's bin directory to the PATH. This effectively "activates"
59+
# the venv for all subsequent commands in this and future RUN layers.
60+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
61+
62+
# Copy requirements.txt and install Python dependencies into the virtual environment.
3263
COPY requirements.txt /synthtool/requirements.txt
3364
RUN pip install --require-hashes -r /synthtool/requirements.txt
3465

35-
# Put synthtool in the PYTHONPATH so owlbot.py scripts will find it.
36-
ENV PYTHONPATH="/synthtool"
66+
# Set PYTHONPATH to ensure synthtool can be found by Python scripts.
67+
# Include the virtual environment's site-packages for completeness, though
68+
# the PATH modification often handles this for executables run directly.
69+
ENV PYTHONPATH="/synthtool:$VIRTUAL_ENV/lib/python3.11/site-packages"
3770

38-
# Tell synthtool to pull templates from this docker image instead of from
39-
# the live repo.
71+
# Configure synthtool to use templates from this image.
4072
ENV SYNTHTOOL_TEMPLATES="/synthtool/synthtool/gcp/templates"
4173

42-
# Copy synthtool.
74+
# Copy synthtool source code and associated Docker files.
4375
COPY synthtool /synthtool/synthtool
4476
COPY docker /synthtool/docker
4577
COPY post-processor-changes.txt /post-processor-changes.txt
4678

47-
# Update permissions so non-root users won't see errors.
48-
RUN find /synthtool -exec chmod a+r {} \;
49-
RUN find /synthtool -type d -exec chmod a+x {} \;
79+
# Update file permissions to prevent errors for non-root users.
80+
RUN find /synthtool -exec chmod a+r {} \; && \
81+
find /synthtool -type d -exec chmod a+x {} \;
5082

83+
# Install Node.js dependencies for post-processing.
5184
RUN cd /synthtool && mkdir node_modules && npm install @google-cloud/[email protected]
5285

86+
## Entrypoint Configuration
87+
88+
# Set the entrypoint to a shell, and the default command to your entrypoint script.
5389
ENTRYPOINT [ "/bin/bash" ]
54-
CMD [ "/synthtool/docker/owlbot/nodejs/entrypoint.sh" ]
90+
CMD [ "/synthtool/docker/owlbot/nodejs/entrypoint.sh" ]

docker/owlbot/nodejs/container_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ commandTests:
55
expectedOutput: ["v18.20.8"]
66
- name: "python"
77
command: ["python", "--version"]
8-
expectedOutput: ["Python 3.10.16"]
8+
expectedOutput: ["Python 3.11.2"]

docker/owlbot/nodejs_mono_repo/Dockerfile

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,76 @@
1616

1717
# build from the root of this repo:
1818
# docker build -t gcr.io/repo-automation-bots/owlbot-nodejs-mono-repo -f docker/owlbot/nodejs_mono_repo/Dockerfile .
19-
FROM python:3.10.12-bookworm
19+
FROM marketplace.gcr.io/google/debian12:latest
2020

2121
WORKDIR /
2222

23-
###################### Install nodejs.
24-
RUN curl https://nodejs.org/dist/v18.17.0/node-v18.17.0-linux-x64.tar.xz > /tmp/nodejs.tar.xz
25-
RUN tar -C /usr/local --strip-components=1 -xJf /tmp/nodejs.tar.xz
26-
RUN rm -f /tmp/nodejs.tar.xz
27-
ENV PATH "$PATH:/usr/local/bin"
23+
## Install Essential Tools, Python 3.11, and xz-utils
2824

29-
###################### Install git and update image to latest.
30-
RUN apt-get update && apt-get install -y git && apt-get upgrade -y
25+
# Update apt and install core tools.
26+
# This includes git, curl, and 'xz-utils' (needed for Node.js tarball decompression).
27+
# python3, python3-pip, and python3-venv are installed to provide Python 3.11 and
28+
# the tools for creating virtual environments.
29+
RUN apt-get update && \
30+
apt-get install -y --no-install-recommends \
31+
ca-certificates \
32+
git \
33+
curl \
34+
xz-utils \
35+
python3 \
36+
python3-pip \
37+
python3-venv && \
38+
rm -rf /var/lib/apt/lists/*
3139

32-
###################### Install synthtool's requirements.
40+
# Verify Python installation and ensure pip is available.
41+
# 'python3' command will now point to Python 3.11.
42+
RUN python3 --version
43+
RUN python3 -m pip --version
44+
45+
## Install Node.js from apt-get
46+
47+
# Add NodeSource APT repository for Node.js v18
48+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
49+
apt-get install -y nodejs && \
50+
rm -rf /var/lib/apt/lists/*
51+
52+
# Verify Node.js and npm installations
53+
RUN node --version
54+
RUN npm --version
55+
56+
## Install Synthtool and Dependencies
57+
58+
# Create a Python virtual environment for synthtool's dependencies.
59+
# This isolates your Python packages from the system Python, preventing conflicts.
60+
ENV VIRTUAL_ENV=/opt/venv/synthtool
61+
RUN python3 -m venv $VIRTUAL_ENV
62+
# Add the virtual environment's bin directory to the PATH. This effectively "activates"
63+
# the venv for all subsequent commands in this and future RUN layers.
64+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
65+
66+
# Copy requirements.txt and install Python dependencies into the virtual environment.
67+
# Since we're in the venv, 'pip' directly refers to the venv's pip.
3368
COPY requirements.txt /synthtool/requirements.txt
3469
RUN pip install --require-hashes -r /synthtool/requirements.txt
3570

36-
# Put synthtool in the PYTHONPATH so owlbot.py scripts will find it.
37-
ENV PYTHONPATH="/synthtool"
71+
# Set PYTHONPATH to ensure synthtool can be found by Python scripts.
72+
# Include the virtual environment's site-packages for completeness.
73+
ENV PYTHONPATH="/synthtool:$VIRTUAL_ENV/lib/python3.11/site-packages"
3874

39-
# Tell synthtool to pull templates from this docker image instead of from
40-
# the live repo.
75+
# Configure synthtool to use templates from this image.
4176
ENV SYNTHTOOL_TEMPLATES="/synthtool/synthtool/gcp/templates"
4277

43-
# Copy synthtool.
78+
# Copy synthtool source code and associated Docker files.
4479
COPY synthtool /synthtool/synthtool
4580
COPY docker /synthtool/docker
4681
COPY post-processor-changes.txt /post-processor-changes.txt
4782

48-
# Update permissions so non-root users won't see errors.
49-
RUN find /synthtool -exec chmod a+r {} \;
50-
RUN find /synthtool -type d -exec chmod a+x {} \;
83+
# Update file permissions to prevent errors for non-root users.
84+
RUN find /synthtool -exec chmod a+r {} \; && \
85+
find /synthtool -type d -exec chmod a+x {} \;
5186

52-
# Install dependencies used for post processing:
53-
# * gts/typescript are used for linting.
54-
# * google-gax and gapic-tools are used for compiling protos.
55-
RUN cd /synthtool && mkdir node_modules && npm i [email protected] [email protected] \
56-
87+
# Install Node.js dependencies for post-processing.
88+
RUN cd /synthtool && mkdir node_modules && npm i [email protected] [email protected] \
89+
5790

5891
ENTRYPOINT [ "/bin/bash", "/synthtool/docker/owlbot/nodejs_mono_repo/entrypoint.sh" ]

docker/owlbot/nodejs_mono_repo/container_test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ schemaVersion: 1.0.0
22
commandTests:
33
- name: "node"
44
command: ["node", "--version"]
5-
expectedOutput: ["v18.17.0"]
5+
expectedOutput: ["v18.20.8"]
66
- name: "python"
77
command: ["python", "--version"]
8-
expectedOutput: ["Python 3.10.12"]
8+
expectedOutput: ["Python 3.11.2"]

0 commit comments

Comments
 (0)