Skip to content

Commit

Permalink
Add build options examples
Browse files Browse the repository at this point in the history
This adds an example of how to practically use `build-option`
with pillow for Python

Signed-off-by: Ivana Yovcheva (VMware) <[email protected]>
  • Loading branch information
ivanayov committed Jul 17, 2018
1 parent 59c6f47 commit 6f6a0dc
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion docs/cli/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ARG ADDITIONAL_PACKAGE
RUN apk --no-cache add curl ${ADDITIONAL_PACKAGE} \

```
<<<<<<< HEAD
## 2.0 Pass ADDITIONAL_PACKAGE through `--build-arg`

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`.
Expand Down Expand Up @@ -101,4 +102,63 @@ Remeber to add any `ARG` values to the template's Dockerfile:
ARG ARGNAME2
```

For more information about passing build arguments to Docker, please visit the [Docker documentation](https://docs.docker.com/engine/reference/commandline/build/)
For more information about passing build arguments to Docker, please visit the [Docker documentation](https://docs.docker.com/engine/reference/commandline/build/)
=======

## 2.1 Build options examples

Let's see some practical examples with the `build-option` flag.
* Use [Pillow](https://pillow.readthedocs.io/en/5.2.x/) for image processing in your Python function
Create function with
```
$ faas-cli new faas_black_and_white --lang python3 --prefix <your-docker-namespace>
```
Add `pillow` to `requirements.txt` .
Copy some resource images to `faas_black_and_white/`.
Edit `handler.py`:
```python
import os
from PIL import Image
def handle(req):
img = Image.open("function/" + req)
blackAndWhite = img.convert('1')
blackAndWhite.save("function/blackAndWhite.jpeg")
with open("function/blackAndWhite.jpeg", 'rb') as pic:
res = pic.read()
os.write(1, res)
return res
```
What the code does is to open an image, available in resources and convert it to black and white.
Now build the function with build options:
```
faas build -f faas_black_and_white.yml --build-option dev --build-option pillow
```
Push and deploy:
```
faas push -f faas_black_and_white.yml && faas deploy -f faas_black_and_white.yml
```
Test the function with:
```bash
echo "image-name.jpg" | faas invoke pillow-func > blackAndWhite.jpg
```
Or in your web browser by opening http://127.0.0.1:8080/function/pillow-func
>>>>>>> Add build options examples

0 comments on commit 6f6a0dc

Please sign in to comment.