Hey, I'm new to Wiremock. I'm using the Docker ima...
# help
v
Hey, I'm new to Wiremock. I'm using the Docker image in K8s and can't figure out how to set up the stubs backup. I created a dedicated volume in the root, but missing the last step. Any advice will be much appreciated šŸ™‚
o
Hi! What do you mean under backup in these regards? Do you want to extract mappings from the server or what?
v
@Oleg Nenashev I want to save the mappings to the storage when the pod is terminating. And save all new mappings to /mappings as they are created
@Oleg Nenashev tried to set it up like this, doesn't work. /data is my persistent storage volume
Copy code
lifecycle:
          preStop:
            exec:
              command:
              - /bin/sh
              - -c
              - curl -X POST <http://wiremock:8080/__admin/mappings/save>
              - rm -rf /data/
              - cp -R /home/wiremock/ /data/
          postStart:
            exec:
              command:
              - /bin/sh
              - -c
              - cp -R /data/ /home/wiremock/
              - curl -X POST <http://wiremock:8080/__admin/mappings/reset>
o
What does block you from just keeping the source of truth on the volume and back it using K8s tools up instead of relying ion
/data
?
v
Not sure I understand. Which volume are you referring to?
I'm not building the image, pulling it from the repository
o
Copy code
apiVersion: v1
kind: Pod
metadata:
  name: wiremock
spec:
  containers:
  - name: wiremock
    image: wiremock/wiremock:2.35.0
    volumeMounts:
    - name: wiremock-storage
      mountPath: /home/wiremock
  volumes:
  - name: wiremock-storage
    emptyDir: {}
