I'm trying to create a ci pipeline for my code. I have registered a runner with docker executor in my machine. I noticed it is cloning the repository with root privileges inside the docker container
$ ls -l
total 4
drwxrwxrwx 4 root root 4096 Jan 3 18:02 my-repo
Thus, to build the content on my repo I must run some commands with sudo from my .gitlab-ci.yml and I don't want that.
stages:
- build
default:
image: MyImage:latest
build:
stage: build
script:
# I don't want to use sudo here but as my repo is cloned with root privileges I must use sudo.
- sudo ./build -j 1
Is there a way to tell gitlab-runner to clone the repository with user privileges?
edit
My dockerfile creates an image with a user
# Create a user of uid/gid 1000 to match user on most host machines
RUN apt-get update && apt-get -y install sudo && rm -rf /var/lib/apt/lists/*
RUN addgroup --gid 1000 myUser
RUN adduser --disabled-password --gecos "" --uid 1000 --gid 1000 myUser
RUN usermod -a -G sudo myUser
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN usermod -a -G dialout myUser
USER myUser
RUN touch ~/.sudo_as_admin_successful
COPY --chown=1000:1000 export.sh .
RUN ./export.sh
WORKDIR /dev_folder/
CMD ["/bin/bash"]