Search code examples
dockercontinuous-integrationgitlabrunner

Ownership issue with Shell Runner


I'm trying to setup a pipeline on my django project with a shell runner.

I have 2 jobs :

  • one to build my image
  • one to run the tests.

The first build succeeded but when during my second job I have an ownership issue on my jobs folder :

warning: failed to remove api/__pycache__/resolvers.cpython-37.pyc

Here is my gitlab runner config :

[[runners]]
  name = "Shell Runner"
  url = "https://gitlab.com"
  token = "<my-token>"
  executor = "shell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

Is there a way to have separate jobs for build and test without this problem ?


Solution

  • So after struggling with this I finally found a solution.

    When python install modules in __pycache__ the owner is root so the runner can not delete those files between each jobs.

    To fix this I added ENV PYTHONDONTWRITEBYTECODE 1 in my Dockerfile to prevent the creation of __pycache__ files.