Skip to content

Commit 752c8a9

Browse files
Jiaxin FanJiaxin Fan
authored andcommitted
Restore missing documentation about how to test runtimes standalone.
1 parent 2f6f268 commit 752c8a9

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
-->
19+
20+
# Tests for OpenWhisk NodeJS Runtime as Standalone Container
21+
## Building the Runtime Container
22+
After a runtime container is built, one should be able to run it as a standalone container.
23+
The following example shows how to generate a Docker image for the Node.js 18 runtime version and test the standalone runtime using the `curl` command. Testing other runtime versions can be done in the same manner.
24+
25+
- Run the `distDocker` command to generate the local Docker image for the desired runtime version.
26+
```
27+
./gradlew core:nodejs18Action:distDocker
28+
```
29+
This will return the following runtime image with the name `action-nodejs-v18`
30+
31+
## 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`:
34+
```
35+
docker run --publish 3008:8080 -i -t action-nodejs-v18:latest
36+
```
37+
38+
## Testing
39+
This example has prepared a `helloworld.json` file to post using `curl`.
40+
41+
### Initialze the Runtime
42+
Initialize the runtime with by invoking the ```/init``` endpoint.
43+
```
44+
curl -H "Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/init
45+
46+
{"OK":true}
47+
```
48+
49+
#### Run the function
50+
51+
Execute the function using the ```/run``` endpoint.
52+
53+
```
54+
curl -H ""Content-Type:application/json" -X POST --data '@openwhisk-runtime-nodejs/tests/src/test/standalone/helloworld/helloworld.json' http://localhost:3008/run
55+
56+
{"payload":"Hello World!"}
57+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"value": {
3+
"name" : "nodejs-helloworld",
4+
"main" : "main",
5+
"binary": false,
6+
"code" : "function main() {return {payload: 'Hello World!'};}"
7+
}
8+
}

0 commit comments

Comments
 (0)