You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2021/03/11 14:16:35 UTC

[GitHub] [openwhisk-runtime-nodejs] bragaigor opened a new pull request #190: Introduce tutorial to deploy NodeJS runtime locally

bragaigor opened a new pull request #190:
URL: https://github.com/apache/openwhisk-runtime-nodejs/pull/190


   The introduced tutorial uses Docker and a tranfer data
   tool (e.g. curl, wget or Postman). A summary of the tutorial
   steps are:
   
   1. Create docker container based on core/nodejs14Action
      Dockerfile
   2. Deploy/run the container locally
   3. Create function that resides in a json file
   4. Initialize the function against the deployed container
      using either curl, wget or Postman
   5. Call/trigger function using either curl, wget or Postman
   
   Signed-off-by: Igor Braga <hi...@gmail.com>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openwhisk-runtime-nodejs] bragaigor commented on pull request #190: Introduce tutorial to deploy NodeJS runtime locally

Posted by GitBox <gi...@apache.org>.
bragaigor commented on pull request #190:
URL: https://github.com/apache/openwhisk-runtime-nodejs/pull/190#issuecomment-796768149


   cc: @mrutkows 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openwhisk-runtime-nodejs] mrutkows commented on a change in pull request #190: Introduce tutorial to deploy NodeJS runtime locally

Posted by GitBox <gi...@apache.org>.
mrutkows commented on a change in pull request #190:
URL: https://github.com/apache/openwhisk-runtime-nodejs/pull/190#discussion_r593352998



##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:

Review comment:
       Does not need to be a heading; simple text is fine under "Build runtimes"

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both

Review comment:
       Does not need to be a heading, simple text is fine under the current heading

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.

Review comment:
       This should be 
   "Using Gradle"
   and it should be listed as the first option.

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally

