Skip to content

Commit 7b070c2

Browse files
docs: added documentation for docker (#64)
* docs: added documentation for docker Signed-off-by: Pranshu Srivastava <[email protected]> * fix: removed bin Signed-off-by: Pranshu Srivastava <[email protected]> * fix: made changes according to the comments Signed-off-by: Pranshu Srivastava <[email protected]> * fix: added prerequisites Signed-off-by: Pranshu Srivastava <[email protected]> * fix: added explanation for buildDelay Signed-off-by: Pranshu Srivastava <[email protected]> --------- Signed-off-by: Pranshu Srivastava <[email protected]>
1 parent 8297095 commit 7b070c2

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

spring-petclinic/README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ This is a petclinic app where you can record testcases and mocks by interacting
44
This project has two parts - the frontend and backend, since Keploy is a backend testing platform, we need to start the backend part of the project
55
using Keploy and run the frontend as it is.
66

7+
Prerequisites:
8+
1. Node 20.11.0 LTS
9+
2. Docker Desktop 4.25.2 and above
10+
3. MVN version 3.6.3
11+
712
## Setup the frontend
813

914
```
@@ -25,7 +30,7 @@ npm run start
2530
## Spin up the database
2631

2732
```
28-
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 --net keploy-network postgres:15.2
33+
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 --net keploy-network --name mypostgres postgres:15.2
2934
```
3035

3136
## Setup Keploy
@@ -41,20 +46,65 @@ cd samples-java/spring-petclinic/spring-petclinic-rest
4146
mvn clean install -Dmaven.test.skip=true
4247
```
4348

44-
## Run the backend with Keploy
49+
You also need to update the postgresql properties, go to
50+
51+
```
52+
spring-petclinic/spring-petclinic-rest/src/main/resources/application-postgresql.properties
53+
```
54+
55+
and change
56+
57+
```
58+
spring.datasource.url=jdbc:postgresql://mypostgres:5432/petclinic
59+
```
60+
61+
to
62+
63+
```
64+
spring.datasource.url=jdbc:postgresql://localhost:5432/petclinic
65+
```
66+
67+
## Run the backend with Keploy(binary)
4568

4669
```
4770
keploy record -c "java -jar target/<name-of-your-jar>"
4871
```
4972

5073
Now when you interact with the UI, the tests should start getting created in a folder called 'keploy' in the directory where you started the backend. When you are done recording the testcases and mocks, you can run them using keploy.
5174

52-
## Running the testcases using Keploy
75+
## Starting the backend with Keploy(docker)
76+
Starting the backend with keploy requires just a small change in the script used to run Keploy. The command will look something like this:
77+
78+
### For docker on Mac
79+
80+
```
81+
alias keploy='sudo docker run --pull always --name keploy-v2 -e BINARY_TO_DOCKER=true -p 16789:16789 --privileged --pid=host -it -v " + os.Getenv("PWD") + ":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v debugfs:/sys/kernel/debug:rw -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v " + os.Getenv("HOME") + "/.keploy-config:/root/.keploy-config -v " + os.Getenv("HOME") + "/.keploy:/root/.keploy --rm ghcr.io/keploy/keploy'
82+
```
83+
84+
### For docker on Linux
85+
86+
```
87+
alias keploy='sudo docker run --pull always --name keploy-v2 -e BINARY_TO_DOCKER=true -p 16789:16789 --privileged --pid=host -it -v " + os.Getenv("PWD") + ":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v " + os.Getenv("HOME") + "/.keploy-config:/root/.keploy-config -v " + os.Getenv("HOME") + "/.keploy:/root/.keploy --rm ghcr.io/keploy/keploy'
88+
89+
```
90+
91+
```
92+
keploy record -c "docker compose up" --containerName javaApp --buildDelay 50s
93+
```
94+
95+
## Running the testcases using Keploy(binary)
5396

5497
```
5598
keploy test -c "java -jar target/<name-of-your-jar>" --delay 10
5699
```
100+
101+
## Running the testcases using Keploy(docker)
102+
103+
```
104+
keploy test -c "docker compose up" --containerName javaApp --buildDelay 50s --delay 10
105+
```
57106
Here `delay` is the time it takes for your application to get started, after which Keploy will start running the testcases. If your application takes longer than 10s to get started, you can change the `delay` accordingly.
107+
`buildDelay` is the time that it takes for the image to get built. This is useful when you are building the docker image from your docker compose file itself.
58108

59109
Hope this helps you out, if you still have any questions, reach out to us on our [Slack](https://join.slack.com/t/keploy/shared_invite/zt-12rfbvc01-o54cOG0X1G6eVJTuI_orSA)
60110

0 commit comments

Comments
 (0)