github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/charts/mockserver/README.md (about) 1 ## Installing MockServer 2 3 ### Prerequisites 4 5 - Kubernetes (i.e. [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) or [Docker for Desktop](https://www.docker.com/products/docker-desktop)) 6 - [Helm](https://docs.helm.sh/using_helm/#quickstart-guide) 7 8 ### Helm Install 9 10 To run MockServer in Kubernetes the easiest way is to use the existing [MockServer helm chart](http://www.mock-server.com/mockserver-5.11.1.tgz). 11 12 This is available by using `www.mock-server.com` as a chart repo, with the following command: 13 14 ```bash 15 helm upgrade --install --namespace mockserver mockserver http://www.mock-server.com/mockserver-5.11.1.tgz 16 ``` 17 18 **OR** 19 20 If you have helm chart source folder (i.e. you have the repository cloned): 21 22 ```bash 23 helm upgrade --install --namespace mockserver mockserver helm/mockserver 24 ``` 25 26 The two commands above will install MockServer into a **namespace** called `mockserver` with default configuration (as per the embedded [values.yaml](https://github.com/mock-server/mockserver/blob/master/helm/mockserver/values.yaml)). 27 MockServer will then be available on domain name `mockserver.mockserver.svc.cluster.local`, as long as the namespace you are calling from isn't prevented (by network policy) to call the `mockserver` namespace. 28 29 **THEN** 30 31 To view the logs: 32 33 ```bash 34 kubectl -n mockserver logs --tail=100 -l app=mockserver,release=mockserver 35 ``` 36 37 To wait until the deployment is complete run: 38 39 ```bash 40 kubectl -n mockserver rollout status deployments mockserver 41 ``` 42 43 To check the status of the deployment without waiting, run the following command and confirm the `mockserver` has the `Running` status: 44 45 ```bash 46 kubectl -n mockserver get po -l release=mockserver 47 ``` 48 49 ### Basic MockServer Configuration 50 51 Modify the arguments used to start the docker container by setting values explicitly using `--set`, as follows: 52 53 ```bash 54 helm upgrade --install --namespace mockserver --set app.serverPort=1080 --set app.logLevel=INFO mockserver http://www.mock-server.com/mockserver-5.11.1.tgz 55 ``` 56 57 The following values are supported: 58 59 - `app.serverPort` (default: 1080) 60 - `app.logLevel` (default: INFO) 61 - `app.proxyRemoteHost` (no default) 62 - `app.proxyRemotePort` (no default) 63 - `app.jvmOptions` (no default) 64 - `image.snapshot` (default: false) - set `true` to use latest snapshot version 65 66 For example configure a proxyRemoteHost and proxyRemotePort, as follows: 67 68 ```bash 69 helm upgrade --install --namespace mockserver --set app.serverPort=1080 --set app.proxyRemoteHost=www.mock-server.com --set app.proxyRemotePort=443 mockserver http://www.mock-server.com/mockserver-5.11.1.tgz 70 ``` 71 72 Double check the correct arguments have been passed to the pod, as follows: 73 74 ```bash 75 kubectl -n mockserver logs -l app=mockserver,release=mockserver 76 ``` 77 78 ### Detailed MockServer Configuration 79 80 If a configmap called `mockserver-config` exists in the same namespace this will be mapped into the MockServer container under the `mountPath` `/config`. 81 This configmap can be used to configure MockServer by containing a `mockserver.properties` file and other related configuration files such as a: 82 83 - [json expectation initialization](https://www.mock-server.com/mock_server/initializing_expectations.html), or 84 - custom [TLS CA, X.509 Certificate or Private Key](https://www.mock-server.com/mock_server/HTTPS_TLS.html#configuration) 85 The `mockserver.properties` file should load these additional files from the directory `/config` which is the `mountPath` for the configmap. 86 87 See [MockServer Configuration](https://www.mock-server.com/mock_server/configuration_properties.html) for details of all configuration options. 88 89 The mapping of the configuration configmap can be configured as follows: 90 91 - `app.mountedConfigMapName` (default: mockserver-config) - name of the configuration configmap (in the same namespace) to mount 92 - `app.propertiesFileName` (default: mockserver.properties) - path of the property file in the configmap 93 94 For example: 95 96 ```bash 97 helm upgrade --install --namespace mockserver --set app.mountedConfigMapName=other-mockserver-config --set app.propertiesFileNamem=other-mockserver.properties mockserver helm/mockserver 98 ``` 99 100 An example of a helm chart to configure MockServer is [helm/mockserver-config](https://github.com/mock-server/mockserver/tree/master/helm/mockserver-config) 101 102 ### Extending MockServer Classpath 103 104 To use [class callbacks](https://www.mock-server.com/mock_server/creating_expectations.html#button_response_class_callback) or an [expectation initializer class](https://www.mock-server.com/mock_server/initializing_expectations.html#expectation_initializer_class) the classpath for MockServer must include the specified classes. 105 To support adding classes to the classpath if a configmap called `mockserver-config` exists in the same namespace any jar files contained in this configmap will be added into MockServer classpath. 106 107 The mapping of the libs configmap can be configured as follows: 108 109 - `app.mountedLibsConfigMapName` (default: mockserver-config) - name of the libs configmap (in the same namespace) to mount 110 111 For example: 112 113 ```bash 114 helm upgrade --install --namespace mockserver --set app.mountedLibsConfigMapName=mockserver-libs mockserver helm/mockserver 115 ``` 116 117 ### MockServer URL 118 119 #### Local Kubernetes Cluster (i.e. [minikube](https://github.com/kubernetes/minikube), [microk8s](https://microk8s.io/)) 120 121 If the `service` type hasn't been modified the following will provide the MockServer URL from outside the cluster. 122 123 ```bash 124 export NODE_PORT=$(kubectl get -n mockserver -o jsonpath="{.spec.ports[0].nodePort}" services mockserver) 125 export NODE_IP=$(kubectl get nodes -n mockserver -o jsonpath="{.items[0].status.addresses[0].address}") 126 export MOCKSERVER_HOST=$NODE_IP:$NODE_PORT 127 echo http://$MOCKSERVER_HOST 128 ``` 129 130 To test the installation the following `curl` command should return the ports MockServer is bound to: 131 132 ```bash 133 curl -v -X PUT http://$MOCKSERVER_HOST/status 134 ``` 135 136 #### Docker for Desktop 137 138 [Docker for Desktop](https://www.docker.com/products/docker-desktop) automatically exposes **LoadBalancer** services. 139 On MacOS Docker for Desktop runs inside [Hyperkit](https://github.com/moby/hyperkit) so the node IP address is not reachable, therefore the only way to call services is via the exposed **LoadBalancer** service added by Docker for Desktop. 140 141 To ensure that Docker for Desktop exposes MockServer update the service type to **LoadBalancer** using **--set service.type=LoadBalancer** and set the exposed port using **--set service.port=1080**, as follows: 142 143 ```bash 144 helm upgrade --install --namespace mockserver --set service.type=LoadBalancer --set service.port=1080 mockserver http://www.mock-server.com/mockserver-5.11.1.tgz 145 ``` 146 147 MockServer will then be reachable on **http://localhost:1080** 148 149 For **LoadBalancer** services it is possible to query kubernetes to programmatically determine the MockServer base URL as follows: 150 151 ```bash 152 export SERVICE_IP=$(kubectl get svc --namespace mockserver mockserver -o jsonpath='{.status.loadBalancer.ingress[0].hostname}') 153 export MOCKSERVER_HOST=$SERVICE_IP:1081 154 echo http://$MOCKSERVER_HOST 155 ``` 156 157 #### Outside Remote Kubernetes Cluster (i.e. Azure AKS, AWS EKS, etc) 158 159 ```bash 160 kubectl -n mockserver port-forward svc/mockserver 1080:1080 & 161 export MOCKSERVER_HOST=127.0.0.1:1080 162 echo http://$MOCKSERVER_HOST 163 ``` 164 165 #### Inside Kubernetes Cluster 166 167 If a [DNS server](https://kubernetes.io/docs/concepts/services-networking/service/#dns) has been installed in the Kubernetes cluster the following DNS name should be available `mockserver.<namespace>.svc.cluster.local`, i.e. `mockserver.mockserver.svc.cluster.local` 168 169 ### Helm Delete 170 171 To completely remove the chart: 172 173 ```bash 174 helm delete mockserver --purge 175 ```