Skip to content

Commit 6699cba

Browse files
committed
Add build folder to .gitignore and address issue comments
Reorder tutorial so that Gradle instructions come first Signed-off-by: Igor Braga <higorb1@gmail.com>
1 parent c4ad232 commit 6699cba

File tree

2 files changed

+112
-109
lines changed

2 files changed

+112
-109
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ default.props
66
.ant-targets-build.xml
77
/results/
88
/logs/
9+
/build/
910
/config/custom-config.xml
1011
results
1112
*.retry

README.md

Lines changed: 111 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,109 @@ This README documents the build, customisation and testing of these runtime imag
3636

3737
## Build Runtimes
3838

39-
### You have 2 options to build the NodeJS runtime:
40-
- Building locally
41-
- Using OpenWhisk Actions.
42-
### This README walks you through how to do both
39+
You have 2 options to build the NodeJS runtime:
40+
- [Using Gradle](#using_gradle)
41+
- [Using Docker](#using_docker)
4342

44-
# Building NodeJS Runtime Locally
43+
This README walks you through how to do both
44+
45+
---
46+
47+
## Using Gradle <a name="using_gradle"></a>
48+
49+
### Pre-requisites
50+
- [Gradle](https://gradle.org/)
51+
- [Docker](https://www.docker.com/)
52+
- [OpenWhisk CLI wsk](https://github.com/apache/openwhisk-cli/releases)
53+
54+
If the deployment of Apache OpenWhisk includes these images in the runtime manifest, use the `--kind` parameter to select the Node.js runtime version.
55+
56+
### Node.js v10
57+
58+
```
59+
wsk action update myAction myAction.js --kind nodejs:10
60+
```
61+
62+
### Node.js v12
63+
64+
```
65+
wsk action update myAction myAction.js --kind nodejs:12
66+
```
67+
68+
### Node.js v14
69+
70+
```
71+
wsk action update myAction myAction.js --kind nodejs:14
72+
```
73+
74+
## Images
75+
76+
All the runtime images are published by the project to Docker Hub @ [https://hub.docker.com/u/openwhisk](https://hub.docker.com/u/openwhisk)
77+
78+
- [https://hub.docker.com/r/openwhisk/action-nodejs-v10](https://hub.docker.com/r/openwhisk/action-nodejs-v10)
79+
- [https://hub.docker.com/r/openwhisk/action-nodejs-v12](https://hub.docker.com/r/openwhisk/action-nodejs-v12)
80+
- [https://hub.docker.com/r/openwhisk/action-nodejs-v14](https://hub.docker.com/r/openwhisk/action-nodejs-v14)
81+
82+
These images can be used to execute Node.js actions on any deployment of Apache OpenWhisk, even those without those images defined the in runtime manifest, using the `--docker` action parameter.
83+
84+
```
85+
wsk action update myAction myAction.js --docker openwhisk/action-nodejs-v12
86+
```
87+
88+
If you build a custom version of the images, pushing those an external Docker Hub repository will allow you to use those on the Apache OpenWhisk deployment.
89+
90+
### Runtimes Manifest
91+
92+
Available runtimes in Apache OpenWhisk are defined using the runtimes manifest in this file: [runtimes.json](https://github.com/apache/openwhisk/blob/master/ansible/files/runtimes.json#L16-L72)
93+
94+
Modify the manifest and re-deploy the platform to pick up local images changes.
95+
96+
## Development
97+
98+
Dockerfiles for runtime images are defined in the `core` directory. Each runtime version folder has a custom `Dockerfile` and `package.json`. If you need to add extra dependencies to a runtime version - modify these files.
99+
100+
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.
101+
102+
### Build <a name="build_gradle"></a>
103+
104+
- Run the `distDocker` command to generate local Docker images for the different runtime versions. (Make sure docker daemon is running)
105+
106+
```
107+
./gradlew core:nodejs10Action:distDocker
108+
./gradlew core:nodejs12Action:distDocker
109+
./gradlew core:nodejs14Action:distDocker
110+
```
111+
112+
This will return the following runtime images with the following names: `action-nodejs-v10`, `action-nodejs-v12` and `action-nodejs-v14`.
113+
114+
### Testing
115+
116+
- Install project dependencies from the top-level Apache OpenWhisk [project](https://github.com/apache/openwhisk), which ensures correct versions of dependent libraries are available in the Maven cache.
117+
118+
```
119+
./gradlew install
120+
```
121+
122+
*This command **MUST BE** run from the directory containing the main Apache OpenWhisk [repository](https://github.com/apache/openwhisk), not this repository's directory.*
123+
124+
- Build the local Docker images for the runtime versions (see the instructions above).
125+
- Build the custom Docker images used in local testing.
126+
127+
```
128+
./gradlew tests:dat:docker:nodejs10docker:distDocker
129+
./gradlew tests:dat:docker:nodejs12docker:distDocker
130+
./gradlew tests:dat:docker:nodejs14docker:distDocker
131+
```
132+
133+
- Run the project tests.
134+
135+
```
136+
./gradlew :tests:test
137+
```
138+
139+
---
140+
141+
## Using Docker <a name="using_docker"></a>
45142

46143
### Pre-requisites
47144
- [Docker](https://www.docker.com/)
@@ -60,29 +157,27 @@ cd openwhisk-runtime-nodejs
60157
```
61158
FROM node:lts-stretch
62159
```
63-
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:
64-
```
65-
FROM node:14.16.0-stretch
66-
```
160+
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.
67161

68-
Or in the command line you can simply type:
69162
```
70-
cp core/nodejs14Action/Dockerfile core/nodejsActionBase/
163+
mkdir build
164+
cp -r core/nodejsActionBase/* build
165+
cp core/nodejs14Action/Dockerfile build
71166
```
72167

73-
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.
168+
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.
74169

75170
**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):
76171
```
77-
git reset --hard origin/master
172+
rm -rf build/*
78173
```
79174

80175
2. Build docker
81176
```
82-
docker build -t nodejs-action-v14:1.0-SNAPSHOT $(pwd)/core/nodejsActionBase
177+
docker build -t nodejs-action-v14:1.0-SNAPSHOT $(pwd)/build
83178
```
84179

85-
2.1. Check docker `IMAGE ID` (1st column) for repository `nodejs-action-v14` (assuming you built with the first option above)
180+
2.1. Check docker `IMAGE ID` (1st column) for repository `nodejs-action-v14`
86181
```
87182
docker images
88183
```
@@ -100,7 +195,7 @@ Or run the container in the background (Add `-d` (detached) to the command above
100195
```
101196
docker run -d -p 127.0.0.1:80:8080/tcp --name=bloom_whisker --rm -it nodejs-action-v14:1.0-SNAPSHOT
102197
```
103-
198+
**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/>
104199
Lists all running containers
105200
```
106201
docker ps
@@ -332,96 +427,3 @@ XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
332427
```
333428

334429
#### At this point you can edit js-fib-run.json an try other `fib_n` values. All you have to do is save `js-fib-run.json` and trigger the function again. Notice that here we're just modifying the parameters of our function; therefore, there's no need to re-run/re-initialize our container that contains our NodeJS runtime.
335-
336-
337-
# Building NodeJS Runtime using OpenWhisk Actions
338-
339-
### Pre-requisites
340-
- [Gradle](https://gradle.org/)
341-
- [Docker](https://www.docker.com/)
342-
- [OpenWhisk CLI wsk](https://github.com/apache/openwhisk-cli/releases)
343-
344-
If the deployment of Apache OpenWhisk includes these images in the runtime manifest, use the `--kind` parameter to select the Node.js runtime version.
345-
346-
### Node.js v10
347-
348-
```
349-
wsk action update myAction myAction.js --kind nodejs:10
350-
```
351-
352-
### Node.js v12
353-
354-
```
355-
wsk action update myAction myAction.js --kind nodejs:12
356-
```
357-
358-
### Node.js v14
359-
360-
```
361-
wsk action update myAction myAction.js --kind nodejs:14
362-
```
363-
364-
## Images
365-
366-
All the runtime images are published by the project to Docker Hub @ [https://hub.docker.com/u/openwhisk](https://hub.docker.com/u/openwhisk)
367-
368-
- [https://hub.docker.com/r/openwhisk/action-nodejs-v10](https://hub.docker.com/r/openwhisk/action-nodejs-v10)
369-
- [https://hub.docker.com/r/openwhisk/action-nodejs-v12](https://hub.docker.com/r/openwhisk/action-nodejs-v12)
370-
- [https://hub.docker.com/r/openwhisk/action-nodejs-v14](https://hub.docker.com/r/openwhisk/action-nodejs-v14)
371-
372-
These images can be used to execute Node.js actions on any deployment of Apache OpenWhisk, even those without those images defined the in runtime manifest, using the `--docker` action parameter.
373-
374-
```
375-
wsk action update myAction myAction.js --docker openwhisk/action-nodejs-v12
376-
```
377-
378-
If you build a custom version of the images, pushing those an external Docker Hub repository will allow you to use those on the Apache OpenWhisk deployment.
379-
380-
### Runtimes Manifest
381-
382-
Available runtimes in Apache OpenWhisk are defined using the runtimes manifest in this file: [runtimes.json](https://github.com/apache/openwhisk/blob/master/ansible/files/runtimes.json#L16-L72)
383-
384-
Modify the manifest and re-deploy the platform to pick up local images changes.
385-
386-
## Development
387-
388-
Dockerfiles for runtime images are defined in the `core` directory. Each runtime version folder has a custom `Dockerfile` and `package.json`. If you need to add extra dependencies to a runtime version - modify these files.
389-
390-
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.
391-
392-
### Build <a name="build_dradle"></a>
393-
394-
- Run the `distDocker` command to generate local Docker images for the different runtime versions. (Make sure docker daemon is running)
395-
396-
```
397-
./gradlew core:nodejs10Action:distDocker
398-
./gradlew core:nodejs12Action:distDocker
399-
./gradlew core:nodejs14Action:distDocker
400-
```
401-
402-
This will return the following runtime images with the following names: `action-nodejs-v10`, `action-nodejs-v12` and `action-nodejs-v14`.
403-
404-
### Testing
405-
406-
- Install project dependencies from the top-level Apache OpenWhisk [project](https://github.com/apache/openwhisk), which ensures correct versions of dependent libraries are available in the Maven cache.
407-
408-
```
409-
./gradlew install
410-
```
411-
412-
*This command **MUST BE** run from the directory containing the main Apache OpenWhisk [repository](https://github.com/apache/openwhisk), not this repository's directory.*
413-
414-
- Build the local Docker images for the runtime versions (see the instructions above).
415-
- Build the custom Docker images used in local testing.
416-
417-
```
418-
./gradlew tests:dat:docker:nodejs10docker:distDocker
419-
./gradlew tests:dat:docker:nodejs12docker:distDocker
420-
./gradlew tests:dat:docker:nodejs14docker:distDocker
421-
```
422-
423-
- Run the project tests.
424-
425-
```
426-
./gradlew :tests:test
427-
```

0 commit comments

Comments
 (0)