Docker runnes - how does GitLab make my project source code available?

To me it’s not clear how GitLab makes my project source code automatically available in the container I use.

For example, let’s suppose I have the following job:

job:
  stage: test
  image: customimage:latest
  script:
    - find . -name '*.json'

My doubts are the following:

  • How is my source code copied/mounted in the container?
  • How the working directory is automatically set to the source code directory? In other words, why find . directly looks inside my directory source code and I don’t need to type any find /some/strange/directory/myproject/?
  • What happens to the ENTRYPOINT/CMD instructions of the Dockerfile of the image?

Hey Antonio,

  1. & 2. GitLab Runner is automatically cloning/fetching changes from your project into $CI_BUILDS_DIR directory, which by default is something like /builds/<my-group>/<my-project>. You can double check that by running pwd in your job. So, technically WORKDIR is also set to that path when running your job, no matter of which WORKDIR you have in your Docker image.
  2. I’m not 100% sure, but normally they are overridden with bash or sh. I usually do have a habit of pre-building my environments (aka Docker images) in another project, and using their images in relevant project, but most of them are some extended Ubuntu/Alpine images so naturally they use bash/sh.

Best regards!

1 Like