5

I am using docker-compose in my project and spinning up the rodolpheche/wiremock image like below

  wiremock:
image: rodolpheche/wiremock
ports:
  - "xxxx:xxxxx"
volumes:
  - ./src/wiremock:/home/wiremock

Now I want to add some random body transformer extension to the above wiremock image. extension path is = org.m.BodyRandomizer

I have seen the docker page(https://hub.docker.com/r/rodolpheche/wiremock/) regarding adding an extension but I could not get much.

Manoj Kumar
  • 68
  • 1
  • 7
  • I noticed you marked the answer as accepted and then undo it, what did not work about it? Maybe I can provide an alternative suggestion :) – Sven Hakvoort Dec 07 '18 at 07:18
  • Hi Sven. Actual my extension is there in one of our internal libraries and we are using in many other repos. I am wondering if there is any way I can add this extension which is there in lib and without defining it in each and every repo. – Manoj Kumar Dec 07 '18 at 07:25
  • You mean that you want that every time you start this image like described in your question it will automatically include this extension? So a custom docker file? – Sven Hakvoort Dec 07 '18 at 07:27
  • My worry is do I need to move my extension file ie (org.m.BodyRandomizer.scala) (which is there in lib)to each and every repository to src/wiremock/etensions where I am using docker wiremock. Or Is there way I can just give my extension class path in docker-compose file so that it will pick it up run. – Manoj Kumar Dec 07 '18 at 07:40
  • You can just place it anywhere on the docker host, for example `~/extensions` and bind that volume to `/var/wiremock/extensions`, it does not have to be in your project directory. This will allow you to use this directory for every repo you want to containerize in docker – Sven Hakvoort Dec 07 '18 at 07:42
  • I am using sbt project and I am downloading the jar file as one of the dependency and it will there in $HOME/ivy2/cache/our.jar and how can move this jar to src/wiremock/etensions – Manoj Kumar Dec 07 '18 at 09:35
  • I don't quite understand this next problem, because first you mention that you do not want to have/define it in every repo and now you want it again in the project dir? Could you update the question explaining this clearly? – Sven Hakvoort Dec 07 '18 at 09:51

2 Answers2

4

You will need to add an additional volume mount to /var/wiremock/extensions to which you bind your local folder which contains the extension you want to add. In addition to that you will have to specify a command option in your compose to execute the call --extensions com.opentable.extension.BodyTransformer.

This will result in something like this:

wiremock:
    image: rodolpheche/wiremock
    ports:
      - "xxxx:xxxxx"
    command: --extensions com.opentable.extension.BodyTransformer
    volumes:
      - ./src/wiremock:/home/wiremock
      - ./extension_dir:/var/wiremock/extensions

I hope this helps you

Sven Hakvoort
  • 3,543
  • 2
  • 17
  • 34
0

While Sven's answer is correct it didn't work for me when I've had command options separated by new lines e.g.

    command:
      - -global-response-templating
      - -no-request-journal
      - -extensions org.wiremock.webhooks.Webhooks

It worked before, but without the extensions parameter. However it has started to work for me when I've changed this to a single quoted line like

    command: "--extensions org.wiremock.webhooks.Webhooks --global-response-templating --no-request-journal"
ZZ 5
  • 1,744
  • 26
  • 41