WithWatchStaticMappings doesn't respect new files #636

Closed
opened 2025-12-29 08:31:31 +01:00 by adam · 15 comments
Owner

Originally created by @mantasburokas on GitHub (Oct 2, 2024).

Originally assigned to: @StefH on GitHub.

Describe the bug

"--WatchStaticMappings true" command doesn't respect new files copied. This is a bit annoying in docker in docker configuration where I can't bind mappings using WithMappings() as docker bind always references the host and not the parent container.

Expected behavior:

On new file copy static mappings are read.

Test to reproduce

    private readonly WireMockContainer _wireMockContainer = new WireMockContainerBuilder()
        .WithWatchStaticMappings(true)
        .WithPortBinding(5000, 80)
        .Build();

   await _wireMockContainer.CopyAsync($"{AppDomain.CurrentDomain.BaseDirectory}Mappings", "/app/__admin/mappings");

Check mappings or make request

Workaround exists using admin client: await _wireMockContainer.CreateWireMockAdminClient().ResetMappingsAsync(true);

Originally created by @mantasburokas on GitHub (Oct 2, 2024). Originally assigned to: @StefH on GitHub. ### Describe the bug "--WatchStaticMappings true" command doesn't respect new files copied. This is a bit annoying in docker in docker configuration where I can't bind mappings using WithMappings() as docker bind always references the host and not the parent container. ### Expected behavior: On new file copy static mappings are read. ### Test to reproduce ``` c# private readonly WireMockContainer _wireMockContainer = new WireMockContainerBuilder() .WithWatchStaticMappings(true) .WithPortBinding(5000, 80) .Build(); await _wireMockContainer.CopyAsync($"{AppDomain.CurrentDomain.BaseDirectory}Mappings", "/app/__admin/mappings"); ``` Check mappings or make request ### Other related info Workaround exists using admin client: `await _wireMockContainer.CreateWireMockAdminClient().ResetMappingsAsync(true);`
adam added the bug label 2025-12-29 08:31:31 +01:00
adam closed this issue 2025-12-29 08:31:31 +01:00
Author
Owner

@StefH commented on GitHub (Oct 2, 2024):

Sounds familiar.

Related to this?
eb7e6c397f/src/WireMock.Net.Aspire/WireMockServerBuilderExtensions.cs (L57)

@StefH commented on GitHub (Oct 2, 2024): Sounds familiar. Related to this? https://github.com/WireMock-Net/WireMock.Net/blob/eb7e6c397f686859401b3b527d68ad55dd87ff6b/src/WireMock.Net.Aspire/WireMockServerBuilderExtensions.cs#L57
Author
Owner

@mantasburokas commented on GitHub (Oct 2, 2024):

If that's the correct use then no dice - mappings are still empty.

    private readonly WireMockContainer _wireMockContainer = new WireMockContainerBuilder()
        .WithWatchStaticMappings(true)
        .WithPortBinding(5000, 80)
        .WithEnvironment("DOTNET_USE_POLLING_FILE_WATCHER", "1") // https://khalidabuhakmeh.com/aspnet-docker-gotchas-and-workarounds#configuration-reloads-and-filesystemwatcher 
        .Build();
@mantasburokas commented on GitHub (Oct 2, 2024): If that's the correct use then no dice - mappings are still empty. ``` private readonly WireMockContainer _wireMockContainer = new WireMockContainerBuilder() .WithWatchStaticMappings(true) .WithPortBinding(5000, 80) .WithEnvironment("DOTNET_USE_POLLING_FILE_WATCHER", "1") // https://khalidabuhakmeh.com/aspnet-docker-gotchas-and-workarounds#configuration-reloads-and-filesystemwatcher .Build(); ```
Author
Owner

@StefH commented on GitHub (Oct 2, 2024):

Mmm.

The only thing I can build is a simple polling to a new rest endpoint like /__admin/mappings/readStaticMappings.

@StefH commented on GitHub (Oct 2, 2024): Mmm. - https://learn.microsoft.com/en-us/answers/questions/1539195/filewatcher-helper-system-events-not-triggered-in - https://forums.docker.com/t/file-system-watch-does-not-work-with-mounted-volumes/12038 The only thing I can build is a simple polling to a new rest endpoint like `/__admin/mappings/readStaticMappings`.
Author
Owner

@StefH commented on GitHub (Oct 2, 2024):

https://github.com/WireMock-Net/WireMock.Net/pull/1189

@StefH commented on GitHub (Oct 2, 2024): https://github.com/WireMock-Net/WireMock.Net/pull/1189
Author
Owner

@StefH commented on GitHub (Oct 2, 2024):

@mantasburokas
Can you try 1.6.7-preview-01 ?

(Make sure to delete your local ":latest" image for WireMock.Net)

