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 440 forks source link

Enable users to configure Wiremock server via environment variables #1268

Open Sic4Parvis9Magna opened 4 years ago

Sic4Parvis9Magna commented 4 years ago

Description: There were some discussions related to the subject of that issue. See here: issue#1 issue#2 It seems like there is a request for such functionality.

Possible approach From my perspective, it can be solved by introducing a bean of com.github.tomakehurst.wiremock.core.Options type via a class annotated with @ConfigurationProperties(prefix="wiremock.embedded")

marcingrzejszczak commented 4 years ago

It seems like there is a request for such functionality.

Currently there are 2 people ;)

I'll think about this. Thanks for filing the issue.

Sic4Parvis9Magna commented 4 years ago

It seems like there is a request for such functionality.

Currently there are 2 people ;)

I'll think about this. Thanks for filing the issue.

Yep, that's not many people requested that functionality so far. It will make the docker image more flexible for using as a base image and so on. If my guess is correct implementation would not take a lot of effort.

Thanks for considering it as a possible feature.

plamentotev commented 3 years ago

I have use case similar to #711. I want to proxy requests that does not match the stubs to the real API. proxyBaseUrl option from standalone Wiremock application just adds catch all mapping that proxies the request. It is easy to add this additional mapping as Wiremock by default looks into src/test/resources/mappings. I am using the Docker image to run the stubs. Mounting the additional mapping into src/test/resources/mappings works but src/test/resources seems to be a bit random outside of Maven/Gradle project.

To configure this path is quite easy. I've implemented HttpServerStubConfigurer<WireMockConfiguration> that sets wireMockConfiguration.withRootDirectory() to the desired value. Then I've set the STUBRUNNER_HTTP_SERVER_STUB_CONFIGURER environment variable to my HttpServerStubConfigurer implementation.

While this works the downside is that I need to build my own stub runner and Docker image just to configure wireMockConfiguration. At the same time there is WireMockHttpServerStubConfigurer that is intended (or not?) to do just that. I wonder why the current implementation is no-op. Maybe StubRunnerOptions can be extended with httpServerStubConfigurerOptions in addition to httpServerStubConfigurer so the HttpServerStubConfigurer can use it to configure the HTTP Server stub. And then WireMockHttpServerStubConfigurer can use it to configure Wiremock. Does that makes sense?

If this is implemented then my use case (and the other mentioned here) are just a matter of setting environment variable (or two) and would not require implementing custom HttpServerStubConfigurer.

protux commented 2 years ago

Hello @marcingrzejszczak, this is useful for anyone using wiremock e.g. in a docker-compose setup where wiremock is started standalone to mock away other services not needed in a local environment. So with me, there are at least 3 people having a demand (and probably more). Kind Regards

marcingrzejszczak commented 2 years ago

Sure, there's already some work in progress in this PR https://github.com/spring-cloud/spring-cloud-contract/pull/1687 but it's not yet ready for review. If you want to help out, please be my guest