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
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.
33
17
34
18
* How to use
35
19
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.
37
21
38
-
You can do this with
22
+
There are two ways to achieve this:
39
23
40
24
```bash
41
25
faas-cli build --lang python3 --build-option dev [--build-option debug]
@@ -49,15 +33,17 @@ or in YAML:
49
33
- dev
50
34
```
51
35
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.
53
37
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.
55
39
56
-
* Edit templates to support dev build
40
+
* Edit templates to support additional build options
57
41
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.
59
43
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:
61
47
62
48
```yaml
63
49
build_options:
@@ -74,7 +60,7 @@ build_options:
74
60
#- etc.
75
61
```
76
62
77
-
and edit `Dockerfile` with
63
+
and if not already present edit `Dockerfile` with:
78
64
79
65
```dockerfile
80
66
# Add the following line
@@ -84,3 +70,35 @@ ARG ADDITIONAL_PACKAGE
84
70
RUN apk --no-cache add curl ${ADDITIONAL_PACKAGE} \
85
71
86
72
```
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`.
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