Note that I only tested on windows.

@StefH commented on GitHub (Oct 2, 2024): @mantasburokas Can you try 1.6.7-preview-01 ? (Make sure to delete your local ":latest" image for WireMock.Net) Note that I only tested on windows.
Author
Owner

@mantasburokas commented on GitHub (Oct 3, 2024):

I have deleted all existing images and containers, upgraded the package but still no mappings. Added a breakpoint on CopyAsync to observe if maybe mappings appear after some delay but they don't. I also ran the unit tests on windows.

@mantasburokas commented on GitHub (Oct 3, 2024): I have deleted all existing images and containers, upgraded the package but still no mappings. Added a breakpoint on CopyAsync to observe if maybe mappings appear after some delay but they don't. I also ran the unit tests on windows.
Author
Owner

@StefH commented on GitHub (Oct 3, 2024):

Ah sorry I misunderstood your question.
I thought you were just using this to mount this folder to the internal __admin/mappings folder.

    .WithMappings($"{AppDomain.CurrentDomain.BaseDirectory}Mappings")

This has been solved in the preview version.


BTW, when running on windows and using a windows container, the second argument should be c:\\app\\__admin\\mappings ?

@StefH commented on GitHub (Oct 3, 2024): Ah sorry I misunderstood your question. I thought you were just using this to mount this folder to the internal __admin/mappings folder. ``` c# .WithMappings($"{AppDomain.CurrentDomain.BaseDirectory}Mappings") ``` This has been solved in the preview version. --- BTW, when running on windows and using a windows container, the second argument should be `c:\\app\\__admin\\mappings` ?
Author
Owner

@mantasburokas commented on GitHub (Oct 3, 2024):

Yeah, but I am running on windows for local setup and using linux containers. So just to re-iterate, the problem is that WithMappings() works as expected on local setup but in docker in docker configuration I can't mount the path from parent container. That's why I'd like to copy the mappings directory by hand and expect the watch flag to pick it up.

@mantasburokas commented on GitHub (Oct 3, 2024): Yeah, but I am running on windows for local setup and using linux containers. So just to re-iterate, the problem is that WithMappings() works as expected on local setup but in docker in docker configuration I can't mount the path from parent container. That's why I'd like to copy the mappings directory by hand and expect the watch flag to pick it up.
Author
Owner

@StefH commented on GitHub (Oct 3, 2024):

Can you give an example how you use these multiple docker containers?

@StefH commented on GitHub (Oct 3, 2024): Can you give an example how you use these multiple docker containers?
Author
Owner

@mantasburokas commented on GitHub (Oct 3, 2024):

I can prepare a test solution but I am bit busy this week. Basically I have dockerfile that runs my tests and since my tests run in docker then wiremock becomes a docker in docker setup.

@mantasburokas commented on GitHub (Oct 3, 2024): I can prepare a test solution but I am bit busy this week. Basically I have dockerfile that runs my tests and since my tests run in docker then wiremock becomes a docker in docker setup.
Author
Owner

@StefH commented on GitHub (Oct 3, 2024):

What happens when you just go into the WireMock.Net container and touch or create a file? Is there an update triggered? (You can checkout the logs to see this).

@StefH commented on GitHub (Oct 3, 2024): What happens when you just go into the WireMock.Net container and `touch` or create a file? Is there an update triggered? (You can checkout the logs to see this).
Author
Owner

@StefH commented on GitHub (Oct 6, 2024):

Please test new version: 1.6.7-preview-02 (make sure to delete the all local versions to be sure you get the latest)
When you do a CopyAsync after the container is started, the new mapping will be processed.

And I noticed that when using CopyAsync in a Windows Container, I get error:

filesystem operations against a running Hyper-V container are not supported
@StefH commented on GitHub (Oct 6, 2024): Please test new version: 1.6.7-preview-02 (make sure to delete the all local versions to be sure you get the latest) When you do a CopyAsync after the container is started, the new mapping will be processed. And I noticed that when using CopyAsync in a Windows Container, I get error: ``` filesystem operations against a running Hyper-V container are not supported ```
Author
Owner

@StefH commented on GitHub (Oct 24, 2024):

@mantasburokas did you have time to test that version?

@StefH commented on GitHub (Oct 24, 2024): @mantasburokas did you have time to test that version?
Author
Owner

@StefH commented on GitHub (Oct 29, 2024):

@mantasburokas did you have time to test that version?

@StefH commented on GitHub (Oct 29, 2024): @mantasburokas did you have time to test that version?
Author
Owner

@StefH commented on GitHub (Nov 9, 2024):

Hello @mantasburokas, can you please test that version?

@StefH commented on GitHub (Nov 9, 2024): Hello @mantasburokas, can you please test that version?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#636