3

I'm trying to run a gitlab service running wiremock on my gitlab ci. I want to take my json files for configure wiremock from the repository and mount as a volume to the wiremock image that run as an service on gitlab ci

.gitlab-ci.yml

variables:
  SHARED_PATH: $CI_PROJECT_PATH/src/main/resources

services:
    - name: wiremock/wiremock
      alias: wiremock
      
image: openjdk:11

deploy:jdk11:
  stage: deploy
  script:
    - 'curl -X POST http://wiremock:8080/'

I want to mount the SHARED_PATH as a volume for the wiremock service

2 Answers2

2

Currently there is no possibility to mount a volume.

See this in the Gitlab issue tracker: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/28121

Csongor Fagyal
  • 514
  • 2
  • 10
-1

The job directory is already mounted in containers started with services:. All services have the job directory mounted as a volume under /builds.

If you need to move that to a specific location inside the service image, you can use services:[]:entrypoint: to define an entrypoint that copies the files, creates symlinks, or whatever you need to do.

For example, you might do something like this:

services:
  - name: wiremock/wiremock
    entrypoint: ["/bin/bash", "-c", "cp /builds/ /home/wiremock/builds && /docker-entrypoint.sh"]
    # change the source/destination as needed

See the services documentation for more information.

sytech
  • 29,298
  • 3
  • 45
  • 86
  • I think the service starts before I have the git repo on /builds/ at this point looks like /builds/ it's empty and I can't copy the content from my repo – Jonathan Amaya May 13 '22 at 00:52
  • Aw shucks, yeah, you're right @JonathanAmaya. Seems like you would have to make the entrypoint wait until the clone is done. But in principle it _should_ work, say, if you added a big sleep at the beginning like `sleep 60 && cp builds [...]` though obviously not ideal. The big downside is you spend 30 seconds just waiting for the timeout... and you have to make sure wiremock is up in the job. That can be avoided, but would be somewhat complex to do.... If wiremock can pick up filesystem changes on-the-fly, you could try just making a symlink and starting wiremock right away. Hmm.... – sytech May 13 '22 at 04:01
  • 1
    Just for all people who found this question. You can find the "wait until git clone" working workaround here https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3210. – Pavel Martynov Jan 18 '23 at 14:01