10000 docs: format and add buildpack instructions (#91) · sesi/functions-framework-python@46d2149 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46d2149

Browse files
authored
docs: format and add buildpack instructions (GoogleCloudPlatform#91)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
1 parent 8fd2a6b commit 46d2149

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ curl http://my-url
2727

2828
All without needing to worry about writing an HTTP server or complicated request handling logic.
2929

30-
# Features
30+
## Features
3131

3232
* Spin up a local development server for quick testing
3333
* Invoke a function in response to a request
3434
* Automatically unmarshal events conforming to the [CloudEvents](https://cloudevents.io/) spec
3535
* Portable between serverless platforms
3636

37-
# Installation
37+
## Installation
3838

3939
Install the Functions Framework via `pip`:
4040

@@ -48,7 +48,9 @@ Or, for deployment, add the Functions Framework to your `requirements.txt` file:
4848
functions-framework==2.0.0
4949
```
5050

51-
# Quickstart: Hello, World on your local machine
51+
## Quickstarts
52+
53+
### Quickstart: Hello, World on your local machine
5254

5355
Create an `main.py` file with the following contents:
5456

@@ -66,7 +68,7 @@ functions-framework --target=hello
6668
Open http://localhost:8080/ in your browser and see *Hello world!*.
6769

6870

69-
# Quickstart: Set up a new project
71+
### Quickstart: Set up a new project
7072

7173
Create a `main.py` file with the following contents:
7274

@@ -100,27 +102,52 @@ curl localhost:8080
100102
# Output: Hello world!
101103
```
102104

103-
# Run your function on serverless platforms
105+
### Quickstart: Build a Deployable Container
106+
107+
1. Install [Docker](https://store.docker.com/search?type=edition&offering=community) and the [`pack` tool](https://buildpacks.io/docs/install-pack/).
108+
109+
1. Build a container from your function using the Functions [buildpacks](https://github.com/GoogleCloudPlatform/buildpacks):
110+
```sh
111+
pack build \
112+
--builder gcr.io/buildpacks/builder:v1 \
113+
--env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \
114+
--env GOOGLE_FUNCTION_TARGET=hello \
115+
my-first-function
116+
```
117+
118+
1. Start the built container:
119+
```sh
120+
docker run --rm -p 8080:8080 my-first-function
121+
# Output: Serving function...
122+
```
123+
124+
1. Send requests to this function using `curl` from another terminal window:
125+
```sh
126+
curl localhost:8080
127+
# Output: Hello World!
128+
```
129+
130+
## Run your function on serverless platforms
104131

105-
## Google Cloud Functions
132+
### Google Cloud Functions
106133

107134
This Functions Framework is based on the [Python Runtime on Google Cloud Functions](https://cloud.google.com/functions/docs/concepts/python-runtime).
108135

109136
On Cloud Functions, using the Functions Framework is not necessary: you don't need to add it to your `requirements.txt` file.
110137

111138
After you've written your function, you can simply deploy it from your local machine using the `gcloud` command-line tool. [Check out the Cloud Functions quickstart](https://cloud.google.com/functions/docs/quickstart).
112139

113-
## Cloud Run/Cloud Run on GKE
140+
### Cloud Run/Cloud Run on GKE
114141

115142
Once you've written your function and added the Functions Framework to your `requirements.txt` file, all that's left is to create a container image. [Check out the Cloud Run quickstart](https://cloud.google.com/run/docs/quickstarts/build-and-deploy) for Python to create a container image and deploy it to Cloud Run. You'll write a `Dockerfile` when you build your container. This `Dockerfile` allows you to specify exactly what goes into your container (including custom binaries, a specific operating system, and more). [Here is an example `Dockerfile` that calls Functions Framework.](https://github.com/GoogleCloudPlatform/functions-framework-python/blob/master/examples/cloud_run_http)
116143

117144
If you want even more control over the environment, you can [deploy your container image to Cloud Run on GKE](https://cloud.google.com/run/docs/quickstarts/prebuilt-deploy-gke). With Cloud Run on GKE, you can run your function on a GKE cluster, which gives you additional control over the environment (including use of GPU-based instances, longer timeouts and more).
118145

119-
## Container environments based on Knative
146+
### Container environments based on Knative
120147

121148
Cloud Run and Cloud Run on GKE both implement the [Knative Serving API](https://www.knative.dev/docs/). The Functions Framework is designed to be compatible with Knative environments. Just build and deploy your container to a Knative environment.
122149

123-
# Configure the Functions Framework
150+
## Configure the Functions Framework
124151

125152
You can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.
126153

@@ -134,7 +161,7 @@ You can configure the Functions Framework using command-line flags or environmen
134161
| `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` |
135162

136163

137-
# Enable Google Cloud Functions Events
164+
## Enable Google Cloud Functions Events
138165

139166
The Functions Framework can unmarshall incoming
140167
Google Cloud Functions [event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) payloads to `data` and `context` objects.
@@ -158,7 +185,7 @@ documentation on
158185

159186
See the [running example](examples/cloud_run_event).
160187

161-
# Enable CloudEvents
188+
## Enable CloudEvents
162189

163190
The Functions Framework can unmarshall incoming
164191
[CloudEvent](http://cloudevents.io) payloads to a `cloudevent` object.
@@ -176,11 +203,11 @@ To enable automatic unmarshalling, set the function signature type to `cloudeven
176203

177204
See the [running example](examples/cloud_run_cloudevents).
178205

179-
# Advanced Examples
206+
## Advanced Examples
180207

181208
More advanced guides can be found in the [`examples/`](https://github.com/GoogleCloudPlatform/functions-framework-python/blob/master/examples/) directory.
182209
You can also find examples on using the CloudEvent Python SDK [here](https://github.com/cloudevents/sdk-python).
183210

184-
# Contributing
211+
## Contributing
185212

186213
Contributions to this library are welcome and encouraged. See [CONTRIBUTING](CONTRIBUTING.md) for more information on how to get started.

0 commit comments

Comments
 (0)
0