With GitLab CI/CD, how to have the code owned by non-root user in a container?

I have a Dockerfile with the following lines,

FROM python:alpine
RUN addgroup -S java
RUN adduser -s /bin/bash -S -G java java
USER java
WORKDIR /home/java

so that when the image is instantiated (container running), it will run as user ‘java’

When GitLab CI/CD clones the project code however, it is owned by root in directory /home/java

This is unexpected behavior, I would expect it to be owned by user ‘java’

How do I get the code to be cloned by user ‘java’, and owned (user:group), by user:group ‘java:java’?

1 Like