Hey all,
I cannot seem to run python containers built to run as a user, on google cloud build. As soon as I remove the USER (and related commands) from the Dockerfile, everything works.
The container works outside Google cloud build just fine (verified by pulling the exact container built locally and running it)
The build exits with an error like this:
ModuleNotFoundError: No module named 'google'
If I use pipenv to install dependencies instead of requirements.txt, then this:
ModuleNotFoundError: No module named 'pipenv'
I've tried searching around, but here's the only reference to something similar (but this involves cloud run):
Any help would be appreciated!
Thanks,
Sagar
PS: Here's the dockerfile, build config if it helps:
Dockerfile:
FROM python:3.8.12-buster as base
WORKDIR /app/
COPY . /app/
RUN groupadd -r appuser && useradd -g appuser -m -u 1234 appuser
RUN chown -R appuser:appuser /app
USER 1234
ENV PATH="/home/appuser/.local/bin:${PATH}"
RUN pip install --upgrade pip
RUN pip install -r requirements.txt --user
FROM base as release
CMD ["./run.sh"]
Build config:
run.sh simply runs a python script - 'python myscript.py' - or when using pipenv, 'pipenv run myscript.py'
The failure will be anywhere I try to import anything I expect to be installed by pip, for ex:
from google.cloud import storage