Update the handler to match style of golang-http-template#16
Update the handler to match style of golang-http-template#16alexellis merged 3 commits intoopenfaas:masterfrom kturcios:event-context-model
Conversation
- Created two new templates, python3-http & python3-http-armhf - Added waitress as the production server for new templates Signed-off-by: Kevin Turcios <kevin_turcios@outlook.com>
| $ curl -i $OPENFAAS_URL/function/<fn-name> | ||
| ``` | ||
|
|
||
| ## Event and Context Data |
There was a problem hiding this comment.
Is there an "official doc" where the contract with the watchdog is explained?
The goal is to know which field is mandatory, and which is not
There was a problem hiding this comment.
Hi @pcorbel how is this question related to the Python template?
| @@ -0,0 +1,48 @@ | |||
| FROM armhf/python:3.6-alpine | |||
There was a problem hiding this comment.
The stock image 'library/python:3.6-alpine' is compatible with ARM.
So we can use
FROM python:3.6-alpine
and if the image is build on ARM, the ARM version will be pulled.
Tested on Raspberry pi OK 👍
There was a problem hiding this comment.
Oh I had no idea about that! You've tested it on the Raspberry Pi already?
There was a problem hiding this comment.
Yes I've tested and it ran successfully
There was a problem hiding this comment.
I just tried this and it failed. How were you able to run the image on your Raspberry Pi? Did you have to make any other changes?
There was a problem hiding this comment.
Tried what / what failed? Give steps please so we can try too.
There was a problem hiding this comment.
This appears to work for me on armhf:
docker run -ti python:3.6-alpine /bin/sh
There was a problem hiding this comment.
I tried building the template with python:3.6-alpine and deploying it on the rpi, but the watchdog fails with the message Error reading stdout: EOF.
| @@ -0,0 +1,68 @@ | |||
| from flask import Flask, request, jsonify | |||
There was a problem hiding this comment.
No header?
I think it would be a good practice to put
#!/usr/bin/env python
# -*- coding: utf-8 -*-
everywhere
There was a problem hiding this comment.
I'm unfamiliar with this so I'll take a look into it
There was a problem hiding this comment.
We haven't done this elsewhere so please propose it generically @pcorbel in a separate issue.
template/python3-http/Dockerfile
Outdated
| @@ -0,0 +1,48 @@ | |||
| FROM python:3.7-alpine | |||
There was a problem hiding this comment.
Why base python3-http on 3.7 and python-http-armhf on 3.6?
I think it would be a good idea to sync the two of them
|
Hi, is this still WIP? |
Signed-off-by: Kevin Turcios <kevin_turcios@outlook.com>
|
It should be ready now |
README.md
Outdated
| ============================================= | ||
|
|
||
| Python OpenFaaS template with Flask | ||
| The Python Flask templates make use of the incubator project [of-watchdog](https://github.com/openfaas-incubator/of-watchdog) to handle higher throughput than the [classic watchdog](https://github.com/openfaas/faas/tree/master/watchdog) due to the process being kept warm. |
There was a problem hiding this comment.
I think this is technically correct but confusing / too-much-info for the people who may read it.
to handle higher throughput than the classic watchdog due to the process being kept warm.
README.md
Outdated
| faas template pull https://github.com/openfaas-incubator/python-flask-template | ||
| faas new --list | ||
| Languages available as templates: | ||
| Templates available under this repository: |
README.md
Outdated
| - python3-flask | ||
| ``` | ||
| - python3-flask-armhf | ||
| - python3-http* |
There was a problem hiding this comment.
python3-http* - why the suffix *?
README.md
Outdated
|
|
||
| Generate a function with one of the languages: | ||
| Notes: | ||
| - The templates listed with an asterik are the only ones that support additional control over the HTTP response and provide access to HTTP request details. |
There was a problem hiding this comment.
Not necessary to explain this, just show it in the examples.
| By default, flask will automatically attempt to set the correct Content-Type header for you based on the type of response. | ||
|
|
||
| # Wait a couple of seconds then: | ||
| For example, returning a dict object type will automatically attach the header `Content-Type: application/json` and returning a string type will automatically attach the `Content-Type: text/html, charset=utf-8` for you. |
There was a problem hiding this comment.
Should we mention flask given that this is not visible to the user? the template will?
README.md
Outdated
|
|
||
| echo -n content | faas invoke myfunction | ||
| ## Example usage | ||
| ### Custom Status Codes and Response Bodies |
There was a problem hiding this comment.
Why is Bodies capitalisedbutExample usage` isn't?
Sentence case should be fine for both
Signed-off-by: Kevin Turcios <kevin_turcios@outlook.com>
|
|
||
| ARG ADDITIONAL_PACKAGE | ||
| # Alternatively use ADD https:// (which will not be cached by Docker builder) | ||
| RUN apk --no-cache add curl ${ADDITIONAL_PACKAGE} \ |
There was a problem hiding this comment.
As a user, I'd like to be able to install build dependencies and have them removed after pip installs dependencies.
Is that possible?
There was a problem hiding this comment.
Some build dependencies generate .so libraries which are needed in the deployment / runtime container.
| self.headers = request.headers | ||
| self.method = request.method | ||
| self.query = request.args | ||
| self.path = request.path |
There was a problem hiding this comment.
Please also ad request.files and request.form - they are needed for multipart/form-data requests. The request.files attribute is an ImmutableMultiDict of FileStorage (which is a file-ish ducktype), and form is an ImmutableMultiDict of strings which represent the textual multiparts which have no filename in their content-disposition. Maybe make a plain dictionary of lists from the MultiDict, to abstract away the Flask api.
That would make my pull request obsolete.
There was a problem hiding this comment.
That won't be added at this time, but feel free to propose it as an issue.
|
@kturcios I'm going to merge this and would like the comments followed-up in a separate PR. Please also upgrade the watchdogs to the latest possible version. Thank you for working on this template 💯 |
Description
Motivation and Context
This will allow users to return custom responses for their functions.
Which issue(s) this PR fixes
Fixes #8
Fixes #15
Resolves #12
How Has This Been Tested?
Types of changes
Checklist:
git commit -sSigned-off-by: Kevin Turcios kevin_turcios@outlook.com