简体   繁体   中英

how to clone without root on gitlab-runner docker

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?

If you need this in the build stage you have to handle the user privileges of your repo from your Dockerfile.

This is a classic example of a build stage from the gitlab-ci:

 build: stage: build script: - docker build --pull -t $CONTAINER_TEST_IMAGE -f./docker/Dockerfile. - docker logout - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY_SERVER - docker push $CONTAINER_TEST_IMAGE only: - tags@group/project

So you can write you code into the dockerfile and then let gitlab to build it

In your case you have two way:

  • 1 Handle the default entry user and permissions of your image
  • 2 Add an entry point in you gitlab-ci file like this:

 image: name: super/sql:experimental entrypoint: ["docker-entrypoint.sh"]

The last one override the default entry point of your container. I think the first point it's the clean and easy way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM