In a CI/CD environment we first create a specific Wiremock Docker container via a Dockerfile:
FROM wiremock/wiremock:latest
COPY wiremock /home/wiremock
ENTRYPOINT ["/docker-entrypoint.sh", "--global-response-templating", "--verbose"]
Yes, I noticed that in the examples of this article the --disable-gzip is mentioned. I guess, just as an example. Correct.
We copy some Zip files into the container.
The response headers contain:
The retrieved file has size 3644. It is not a valid Zip file. Why? How to get the real file as a response?
Works again! The main reason was that the example Dockerfile was not correct for this use case!
Dockerfile:
FROM wiremock/wiremock
COPY stubs /home/wiremock
The zip file is put in stubs/__files as sample-zip.zip.
The stubs/mappings/mappingzip.json contains:
{
"request": {
"method": "GET",
"url": "/fileserver/samplezip"
},
"response": {
"status": 200,
"bodyFileName": "sample-zip.zip",
"headers": {
"Content-Type": "application/zip",
"Content-Disposition": "attachment;filename=\"file.zip\""
}
}
}
Another variant is in stubs/mappings/mappingzip2.json:
{
"request": {
"method": "GET",
"url": "/fileserver/samplezip2"
},
"response": {
"status": 200,
"bodyFileName": "sample-zip.zip",
"headers": {
"Content-Type": "application/octet-stream",
"Content-Disposition": "attachment;filename=\"file2.zip\""
}
}
}
The created docker image is put in the Docker hub.
The standard K8s deployment file is:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wiremockdemo
spec:
replicas: 1
selector:
matchLabels:
app: wiremockdemo
template:
metadata:
labels:
app: wiremockdemo
spec:
containers:
- name: wiremockdemo
image: yourdockerhubaccount/wiremockdemo:development
imagePullPolicy: Always
ports:
- containerPort: 8080
The Service file:
apiVersion: v1
kind: Service
metadata:
name: wiremockdemo
spec:
ports:
- name: http
port: 9200
protocol: TCP
targetPort: 8080
selector:
app: wiremockdemo
type: LoadBalancer
These commands launched the wiremock server as a Kubernetes service:
Browse results: