|
| 1 | +# Build functions |
| 2 | + |
| 3 | +The OpenFaaS CLI supports various options for building a function. |
| 4 | + |
| 5 | +For details and examples run |
| 6 | + |
| 7 | +```bash |
| 8 | +faas-cli build --help |
| 9 | +``` |
| 10 | + |
| 11 | +## 1.0 Pass custom build arguments |
| 12 | + |
| 13 | +You can pass build-time arguments to Docker with |
| 14 | + |
| 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. |
| 33 | + |
| 34 | +* How to use |
| 35 | + |
| 36 | +The OpenFaaS CLI provides a solution by running a build in a dev mode, adding all required native modules. |
| 37 | + |
| 38 | +You can do this with |
| 39 | + |
| 40 | +```bash |
| 41 | +faas-cli build --lang python3 --build-option dev [--build-option debug] |
| 42 | +``` |
| 43 | + |
| 44 | +or in YAML: |
| 45 | + |
| 46 | +```yaml |
| 47 | + build_options: |
| 48 | + - debug |
| 49 | + - dev |
| 50 | +``` |
| 51 | +
|
| 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. |
| 53 | +
|
| 54 | +> Currently only python and ruby templates are edited to support the feature. |
| 55 | +
|
| 56 | +* Edit templates to support dev build |
| 57 | +
|
| 58 | +One may want to support dev build for a custom template or edit the list of additional packages. |
| 59 | +
|
| 60 | +In order to modify a template to support dev build option, you should edit the `template.yml` with the following: |
| 61 | + |
| 62 | +```yaml |
| 63 | +build_options: |
| 64 | + - name: dev |
| 65 | + packages: # A list of required packages |
| 66 | + - make |
| 67 | + - automake |
| 68 | + - gcc |
| 69 | + #- etc. |
| 70 | + - name: debug |
| 71 | + packages: |
| 72 | + - mg |
| 73 | + - iw |
| 74 | + #- etc. |
| 75 | +``` |
| 76 | + |
| 77 | +and edit `Dockerfile` with |
| 78 | + |
| 79 | +```dockerfile |
| 80 | +# Add the following line |
| 81 | +ARG ADDITIONAL_PACKAGE |
| 82 | +
|
| 83 | +# Edit `RUN apk --no-cache add curl \` to the following |
| 84 | +RUN apk --no-cache add curl ${ADDITIONAL_PACKAGE} \ |
| 85 | + |
| 86 | +``` |
0 commit comments