Skip to content

Commit 5760c32

Browse files
rgee0alexellis
authored andcommitted
Re-ordered build.md so build-option is at the start
Signed-off-by: Richard Gee <[email protected]>
1 parent d275fa7 commit 5760c32

File tree

1 file changed

+46
-28
lines changed

1 file changed

+46
-28
lines changed

docs/cli/build.md

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,18 @@ For details and examples run
88
faas-cli build --help
99
```
1010

11-
## 1.0 Pass custom build arguments
11+
## 1.0 Apply build options
1212

13-
You can pass build-time arguments to Docker with
13+
The OpenFaaS CLI enables functions to be built with different options, e.g. `dev`, `debug`, etc.
1414

15-
```bash
16-
faas-cli build --build-arg ARGNAME1=argvalue1 --build-arg ARGNAME2=argvalue2
17-
```
18-
and use them in the template's Dockerfile with
19-
20-
```dockerfile
21-
ARG ARGNAME1
22-
ARG ARGNAME2
23-
```
24-
25-
For more information about passing build arguments to Docker, please visit the [Docker documentation](https://docs.docker.com/engine/reference/commandline/build/)
26-
27-
## 2.0 Apply build options
28-
29-
The OpenFaaS CLI allows you to run a build with different options, f.e. `dev`, `debug`, etc.
30-
31-
By default all templates are restricted to a minor build, which doesn't allow you to use third-party dependencies that require native (f.e C/C++) modules,
32-
like `libssh` in Ruby, `numpy` or `pandas` in Python, etc.
15+
By default all templates provide a minimal build as this optimizes function image sizes. Where appropriate, 3rd-party dependencies can be specified via `requirements.txt`. In scenarios where third-party dependencies also require native (e.g. C/C++) modules,
16+
like `libssh` in Ruby and `numpy` or `pandas` in Python, then `--build-option` can be used.
3317

3418
* How to use
3519

36-
The OpenFaaS CLI provides a solution by running a build in a dev mode, adding all required native modules.
20+
The OpenFaaS CLI provides a `--build-option` flag which enables named sets of native modules to be specified for inclusion in the function build.
3721

38-
You can do this with
22+
There are two ways to achieve this:
3923

4024
```bash
4125
faas-cli build --lang python3 --build-option dev [--build-option debug]
@@ -49,15 +33,17 @@ or in YAML:
4933
- dev
5034
```
5135
52-
If you are building multiple functions, we recommend using YAML configuration instead of CLI flag, as the flag is going to be applied to all functions listed in the YAML file.
36+
Where multiple functions are being built, the YAML configuration is recommended over use of the CLI flag, as the CLI flag applies the `--build-option` to all functions involved in the build activity.
5337

54-
> Currently only python and ruby templates are edited to support the feature.
38+
> Currently, of the official templates, Python and Ruby templates include named build options.
5539

56-
* Edit templates to support dev build
40+
* Edit templates to support additional build options
5741

58-
One may want to support dev build for a custom template or edit the list of additional packages.
42+
It is possible to amend build options in both official and custom templates.
5943

60-
In order to modify a template to support dev build option, you should edit the `template.yml` with the following:
44+
> Altering of official templates should be carefully considered in the context of repeatable builds
45+
46+
In order to modify a template to support further build options, edit the `template.yml` using the following pattern:
6147

6248
```yaml
6349
build_options:
@@ -74,7 +60,7 @@ build_options:
7460
#- etc.
7561
```
7662

77-
and edit `Dockerfile` with
63+
and if not already present edit `Dockerfile` with:
7864

7965
```dockerfile
8066
# Add the following line
@@ -84,3 +70,35 @@ ARG ADDITIONAL_PACKAGE
8470
RUN apk --no-cache add curl ${ADDITIONAL_PACKAGE} \
8571

8672
```
73+
## 2.0 Pass ADDITIONAL_PACKAGE through `--build-arg`
74+
75+
There may be scenarios where a single native module need to be added to a build. A single-package build option could be added as described above. Alternatively a package could be specified through a `--build-arg`.
76+
77+
```bash
78+
faas-cli build --lang python3 --build-arg ADDITIONAL_PACKAGE=jq
79+
```
80+
81+
In the event a `build-option` is set the effect will be cumulative:
82+
83+
```bash
84+
faas-cli build --lang python3 --build-option dev --build-arg ADDITIONAL_PACKAGE=jq
85+
```
86+
87+
The entries in the template's Dockerfile described in 1.0 above need to be present for this mode of operation.
88+
89+
## 3.0 Pass custom build arguments
90+
91+
You can pass `ARG` values to Docker via the CLI.
92+
93+
```bash
94+
faas-cli build --build-arg ARGNAME1=argvalue1 --build-arg ARGNAME2=argvalue2
95+
```
96+
97+
Remeber to add any `ARG` values to the template's Dockerfile:
98+
99+
```dockerfile
100+
ARG ARGNAME1
101+
ARG ARGNAME2
102+
```
103+
104+
For more information about passing build arguments to Docker, please visit the [Docker documentation](https://docs.docker.com/engine/reference/commandline/build/)

0 commit comments

Comments
 (0)