v
And Wiremock will use wiremock-storage as it's only storage?
o
For Mappings and Files and everything under
/home/wiremock
- yes.
v
Will give it a try, thanks! I still need to use the
Copy code
<http://wiremock:8080/__admin/mappings/save>
to save the stubs, right?
o
Yes, it does not sync to the disc without
save
v
Getting this when trying to save: <title>Error 500 java.lang.IllegalArgumentException: Invalid UUID string: save</title>
o
Personally I recommend switching to the configuration-as-code approach and building your Docker image on the top of the official one, but that's up to you
It is a wrong endpoint. Lemme check
v
Totally new to all of this, will try to follow this advice in the future :)
šŸ‘ 1
o
@Vlad Povolotzky Do you use POST for
__admin/mappings/save
? https://wiremock.org/docs/stubbing/#saving-stubs
With GET, it will try to get stub with UUID
save
v
It's POST, sure
o
If you get
IllegalArgumentException
with POST, it is a bug. Could you please file one?
v
šŸ™Œ 1
Where do I open bugs?
o
v
o
Thanks!
v
@Oleg Nenashev mounted the volume to home/mapping and now calling /save saves the stubs there as it should. How do I load the mappings from the /mappings folder? Currently after container restart a call to /mappings returns empty list.
o
Do you have a startup log? If the volume is mapped and WireMock has the same home directory and no conflicting parameters, it should load them
v
That's all there is
o
And with verbose options?
v
Do I need to edit the yamls for verbose option?
o
Yes, it is a CLI argument
v
This is the log on verbose start:
Copy code
2023-09-03 09:31:57.156 Verbose logging enabled                                                                                                                                                 ā”‚
ā”‚                                                                                                                                                                                                 ā”‚
ā”‚ ā–ˆā–ˆ     ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆ    ā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ   ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ   ā–ˆā–ˆ                                                                                                                                ā”‚
ā”‚ ā–ˆā–ˆ     ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ   ā–ˆā–ˆ ā–ˆā–ˆ      ā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ    ā–ˆā–ˆ ā–ˆā–ˆ      ā–ˆā–ˆ  ā–ˆā–ˆ                                                                                                                                 ā”‚
ā”‚ ā–ˆā–ˆ  ā–ˆ  ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆ   ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ    ā–ˆā–ˆ ā–ˆā–ˆ      ā–ˆā–ˆā–ˆā–ˆā–ˆ                                                                                                                                  ā”‚
ā”‚ ā–ˆā–ˆ ā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ   ā–ˆā–ˆ ā–ˆā–ˆ      ā–ˆā–ˆ  ā–ˆā–ˆ  ā–ˆā–ˆ ā–ˆā–ˆ    ā–ˆā–ˆ ā–ˆā–ˆ      ā–ˆā–ˆ  ā–ˆā–ˆ                                                                                                                                 ā”‚
ā”‚  ā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆ  ā–ˆā–ˆ ā–ˆā–ˆ   ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ      ā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ   ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ   ā–ˆā–ˆ                                                                                                                                ā”‚
ā”‚                                                                                                                                                                                                 ā”‚
ā”‚ ----------------------------------------------------------------                                                                                                                                ā”‚
ā”‚ |               Cloud: <https://wiremock.io/cloud>               |                                                                                                                                ā”‚
ā”‚ |                                                              |                                                                                                                                ā”‚
ā”‚ |               Slack: <https://slack.wiremock.org>              |                                                                                                                                ā”‚
ā”‚ ----------------------------------------------------------------                                                                                                                                ā”‚
ā”‚                                                                                                                                                                                                 ā”‚
ā”‚ port:                         8080                                                                                                                                                              ā”‚
ā”‚ enable-browser-proxying:      false                                                                                                                                                             ā”‚
ā”‚ disable-banner:               false                                                                                                                                                             ā”‚
ā”‚ no-request-journal:           false                                                                                                                                                             ā”‚
ā”‚ verbose:                      true                                                                                                                                                              ā”‚
ā”‚                                                                                                                                                                                                 ā”‚
ā”‚ 2023-09-03 09:32:26.244 Admin request received:                                                                                                                                                 ā”‚
ā”‚ 10.1.64.174 - GET /                                                                                                                                                                             ā”‚
ā”‚                                                                                                                                                                                                 ā”‚
ā”‚ Host: [10.1.76.89:8080]                                                                                                                                                                         ā”‚
ā”‚ User-Agent: [kube-probe/1.23+]                                                                                                                                                                  ā”‚
ā”‚ Accept: [*/*]                                                                                                                                                                                   ā”‚
ā”‚ Referer: [<http://10.1.76.89:8080/__admin>]                                                                                                                                                       ā”‚
ā”‚ Connection: [close]                                                                                                                                                                             ā”‚
ā”‚                                                                                                                                                                                                 ā”‚
ā”‚
Only see the healthcheck calls
The saved stubs aren't loading
The files are there, '/save' saves them as expected:
Copy code
root@wiremock-0:/home/wiremock/mappings# ll
total 32
drwxr-xr-x 2 root root 4096 Sep  3 13:54 ./
drwxr-xr-x 5 root root 4096 Aug 30 12:44 ../
-rw-r--r-- 1 root root  349 Aug 31 12:26 post-messagingjson-25f1b193-c1a8-4560-b4c9-4a0fa48db818
-rw-r--r-- 1 root root  349 Aug 31 10:58 post-messagingjson-551e7f3b-7fd7-46a5-a3ef-b560c7576b1c
-rw-r--r-- 1 root root  349 Sep  3 06:41 post-messagingjson-cd2d2762-3c96-469f-9d64-ad721921812c
-rw-r--r-- 1 root root  349 Sep  3 13:54 post-messagingjson-d02207ea-70c8-49f1-a4ee-76b504afafcc
-rw-r--r-- 1 root root  289 Aug 31 11:52 post-messagingjson-d518e1b7-910f-4777-a4c2-66ae710b1be7
-rw-r--r-- 1 root root  349 Sep  3 13:54 post-messagingtest-378e1e84-de1f-4f95-a6ba-e55c7d8a5e5c
@Oleg Nenashev Can you take a look, please? šŸ™
o
What concerns me is that there is no
*.json
extension in the ls output
v
@Oleg Nenashev You're right, they don't have an extension:
Copy code
root@wiremock-0:/home/wiremock/mappings# ls -1
post-messagingjson-25f1b193-c1a8-4560-b4c9-4a0fa48db818
post-messagingjson-551e7f3b-7fd7-46a5-a3ef-b560c7576b1c
post-messagingjson-cd2d2762-3c96-469f-9d64-ad721921812c
post-messagingjson-d02207ea-70c8-49f1-a4ee-76b504afafcc
post-messagingjson-d518e1b7-910f-4777-a4c2-66ae710b1be7
post-messagingtest-378e1e84-de1f-4f95-a6ba-e55c7d8a5e5c
root@wiremock-0:/home/wiremock/mappings#
o
So yes, they should be present if we want WireMock to load it by default
v
Got it, thanks, will check why it's saved this way
šŸ‘ 1
o
FTR https://github.com/wiremock/wiremock/issues/2361 @Vlad Povolotzky. It was created recently