Skip to content

Commit 6d5720f

Browse files
Jiaxin FanJiaxin Fan
authored andcommitted
Revised README, also add EOL at end of file
1 parent a0d014a commit 6d5720f

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

tests/src/test/standalone/README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,63 @@ The following example shows how to generate a Docker image for the Node.js 18 ru
2626
```
2727
./gradlew core:nodejs18Action:distDocker
2828
```
29-
This will return the following runtime image with the name `action-nodejs-v18`
29+
This will return the following runtime image with the name `action-nodejs-v18`, which should be listed after using the `docker images`
3030

3131
## Running the Container
32-
For the purpose of the test. We are going to access the the runner container via `localhost`.
33-
The `Action` container exposes `port 8080` (see the Dockerfile for the associated Docker image), thus we publish the container's `port 8080` to the `localhost`:
32+
For the purpose of the test. We are going to start the container with a web service running inside it built with Node/Express. In order to access this servicec within the container from the outside, as we are about to do using `curl`, port mapping is done next. By doing so, we access the web service inside docker by first reaching an IP port on `localhost`, which subsequently forwards the request to the docker container's designated port.
33+
In our example, the `Action` container exposes `port 8080` (see the Dockerfile for the associated Docker image), thus we publish the container's `port 8080` to the `localhost` (here, `port 3008` on `localhost` is chosen arbitrarily, as long as the port is not already assigned):
3434
```
3535
docker run --publish 3008:8080 -i -t action-nodejs-v18:latest
3636
```
37+
A simpler way is to map `port 80` on `localhost` to the container's `port 8080`. The port number assigned to the HTTP protocol is `80` Since we will be sending actions against the runtime using HTTP, using this number will allow us to omit the port in the request later. In case `port 80` is already assigned, resort to the method above.
3738

3839
## Testing
3940
This example has prepared a `helloworld.json` file to post using `curl`.
41+
```json
42+
{
43+
"value": {
44+
"name" : "nodejs-helloworld",
45+
"main" : "main",
46+
"binary": false,
47+
"code" : "function main() {return {payload: 'Hello World!'};}"
48+
}
49+
}
50+
```
51+
The json file contains a simple JavaScript function, which is the actual payload.
4052

4153
### Initialze the Runtime
42-
Initialize the runtime with by invoking the ```/init``` endpoint.
54+
Before issuing the action against the runtime, we first initialize the function with by invoking the ```/init``` endpoint.
4355
```
4456
curl -H "Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/init
4557
4658
{"OK":true}
4759
```
60+
being the expected response.
61+
62+
As mentioned above, if `port 80` on `localhost` was used, the command could simply be ```
63+
curl -H "Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost/init
64+
```
4865
4966
#### Run the function
5067
51-
Execute the function using the ```/run``` endpoint.
68+
Invoke the function using the ```/run``` endpoint.
5269
5370
```
5471
curl -H ""Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/run
72+
```
5573
74+
The JavaScript function in this example is one without arguments. Using the same json file as during initialization won't be a problem. Strictly speaking, we should have provided another json file with the arguments. In our case, it should simply be
75+
```json
76+
{
77+
"value": {}
78+
}
79+
```
80+
The expected response should be
81+
```
5682
{"payload":"Hello World!"}
57-
```
83+
```
84+
Also the running container will print
85+
```
86+
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
87+
```
88+
in the terminal

0 commit comments

Comments
 (0)