Review comment:
       This is better described as "Using Docker"

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both
+
+# Building NodeJS Runtime Locally
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. All you have to do is substitute the line above from `core/nodejsActionBase/Dockerfile` with the equivalent line from `core/nodejs14Action/Dockerfile` that looks like:
+```
+FROM node:14.16.0-stretch
+```
+
+Or in the command line you can simply type:
+```
+cp core/nodejs14Action/Dockerfile core/nodejsActionBase/

Review comment:
       Really do not like overwriting the Dockerfile in nodejsActionBase; is there an alternative (and one that we can make sure is part of `/gitignore` to avoid developers accidentally committing to the repo.?

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both
+
+# Building NodeJS Runtime Locally
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. All you have to do is substitute the line above from `core/nodejsActionBase/Dockerfile` with the equivalent line from `core/nodejs14Action/Dockerfile` that looks like:
+```
+FROM node:14.16.0-stretch
+```
+
+Or in the command line you can simply type:
+```
+cp core/nodejs14Action/Dockerfile core/nodejsActionBase/
+```
+
+If you follow the instructions at end of this tutorial [here](#build_dradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we copy manually.

Review comment:
       Of course, you should alter/omit the "at the end of the tutorial" when this section gets moved.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openwhisk-runtime-nodejs] mrutkows commented on a change in pull request #190: Introduce tutorial to deploy NodeJS runtime locally

Posted by GitBox <gi...@apache.org>.
mrutkows commented on a change in pull request #190:
URL: https://github.com/apache/openwhisk-runtime-nodejs/pull/190#discussion_r613437993



##########
File path: README.md
##########
@@ -34,7 +34,22 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage

Review comment:
       Usage should remain the title.  It is how you invoke this runtime from the CLI and not a "gradle" usage.  Perhaps this section needs to have its title reverted and moved above either "gradle" or "docker" specific sections (and clarify that this is how you use this runtime and select the correct versions.

##########
File path: README.md
##########
@@ -34,7 +34,22 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes

Review comment:
       Actually, the notion of "build" (section) should be moved below sections "Usage", "Images", and "Development" as all are common/general info. not dependent on the gradle or docker (manual) builds.
   
   Then you would have perhaps a layout like:
   ## Usage
   - NodeJS 10,12,etc.
   
   ## Images
   ### Runtimes manifest
   
   ## Development
   
   ## Building Runtimes
   
   Choices are:
   - Gradle (link to unique header)
   - Docker (link to unique header)
   
   ### Using Gradle
   #### Prerequisites
   #### Building
   #### Testing
   ---
   ### Using Docker
   #### Prerequisites
   #### Building 
   #### Testing
   
   ##### Testing functions with arguments
   ##### Example: Calculate the nth Fibonacci number

##########
File path: README.md
##########
@@ -84,9 +99,9 @@ Dockerfiles for runtime images are defined in the `core` directory. Each runtime
 
 The `core/nodejsActionBase` folder contains the Node.js app server used to implement the [action interface](https://github.com/apache/openwhisk/blob/master/docs/actions-new.md#action-interface), used by the platform to inject action code into the runtime and fire invocation requests. This common code is used in all runtime versions.
 
-### Build

Review comment:
       See layout suggested above

##########
File path: README.md
##########
@@ -84,9 +99,9 @@ Dockerfiles for runtime images are defined in the `core` directory. Each runtime
 
 The `core/nodejsActionBase` folder contains the Node.js app server used to implement the [action interface](https://github.com/apache/openwhisk/blob/master/docs/actions-new.md#action-interface), used by the platform to inject action code into the runtime and fire invocation requests. This common code is used in all runtime versions.
 
-### Build
+### Build <a name="build_gradle"></a>

Review comment:
       Adopting the "Build" -> "Using Gradle" section eliminates need for HTML anchor

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)

Review comment:
       add some reason why you would choose this (manual) method over GRadle... e.g., 
   "The Gradle Wrapper build method uses Docker internally to automate many functions.  If you prefer building and testing with Docker directly, we have provided the following instructions"

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running

Review comment:
       Do not use numbered bullets where possible. Instead this can become a lower section title like "Clone the repository" under the "Build" subsection of "Using Docker"

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. We'll be creating a `build` folder that will contain all the necessary files for us to build our NodeJS container. All you have to do is copy paste the commands below. This will copy the NodeJS application as well as our target Dockerfile with the NodeJS version 14.
+
+```
+mkdir build
+cp -r core/nodejsActionBase/* build
+cp core/nodejs14Action/Dockerfile build
+```
+
+If you follow the instructions at beginning of this tutorial [here](#build_gradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we make create our own little build folder.
+
+**NOTE**: If you think that you messed up some file you can restore all files to its original state by typing the following. Then you can repeat the above command (careful with this command as it will remove all modifications you made to any file locally):
+```
+rm -rf build/*
+```
+
+2. Build docker
+```
+docker build -t nodejs-action-v14:1.0-SNAPSHOT $(pwd)/build
+```
+
+2.1. Check docker `IMAGE ID` (1st column) for repository `nodejs-action-v14`
+```
+docker images
+```
+
+2.2. Tag image (Optional step). Required if you’re pushing your docker image to a registry e.g. dockerHub

Review comment:
       Subsection "(Optional) Tagging the image"

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. We'll be creating a `build` folder that will contain all the necessary files for us to build our NodeJS container. All you have to do is copy paste the commands below. This will copy the NodeJS application as well as our target Dockerfile with the NodeJS version 14.
+
+```
+mkdir build
+cp -r core/nodejsActionBase/* build
+cp core/nodejs14Action/Dockerfile build
+```
+
+If you follow the instructions at beginning of this tutorial [here](#build_gradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we make create our own little build folder.
+
+**NOTE**: If you think that you messed up some file you can restore all files to its original state by typing the following. Then you can repeat the above command (careful with this command as it will remove all modifications you made to any file locally):
+```
+rm -rf build/*
+```
+
+2. Build docker
+```
+docker build -t nodejs-action-v14:1.0-SNAPSHOT $(pwd)/build
+```
+
+2.1. Check docker `IMAGE ID` (1st column) for repository `nodejs-action-v14`
+```
+docker images
+```
+
+2.2. Tag image (Optional step). Required if you’re pushing your docker image to a registry e.g. dockerHub
+```
+docker tag <docker_image_ID> <dockerHub_username>/nodejs-action-v14:1.0-SNAPSHOT
+```
+
+3. Run docker on localhost with either the following commands:
+```
+docker run -p 127.0.0.1:80:8080/tcp --name=bloom_whisker --rm -it nodejs-action-v14:1.0-SNAPSHOT
+```
+Or run the container in the background (Add `-d` (detached) to the command above)
+```
+docker run -d -p 127.0.0.1:80:8080/tcp --name=bloom_whisker --rm -it nodejs-action-v14:1.0-SNAPSHOT
+```
+**NOTE**: The instructions above that [uses gradle](#using_gradle) will also create a docker image. You can also use that image to start your NodeJS container locally and issue the below commands against localhost and things should still work <br/><br/>
+Lists all running containers
+```
+docker ps
+```
+or
+```
+docker ps -a
+```
+You should see a container named `bloom_whisker` being run
+
+4. Create your function (note that each container can only hold one function). In this first example we'll be creating a very simple function. Create a json file called `js-data-init-run.json` which will contain the function that looks something like the following:
+
+NOTE: value of code is the actual payload and must match the syntax of the target runtime language, in this case `javascript`
+```javascript
+{
+   "value": {
+      "name" : "js-helloworld",
+      "main" : "main",
+      "binary" : false,
+      "code" : "function main() {return {payload: 'Hello World!'};}"
+   }
+}
+```
+
+To issue the action against the running runtime, we must first make a request against the `init` API
+We need to issue `POST` requests to init our function
+Using curl (the option `-d` signifies we're issuing a POST request)
+```
+curl -d "@js-data-init-run.json" -H "Content-Type: application/json" http://localhost/init
+```
+Using wget (the option `--post-file` signifies we're issuing a POST request. The option `--output` redirects `wget` output to a file since its response is quite verbose and we're only interested in the Server response; additionally, `wget` will store the Server response in a file called `init.#` where `#` is a number)
+```
+wget -O- --post-file=js-data-init-run.json --header="Content-Type: application/json" --output-file=logfile http://localhost/init
+```
+The above can also be achieved with [Postman](https://www.postman.com/) by setting the headers and body accordingly
+
+Client expected response:
+```
+{"ok":true}
+```
+
+Server will remain silent in this case
+
+Now we can invoke/run our function against the `run` API with:
+Using curl `POST` request
+
+curl -d "@js-data-init-run.json" -H "Content-Type: application/json" http://localhost/run
+Or using `GET` request
+```
+curl --data-binary "@js-data-init-run.json" -H "Content-Type: application/json" http://localhost/run
+```
+
+Or
+Using wget `POST` request. The `-O-` is to redirect `wget` response to `stdout`.
+```
+wget -O- --post-file=js-data-init-run.json --header="Content-Type: application/json" --output-file=logfile http://localhost/run
+```
+
+The above can also be achieved with [Postman](https://www.postman.com/) by setting the headers and body accordingly.
+
+You noticed that we’re passing the same file `js-data-init-run.json` from function initialization request to trigger the function. That’s not necessary and not recommended since to trigger a function all we need is to pass the parameters of the function. So in the above example, it's preferred if we create a file called `js-data-params.json` that looks like the following:
+```javascript
+{
+   "value": {}
+}
+```
+
+And trigger the function with the following (it also works with wget and postman equivalents):
+```
+curl --data-binary "@js-data-params.json" -H "Content-Type: application/json" http://localhost/run
+```
+
+#### You can perform the same steps as above using [Postman](https://www.postman.com/) application. Make sure you have the correct request type set and the respective body. Also set the correct headers key value pairs, which for us is "Content-Type: application/json"
+
+After you trigger the function with one of the above commands you should expect the following client response:
+```
+{"payload": "Hello World!"}
+```
+And Server expected response:
+
+```
+XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
+XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
+```
+
+
+## Creating functions with arguments

Review comment:
       subsection (see sugg. layout above)

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. We'll be creating a `build` folder that will contain all the necessary files for us to build our NodeJS container. All you have to do is copy paste the commands below. This will copy the NodeJS application as well as our target Dockerfile with the NodeJS version 14.
+
+```
+mkdir build
+cp -r core/nodejsActionBase/* build
+cp core/nodejs14Action/Dockerfile build
+```
+
+If you follow the instructions at beginning of this tutorial [here](#build_gradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we make create our own little build folder.
+
+**NOTE**: If you think that you messed up some file you can restore all files to its original state by typing the following. Then you can repeat the above command (careful with this command as it will remove all modifications you made to any file locally):
+```
+rm -rf build/*
+```
+
+2. Build docker
+```
+docker build -t nodejs-action-v14:1.0-SNAPSHOT $(pwd)/build
+```
+
+2.1. Check docker `IMAGE ID` (1st column) for repository `nodejs-action-v14`
+```
+docker images
+```
+
+2.2. Tag image (Optional step). Required if you’re pushing your docker image to a registry e.g. dockerHub
+```
+docker tag <docker_image_ID> <dockerHub_username>/nodejs-action-v14:1.0-SNAPSHOT
+```
+
+3. Run docker on localhost with either the following commands:
+```
+docker run -p 127.0.0.1:80:8080/tcp --name=bloom_whisker --rm -it nodejs-action-v14:1.0-SNAPSHOT
+```
+Or run the container in the background (Add `-d` (detached) to the command above)
+```
+docker run -d -p 127.0.0.1:80:8080/tcp --name=bloom_whisker --rm -it nodejs-action-v14:1.0-SNAPSHOT
+```
+**NOTE**: The instructions above that [uses gradle](#using_gradle) will also create a docker image. You can also use that image to start your NodeJS container locally and issue the below commands against localhost and things should still work <br/><br/>
+Lists all running containers
+```
+docker ps
+```
+or
+```
+docker ps -a
+```
+You should see a container named `bloom_whisker` being run
+
+4. Create your function (note that each container can only hold one function). In this first example we'll be creating a very simple function. Create a json file called `js-data-init-run.json` which will contain the function that looks something like the following:
+
+NOTE: value of code is the actual payload and must match the syntax of the target runtime language, in this case `javascript`
+```javascript
+{
+   "value": {
+      "name" : "js-helloworld",
+      "main" : "main",
+      "binary" : false,
+      "code" : "function main() {return {payload: 'Hello World!'};}"
+   }
+}
+```
+
+To issue the action against the running runtime, we must first make a request against the `init` API
+We need to issue `POST` requests to init our function
+Using curl (the option `-d` signifies we're issuing a POST request)
+```
+curl -d "@js-data-init-run.json" -H "Content-Type: application/json" http://localhost/init
+```
+Using wget (the option `--post-file` signifies we're issuing a POST request. The option `--output` redirects `wget` output to a file since its response is quite verbose and we're only interested in the Server response; additionally, `wget` will store the Server response in a file called `init.#` where `#` is a number)
+```
+wget -O- --post-file=js-data-init-run.json --header="Content-Type: application/json" --output-file=logfile http://localhost/init
+```
+The above can also be achieved with [Postman](https://www.postman.com/) by setting the headers and body accordingly
+
+Client expected response:
+```
+{"ok":true}
+```
+
+Server will remain silent in this case
+
+Now we can invoke/run our function against the `run` API with:
+Using curl `POST` request
+
+curl -d "@js-data-init-run.json" -H "Content-Type: application/json" http://localhost/run
+Or using `GET` request
+```
+curl --data-binary "@js-data-init-run.json" -H "Content-Type: application/json" http://localhost/run
+```
+
+Or
+Using wget `POST` request. The `-O-` is to redirect `wget` response to `stdout`.
+```
+wget -O- --post-file=js-data-init-run.json --header="Content-Type: application/json" --output-file=logfile http://localhost/run
+```
+
+The above can also be achieved with [Postman](https://www.postman.com/) by setting the headers and body accordingly.
+
+You noticed that we’re passing the same file `js-data-init-run.json` from function initialization request to trigger the function. That’s not necessary and not recommended since to trigger a function all we need is to pass the parameters of the function. So in the above example, it's preferred if we create a file called `js-data-params.json` that looks like the following:
+```javascript
+{
+   "value": {}
+}
+```
+
+And trigger the function with the following (it also works with wget and postman equivalents):
+```
+curl --data-binary "@js-data-params.json" -H "Content-Type: application/json" http://localhost/run
+```
+
+#### You can perform the same steps as above using [Postman](https://www.postman.com/) application. Make sure you have the correct request type set and the respective body. Also set the correct headers key value pairs, which for us is "Content-Type: application/json"
+
+After you trigger the function with one of the above commands you should expect the following client response:
+```
+{"payload": "Hello World!"}
+```
+And Server expected response:
+
+```
+XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
+XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
+```
+
+
+## Creating functions with arguments
+If your container still running from the previous example you must stop it and re-run it before proceeding. Remember that each NodeJS runtime can only hold one function (which cannot be overrided due to security reasons)
+Create a json file called `js-data-init-params.json` which will contain the function to be initialized that looks like the following:
+```javascript
+{
+   "value": {
+      "name": "js-helloworld-with-params",
+      "main" : "main",
+      "binary" : false,
+      "code" : "function main(params) { return {payload: 'Hello ' + params.name + ' from ' + params.place + '!!!'} }"
+   }
+}
+```
+
+Also create a json file `js-data-run-params.json` which will contain the parameters to the function used to trigger it. Notice here we're creating 2 separate file from the beginning since this is good practice to make the distinction between what needs to be send via the `init` API and what needs to be sent via the `run` API:
+```javascript
+{
+   "value": {
+      "name": "UFO",
+      "place": "Mars"
+   }
+}
+```
+
+Now, all we have to do is initialize and trigger our function.
+First, to initialize our function make sure your NodeJS runtime container is running if not, spin the container by following step 3.
+Issue a `POST` request against the `init` API with the following command:
+Using curl:
+
+```
+curl -d "@js-data-init-params.json" -H "Content-Type: application/json" http://localhost/init
+```
+Using wget:
+```
+wget --post-file=js-data-init-params.json --header="Content-Type: application/json" --output-file=logfile http://localhost/init
+```
+
+Second, to run/trigger the function issue requests against the run API with the following command:
+Using curl with `POST`:
+```
+curl -d "@js-data-run-params.json" -H "Content-Type: application/json" http://localhost/run
+```
+Or
+Using wget with `POST`:
+```
+wget -O- --post-file=js-data-run-params.json --header="Content-Type: application/json" --output-file=logfile http://localhost/run
+```
+
+After you trigger the function with one of the above commands you should expect the following client response:
+```
+{"payload": "Hello UFO from Mars!!!"}
+```
+
+And Server expected response:
+```
+XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
+XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
+```
+
+## Now let's create a more interesting function

Review comment:
       subsection (see sugg. layout above)

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>

Review comment:
       Adopting the "Build" -> "Using Docker" section eliminates need for HTML anchor

##########
File path: README.md
##########
@@ -34,7 +34,22 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+You have 2 options to build the NodeJS runtime:
+- [Using Gradle](#using_gradle)
+- [Using Docker](#using_docker)
+
+This README walks you through how to do both
+
+---
+
+## Using Gradle <a name="using_gradle"></a>

Review comment:
       Adopting the "Build" -> "Using Gradle" section eliminates need for HTML anchor

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. We'll be creating a `build` folder that will contain all the necessary files for us to build our NodeJS container. All you have to do is copy paste the commands below. This will copy the NodeJS application as well as our target Dockerfile with the NodeJS version 14.
+
+```
+mkdir build
+cp -r core/nodejsActionBase/* build
+cp core/nodejs14Action/Dockerfile build
+```
+
+If you follow the instructions at beginning of this tutorial [here](#build_gradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we make create our own little build folder.
+
+**NOTE**: If you think that you messed up some file you can restore all files to its original state by typing the following. Then you can repeat the above command (careful with this command as it will remove all modifications you made to any file locally):
+```
+rm -rf build/*
+```
+
+2. Build docker
+```
+docker build -t nodejs-action-v14:1.0-SNAPSHOT $(pwd)/build
+```
+
+2.1. Check docker `IMAGE ID` (1st column) for repository `nodejs-action-v14`
+```
+docker images
+```
+
+2.2. Tag image (Optional step). Required if you’re pushing your docker image to a registry e.g. dockerHub
+```
+docker tag <docker_image_ID> <dockerHub_username>/nodejs-action-v14:1.0-SNAPSHOT
+```
+
+3. Run docker on localhost with either the following commands:

Review comment:
       Move under "Testing" subsection

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:

Review comment:
       Subsection instead of bullet "Copy NodeJS version to build"

##########
File path: README.md
##########
@@ -120,3 +135,295 @@ This will return the following runtime images with the following names: `action-
 ```
 ./gradlew :tests:test
 ```
+
+---
+
+## Using Docker <a name="using_docker"></a>
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. We'll be creating a `build` folder that will contain all the necessary files for us to build our NodeJS container. All you have to do is copy paste the commands below. This will copy the NodeJS application as well as our target Dockerfile with the NodeJS version 14.
+
+```
+mkdir build
+cp -r core/nodejsActionBase/* build
+cp core/nodejs14Action/Dockerfile build
+```
+
+If you follow the instructions at beginning of this tutorial [here](#build_gradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we make create our own little build folder.

Review comment:
       Do not refer to this page as a "tutorial"; instead add a subsection "Resetting the build"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openwhisk-runtime-nodejs] mrutkows commented on a change in pull request #190: Introduce tutorial to deploy NodeJS runtime locally

Posted by GitBox <gi...@apache.org>.
mrutkows commented on a change in pull request #190:
URL: https://github.com/apache/openwhisk-runtime-nodejs/pull/190#discussion_r593371641



##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both
+
+# Building NodeJS Runtime Locally
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. All you have to do is substitute the line above from `core/nodejsActionBase/Dockerfile` with the equivalent line from `core/nodejs14Action/Dockerfile` that looks like:
+```
+FROM node:14.16.0-stretch
+```
+
+Or in the command line you can simply type:
+```
+cp core/nodejs14Action/Dockerfile core/nodejsActionBase/
+```
+
+If you follow the instructions at end of this tutorial [here](#build_dradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we copy manually.
+
+**NOTE**: If you think that you messed up some file you can restore all files to its original state by typing the following. Then you can repeat the above command (careful with this command as it will remove all modifications you made to any file locally):
+```
+git reset --hard origin/master
+```
+
+2. Build docker

Review comment:
       Subsection "Build the docker image"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openwhisk-runtime-nodejs] mrutkows commented on a change in pull request #190: Introduce tutorial to deploy NodeJS runtime locally

Posted by GitBox <gi...@apache.org>.
mrutkows commented on a change in pull request #190:
URL: https://github.com/apache/openwhisk-runtime-nodejs/pull/190#discussion_r593362615



##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.

Review comment:
       The options should be intra-document hyperlinks (to section titles for those sections)

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both
+
+# Building NodeJS Runtime Locally
+
+### Pre-requisites
+- [Docker](https://www.docker.com/)
+- [curl](https://curl.se/), [wget](https://www.gnu.org/software/wget/), or [Postman](https://www.postman.com/)
+
+
+0. Choose/create a folder of your liking and make sure docker daemon is running
+
+1. Clone this repo:
+```
+git clone https://github.com/apache/openwhisk-runtime-nodejs
+cd openwhisk-runtime-nodejs
+```
+
+1.1 Choose a NodeJS version. All build files reside inside `core/nodejsActionBase`. If you take a look into `core/nodejsActionBase/Dockerfile` you’ll see a line that looks like:
+```
+FROM node:lts-stretch
+```
+This will use the latest NodeJS version. But we want to be more specific. Now if you look into each of the Dockerfile’s of `core/nodejs14Action`, `core/nodejs12Action`, `core/nodejs10Action`, you’ll notice different nodeJS versions. Let’s go ahead with the 14 version. All you have to do is substitute the line above from `core/nodejsActionBase/Dockerfile` with the equivalent line from `core/nodejs14Action/Dockerfile` that looks like:
+```
+FROM node:14.16.0-stretch
+```
+
+Or in the command line you can simply type:
+```
+cp core/nodejs14Action/Dockerfile core/nodejsActionBase/
+```
+
+If you follow the instructions at end of this tutorial [here](#build_dradle) that uses Gradle, you'll notice that Gradle takes care of this copying for us internally. Here since we just want to use docker and not worry about anything else we copy manually.
+
+**NOTE**: If you think that you messed up some file you can restore all files to its original state by typing the following. Then you can repeat the above command (careful with this command as it will remove all modifications you made to any file locally):
+```
+git reset --hard origin/master
+```
+
+2. Build docker

Review comment:
       Number should be "1." for all occurrences for linted markdown

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both
+
+# Building NodeJS Runtime Locally

Review comment:
       "Using Docker"

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally

Review comment:
       Using Gradle should be the featured option; the manual Docker build which is added in this PR should come after.  Most of the OpenWhisk project use Gradle Wrapper (gradlew) because the build complexity does not need to distract from the developer fixing a bug in the runtime code itself.

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both
+
+# Building NodeJS Runtime Locally

Review comment:
       Make H2

##########
File path: README.md
##########
@@ -34,7 +34,312 @@ This README documents the build, customisation and testing of these runtime imag
 
 **Do you want to learn more about using Node.js actions to build serverless applications?** Please see the main project documentation [here](https://github.com/apache/openwhisk/blob/master/docs/actions-nodejs.md) for that information.
 
-## Usage
+## Build Runtimes
+
+### You have 2 options to build the NodeJS runtime:
+- Building locally
+- Using OpenWhisk Actions.
+### This README walks you through how to do both
+
+# Building NodeJS Runtime Locally

Review comment:
       Add a separator after it is moved to clearly show where "using Gradle" ends and "using Docker" begings




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org