spring-cloud / spring-cloud-contract

Support for Consumer Driven Contracts in Spring
https://cloud.spring.io/spring-cloud-contract
Apache License 2.0
720 stars 439 forks source link

Spring Cloud Contract Stub Runner Docker fails to start if repository mounted in read-only mode #2113

Closed jakub-bochenski closed 4 months ago

jakub-bochenski commented 6 months ago

Describe the bug Per https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/docker-project.html#docker-stubrunner

If you want use the stubs that you have built locally, on your host, you should set the -e STUBRUNNER_STUBS_MODE=LOCAL environment variable and mount the volume of your local m2 (-v "${HOME}/.m2/:/home/scc/.m2:ro").

However doing that with an empty repository prevents the runner from starting, as it's trying to write there

Sample

Running Spring Cloud Contract Stub Runner
Please wait for the dependencies to be downloaded...
Exception in thread "main" java.lang.IllegalStateException: Cannot create directory for library at /home/scc/.m2/repository/org/springframework/boot/experimental/spring-boot-thin-launcher/1.0.30.RELEASE/spring-boot-thin-launcher-1.0.30.RELEASE-exec.jar
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.download(ThinJarWrapper.java:169)
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.launch(ThinJarWrapper.java:129)
        at org.springframework.boot.loader.wrapper.ThinJarWrapper.main(ThinJarWrapper.java:107)
jakub-bochenski commented 6 months ago

I think this could be solved if there were 2 repositories inside the docker image:

I think I could simulate this by doing sth like:

docker run  --rm \
-e "STUBRUNNER_IDS=foo.bar:baz:+:stubs:9876" \
-e "STUBRUNNER_REPOSITORY_ROOT=file:///home/scc/contracts-repository" \
-e "STUBRUNNER_STUBS_MODE=REMOTE" \
-v '${HOME}/.m2/:/home/scc/contracts-repository:ro'
-p "8083:8083" \
-p "9876:9876" springcloud/spring-cloud-contract-stub-runner:4.1.1

but having a built in option for that would be nice.

jakub-bochenski commented 5 months ago

Above workaround will not work if you need to use a remote repository too :(

marcingrzejszczak commented 4 months ago

Why can't you just mount it in a read write mode? Ah, now I see, we mention this in the docs. Let me fix it

jakub-bochenski commented 4 months ago

Would still be nice to mount the repository in :ro mode for security