You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In addition to YAML file support, you can use the CLI to build and deploy individual functions as follows:
4
+
5
+
#### Worked example with Node.js
6
+
7
+
So if you want to write in another language, just prepare a Dockerfile and build an image manually, like in the [FaaS samples](https://github.com/alexellis/faas/tree/master/sample-functions).
8
+
9
+
**Build a FaaS function in NodeJS from a template:**
10
+
11
+
This will generate a Docker image for a Node.js function using the code in `/samples/info`.
12
+
13
+
* The `faas-cli` can accept a `-lang` option of `python` or `node` and is `node` by default.
14
+
15
+
```
16
+
$ ./faas-cli -action=build \
17
+
-image=alexellis2/node_info \
18
+
-name=node_info \
19
+
-handler=./sample/node_info
20
+
21
+
Building: alexellis2/node_info with Docker. Please wait..
22
+
...
23
+
Image: alexellis2/node_info built.
24
+
```
25
+
26
+
You can customise the code by editing the handler.js file and changing the `-handler` parameter. You can also edit the packages.json file, which will be used during the build to make sure all your dependencies are available at runtime.
27
+
28
+
For example:
29
+
30
+
```
31
+
"use strict"
32
+
33
+
module.exports = (context, callback) => {
34
+
console.log("echo - " + context);
35
+
36
+
callback(undefined, {status: "done"});
37
+
}
38
+
```
39
+
40
+
The CLI will then build a Docker image containing the FaaS watchdog and a bootstrap file to invoke your NodeJS function.
41
+
42
+
**Deploy the Docker image as a FaaS function:**
43
+
44
+
Now we can deploy the image as a named function called `node_info`.
45
+
46
+
```
47
+
$ ./faas-cli -action=deploy \
48
+
-image=alexellis2/node_info \
49
+
-name=node_info
50
+
51
+
200 OK
52
+
53
+
URL: http://localhost:8080/function/node_info
54
+
```
55
+
56
+
> This tool can be used to deploy any Docker image as a FaaS function, as long as it includes the watchdog binary as the `CMD` or `ENTRYPOINT` of the image.
57
+
58
+
*Deploy remotely*
59
+
60
+
You can deploy to a remote FaaS instance as along as you push the image to the Docker Hub, or another accessible Docker registry. Specify your remote gateway with the following flag: `-gateway=http://remote-site.com:8080`
$ uname -a | curl http://localhost:8080/function/node_info --data-binary @-
79
87
```
80
88
81
-
*Read on for manual CLI instructions.*
89
+
> For further instructions on the manual CLI flags (without using a YAML file) read [manual_cli.md](https://github.com/alexellis/faas-cli/blob/master/MANUAL_CLI.md)
82
90
83
91
### Installation / pre-requirements
84
92
@@ -118,64 +126,3 @@ $ go build
118
126
This project is part of the FaaS project licensed under the MIT License.
119
127
120
128
For more details see the [Contributing guide](https://github.com/alexellis/faas-cli/blob/master/CONTRIBUTING.md).
121
-
122
-
### Manual CLI options
123
-
124
-
*Update: read-on for YAML support.*
125
-
126
-
#### Worked example with Node.js
127
-
128
-
So if you want to write in another language, just prepare a Dockerfile and build an image manually, like in the [FaaS samples](https://github.com/alexellis/faas/tree/master/sample-functions).
129
-
130
-
**Build a FaaS function in NodeJS from a template:**
131
-
132
-
This will generate a Docker image for a Node.js function using the code in `/samples/info`.
133
-
134
-
* The `faas-cli` can accept a `-lang` option of `python` or `node` and is `node` by default.
135
-
136
-
```
137
-
$ ./faas-cli -action=build \
138
-
-image=alexellis2/node_info \
139
-
-name=node_info \
140
-
-handler=./sample/node_info
141
-
142
-
Building: alexellis2/node_info with Docker. Please wait..
143
-
...
144
-
Image: alexellis2/node_info built.
145
-
```
146
-
147
-
You can customise the code by editing the handler.js file and changing the `-handler` parameter. You can also edit the packages.json file, which will be used during the build to make sure all your dependencies are available at runtime.
148
-
149
-
For example:
150
-
151
-
```
152
-
"use strict"
153
-
154
-
module.exports = (context, callback) => {
155
-
console.log("echo - " + context);
156
-
157
-
callback(undefined, {status: "done"});
158
-
}
159
-
```
160
-
161
-
The CLI will then build a Docker image containing the FaaS watchdog and a bootstrap file to invoke your NodeJS function.
162
-
163
-
**Deploy the Docker image as a FaaS function:**
164
-
165
-
Now we can deploy the image as a named function called `node_info`.
166
-
167
-
```
168
-
$ ./faas-cli -action=deploy \
169
-
-image=alexellis2/node_info \
170
-
-name=node_info
171
-
172
-
200 OK
173
-
174
-
URL: http://localhost:8080/function/node_info
175
-
```
176
-
177
-
> This tool can be used to deploy any Docker image as a FaaS function, as long as it includes the watchdog binary as the `CMD` or `ENTRYPOINT` of the image.
178
-
179
-
*Deploy remotely*
180
-
181
-
You can deploy to a remote FaaS instance as along as you push the image to the Docker Hub, or another accessible Docker registry. Specify your remote gateway with the following flag: `-gateway=http://remote-site.com:8080`
0 commit comments