Skip to content

Commit 1611a0d

Browse files
johnmccabealexellis
authored andcommitted
Reorder Template sections
- Moves templates under a Templates header to the right-hand nav is cleared - Moves PHP7 into the numbered list of templates (we should probably dump the numbering) - Moves the ARM/RPi section out of the templates section Signed-off-by: John McCabe <[email protected]>
1 parent 4257d70 commit 1611a0d

File tree

1 file changed

+51
-49
lines changed

1 file changed

+51
-49
lines changed

docs/cli/templates.md

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Create new functions
22

3+
## Templates
4+
35
The OpenFaaS CLI has a template engine built-in which can create new functions in a given programming language. The way this works is by reading a list of templates from the `./template` location in your current working folder.
46

57
Before creating a new function make sure you pull in the official OpenFaaS language templates from GitHub via the [templates repository](https://github.com/openfaas/templates).
@@ -10,7 +12,7 @@ $ faas-cli template pull
1012

1113
This page shows how to generate functions in the most popular languages and explains how you can manage their dependencies too.
1214

13-
## 1.0 Go
15+
### 1.0 Go
1416

1517
To create a new function named `go-fn` in Go type in the following:
1618

@@ -28,7 +30,7 @@ go-fn.yml
2830

2931
You can now edit `handler.go` and use the `faas-cli` to `build` and `deploy` your function.
3032

31-
### 1.1 Go: dependencies
33+
#### 1.1 Go: dependencies
3234

3335
Dependencies should be managed with a Go vendoring tool such as dep.
3436

@@ -56,7 +58,7 @@ $ dep ensure -add github.com/cnf/structhash
5658

5759
You can now edit your function and add an import statement in `handler.go` to `github.com/cnf/structhash`.
5860

59-
## 2.0 Python 3
61+
### 2.0 Python 3
6062

6163
To create a Python function named `pycon` type in:
6264

@@ -74,13 +76,13 @@ pycon/requirements.txt
7476

7577
> Note: Python 2.7 is also available with the language template `python`.
7678
77-
### 2.1 Python: dependencies
79+
#### 2.1 Python: dependencies
7880

7981
You should edit `pycon/requirements.txt` and add any pip modules you want with each one on a new line, for instance `requests`.
8082

8183
The primary Python template uses Alpine Linux as a runtime environment due to its minimal size, but if you need a Debian environment so that you can compile `numpy` or other modules then read on to the next section.
8284

83-
### 2.2 Python: advanced dependencies
85+
#### 2.2 Python: advanced dependencies
8486

8587
If you need to use pip modules that require compilation then you should try the python3-debian template then add your pip modules to the `requirements.txt` file.
8688

@@ -101,7 +103,7 @@ Successfully installed numpy-1.14.2
101103
...
102104
```
103105

104-
## 3.0 Node.js
106+
### 3.0 Node.js
105107

106108
Generate a function named `js-fn`:
107109

@@ -118,7 +120,7 @@ You'll see:
118120
./js-fn/package.json
119121
```
120122

121-
### 3.1 Node.js dependencies
123+
#### 3.1 Node.js dependencies
122124

123125
Node.js dependencies are managed with `npm` and the `package.json` file which was generated for you.
124126

@@ -131,7 +133,7 @@ npm i --save cheerio
131133

132134
You can now add a `require('cheerio')` statement into your function and make use of this library.
133135

134-
## 4.0 CSharp / .NET Core 2.1
136+
### 4.0 CSharp / .NET Core 2.1
135137

136138
You can create functions in .NET Core 2.1 using C# / CSharp.
137139

@@ -143,7 +145,7 @@ faas-cli new --lang csharp csharp-function
143145

144146
Now you can open your current folder in a tool such as Visual Studio Code and add dependencies using the project (csproj) file.
145147

146-
## 5.0 Ruby
148+
### 5.0 Ruby
147149

148150

149151
Create a function called `ruby-function`:
@@ -163,7 +165,7 @@ The directory structure is:
163165

164166
Your code should be in the handler.rb file
165167

166-
### 5.1 Adding a Gem (Library)
168+
#### 5.1 Adding a Gem (Library)
167169

168170
Open the `Gemfile` in the ruby-function directory
169171

@@ -173,7 +175,7 @@ Add the following line
173175
gem 'httparty'
174176
```
175177

176-
### 5.1 Using our Gem
178+
#### 5.1 Using our Gem
177179

178180
Replace your `handler.rb` code with the following
179181

@@ -187,7 +189,7 @@ class Handler
187189
end
188190
```
189191

190-
### 5.3 Building / Deploy / Run
192+
#### 5.3 Building / Deploy / Run
191193

192194
Edit the `ruby-function.yml` and point your image to your dockerhub, for example
193195
`${your_user}/ruby-function`
@@ -207,7 +209,7 @@ When you HTTParty, you must party hard!
207209
...
208210
```
209211

210-
### 5.4 Invoke!
212+
#### 5.4 Invoke!
211213

212214
```
213215
$ echo 'OpenFaaS' | faas-cli invoke ruby-function
@@ -226,7 +228,7 @@ $ echo 'OpenFaaS' | faas-cli invoke ruby-function
226228
```
227229

228230

229-
## 6.0 Java
231+
### 6.0 Java
230232

231233
A Java 8 template is provided which uses Gradle 4.8.1 as a build-system.
232234

@@ -257,13 +259,42 @@ You can use `getHeader(k)` on the Request interface to query a header.
257259

258260
To set a header such as content-type you can use `setHeader(k, v)` on the Response interface.
259261

260-
## 7.0 Customise a template
262+
### 7.0 PHP 7
263+
264+
To create a PHP7 function named `my-function` type in:
265+
266+
$ faas-cli new my-function --lang php7
267+
268+
You'll see:
269+
270+
my-function.yml
271+
my-function/src/Handler.php
272+
my-function/composer.json
273+
my-function/php-extension.sh
274+
275+
Add any dependencies/extensions as described below and implement your functions business logic in `Handler.php`.
276+
277+
#### 7.1 Composer Dependencies
278+
279+
You should edit `composer.json` and add any required package dependencies, referring to the [Composer Documentation](https://getcomposer.org/doc/) for instructions on using `composer.json`.
280+
281+
#### 7.2 Private Composer Repositories
282+
283+
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on how to use [Composers]((https://getcomposer.org/doc/)) `COMPOSER_AUTH` environment variable to configure access to dependencies in private repositories.
284+
285+
#### 7.3 PHP Extensions
286+
287+
The PHP7 template is based upon the [Docker Library PHP image](https://hub.docker.com/_/php/) and provides the `php-extension.sh` script which exposes the ability to customise extensions installed in a function image.
288+
289+
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on customising installed extensions.
290+
291+
### 8.0 Customise a template
261292

262293
It is recommended that you use the official templates as they are provided and if there is a short-coming that you raise a GitHub issue so we can improve the templates for everyone.
263294

264295
All templates are driven by a Dockerfile and can be customised by editing the files found in the ./template folder.
265296

266-
### 7.1 Update the Dockerfile
297+
#### 8.1 Update the Dockerfile
267298

268299
There are several reasons why you may want to update your Dockerfile, just edit `./template/<language_name>/Dockerfile`.
269300

@@ -273,7 +304,7 @@ There are several reasons why you may want to update your Dockerfile, just edit
273304

274305
* Try a new version of a base-image - it may be that the project is showing support for Node.js LTS, but you want the cutting-edge version, you can do that too
275306

276-
### 7.2 Update a template's configuration
307+
#### 8.2 Update a template's configuration
277308

278309
The name of a template is read from a "template.yml" file kept within the template folder: `./template/<language_name>/template.yml`
279310

@@ -287,13 +318,13 @@ fprocess: dotnet ./root.dll
287318
* `language` is the display name used for `faas-cli new --list`.
288319
* `fprocess` provides the process to run for each invocation - i.e. your function
289320

290-
### 7.3 Use your own templates
321+
#### 8.3 Use your own templates
291322

292323
You can use your own Git repository for a custom or forked set of templates. This can be public or private.
293324

294325
See `faas-cli template pull` for more information.
295326

296-
## 8.0 ARM / Raspberry Pi
327+
## ARM / Raspberry Pi
297328

298329
Templates for ARM and Raspberry Pi are provided on a best-effort basis. If you can help with maintenance please let the project contributors know.
299330

@@ -305,33 +336,4 @@ Type in `faas-cli new --list` and look for any languages ending in `-armhf`. You
305336

306337
For these platforms do the same as above and look for the `-arm64` suffix.
307338

308-
> It is easy to make your own templates so if you need to use this platform please convert one of the "regular" templates for your platform.
309-
310-
## 9.0 PHP 7
311-
312-
To create a PHP7 function named `my-function` type in:
313-
314-
$ faas-cli new my-function --lang php7
315-
316-
You'll see:
317-
318-
my-function.yml
319-
my-function/src/Handler.php
320-
my-function/composer.json
321-
my-function/php-extension.sh
322-
323-
Add any dependencies/extensions as described below and implement your functions business logic in `Handler.php`.
324-
325-
### 9.1 Composer Dependencies
326-
327-
You should edit `composer.json` and add any required package dependencies, referring to the [Composer Documentation](https://getcomposer.org/doc/) for instructions on using `composer.json`.
328-
329-
**Private Composer Repositories**
330-
331-
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on how to use [Composers]((https://getcomposer.org/doc/)) `COMPOSER_AUTH` environment variable to configure access to dependencies in private repositories.
332-
333-
### 9.1 PHP Extensions
334-
335-
The PHP7 template is based upon the [Docker Library PHP image](https://hub.docker.com/_/php/) and provides the `php-extension.sh` script which exposes the ability to customise extensions installed in a function image.
336-
337-
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on customising installed extensions.
339+
> It is easy to make your own templates so if you need to use this platform please convert one of the "regular" templates for your platform.

0 commit comments

Comments
 (0)