Skip to content

Commit c908d4a

Browse files
ohmayrparthea
andauthored
feat: update docker to remove user (#14258)
Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 1bc96bf commit c908d4a

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

.generator/Dockerfile

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -138,38 +138,6 @@ RUN apt-get update && \
138138
&& apt-get clean && \
139139
rm -rf /var/lib/apt/lists/*
140140

141-
# Create the group and user, but only if they don't already exist.
142-
# NOTE: A user needs to be configured by passing down the UID/GID with the
143-
# docker build command to allow the user running the librarian CLI to have
144-
# the permissions within the /app and /bazel_cache directories in the following way:
145-
# DOCKER_BUILDKIT=1 docker build -f .generator/Dockerfile --build-arg UID=$(id -u) --build-arg GID=$(id -g) -t python-librarian-generator:latest .
146-
ARG UID=1000
147-
ARG GID=1000
148-
149-
RUN if ! getent group $GID > /dev/null; then \
150-
groupadd -g $GID myuser; \
151-
fi && \
152-
if ! getent passwd $UID > /dev/null; then \
153-
useradd -u $UID -g $GID -ms /bin/bash myuser; \
154-
fi
155-
156-
# 2025/08/05 08:27:44 could not create directory /.cache/bazelisk: mkdir /.cache: permission denied
157-
# Traceback (most recent call last):
158-
# File "/app/./cli.py", line 147, in _build_bazel_target
159-
# subprocess.run(
160-
# File "/usr/local/lib/python3.9/subprocess.py", line 528, in run
161-
# raise CalledProcessError(retcode, process.args,
162-
# subprocess.CalledProcessError: Command '['bazelisk', '--output_base=/bazel_cache/_bazel_ubuntu/output_base', 'build', '--disk_cache=/bazel_cache/_bazel_ubuntu/cache/repos', '--incompatible_strict_action_env', '//google/cloud/language/v1beta2:language-v1beta2-py']' returned non-zero exit status 1
163-
# We'll point both to the /bazel_cache directory which will be mounted as a volume.
164-
ENV BAZELISK_HOME="/bazel_cache/bazelisk"
165-
ENV BAZEL_HOME="/bazel_cache/bazel"
166-
RUN mkdir -p ${BAZEL_HOME}/_bazel_ubuntu/cache/repos \
167-
${BAZEL_HOME}/_bazel_ubuntu/output_base \
168-
${BAZELISK_HOME} && \
169-
chown -R $UID:$GID ${BAZEL_HOME} ${BAZELISK_HOME}
170-
171-
USER $UID
172-
173141
# Copy all Python interpreters, their pip executables, and their standard libraries from the builder.
174142
COPY --from=builder /usr/local/bin/python3.9 /usr/local/bin/
175143
COPY --from=builder /usr/local/lib/python3.9 /usr/local/lib/python3.9
@@ -190,7 +158,8 @@ COPY --from=builder /usr/local/lib/python3.13 /usr/local/lib/python3.13
190158
COPY --from=builder /usr/local/bin/bazelisk /usr/local/bin/
191159

192160
# Copy bazel cache from the builder.
193-
COPY --from=builder --chown=$UID:$GID /bazel_cache /bazel_cache
161+
COPY --from=builder /bazel_cache /bazel_cache
162+
RUN chmod -R 777 /bazel_cache
194163

195164
# Set the working directory in the container.
196165
WORKDIR /app
@@ -207,7 +176,7 @@ bazel_env/bin/python3.9 -m pip install /tmp/synthtool nox && \
207176
rm -rf /tmp/synthtool
208177

209178
# Copy the CLI script into the container.
210-
COPY --chown=$UID:$GID .generator/cli.py .
179+
COPY .generator/cli.py .
211180
RUN chmod a+rx ./cli.py
212181

213182
ENTRYPOINT ["python3.9", "./cli.py"]

0 commit comments

Comments
 (0)