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
Copy file name to clipboardExpand all lines: docs/cli/build.md
+58-1
Original file line number
Diff line number
Diff line change
@@ -101,4 +101,61 @@ Remeber to add any `ARG` values to the template's Dockerfile:
101
101
ARG ARGNAME2
102
102
```
103
103
104
-
For more information about passing build arguments to Docker, please visit the [Docker documentation](https://docs.docker.com/engine/reference/commandline/build/)
104
+
For more information about passing build arguments to Docker, please visit the [Docker documentation](https://docs.docker.com/engine/reference/commandline/build/)
105
+
106
+
## 2.1 Build options examples
107
+
108
+
Let's see some practical examples with the `build-option` flag.
109
+
110
+
* Use [Pillow](https://pillow.readthedocs.io/en/5.2.x/) for image processing in your Python function
111
+
112
+
Create function with
113
+
114
+
```
115
+
$ faas-cli new faas_black_and_white --lang python3 --prefix <your-docker-namespace>
116
+
```
117
+
118
+
Add `pillow` to `requirements.txt` .
119
+
120
+
Copy some resource images to `faas_black_and_white/`.
121
+
122
+
Edit `handler.py`:
123
+
124
+
```python
125
+
import os
126
+
fromPILimport Image
127
+
128
+
defhandle(req):
129
+
img = Image.open("function/"+ req)
130
+
131
+
blackAndWhite = img.convert('1')
132
+
133
+
blackAndWhite.save("function/blackAndWhite.jpeg")
134
+
135
+
withopen("function/blackAndWhite.jpeg", 'rb') as pic:
136
+
res = pic.read()
137
+
138
+
os.write(1, res)
139
+
return res
140
+
```
141
+
142
+
What the code does is to open an image, available in resources and convert it to black and white.
143
+
144
+
Now build the function with build options:
145
+
```
146
+
faas build -f faas_black_and_white.yml --build-option dev --build-option pillow
0 commit comments