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
Open http://localhost:8080/ in your browser and see *Hello world!*.
67
69
68
70
69
-
# Quickstart: Set up a new project
71
+
###Quickstart: Set up a new project
70
72
71
73
Create a `main.py` file with the following contents:
72
74
@@ -100,27 +102,52 @@ curl localhost:8080
100
102
# Output: Hello world!
101
103
```
102
104
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
104
131
105
-
## Google Cloud Functions
132
+
###Google Cloud Functions
106
133
107
134
This Functions Framework is based on the [Python Runtime on Google Cloud Functions](https://cloud.google.com/functions/docs/concepts/python-runtime).
108
135
109
136
On Cloud Functions, using the Functions Framework is not necessary: you don't need to add it to your `requirements.txt` file.
110
137
111
138
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).
112
139
113
-
## Cloud Run/Cloud Run on GKE
140
+
###Cloud Run/Cloud Run on GKE
114
141
115
142
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)
116
143
117
144
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).
118
145
119
-
## Container environments based on Knative
146
+
###Container environments based on Knative
120
147
121
148
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.
122
149
123
-
# Configure the Functions Framework
150
+
##Configure the Functions Framework
124
151
125
152
You can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.
126
153
@@ -134,7 +161,7 @@ You can configure the Functions Framework using command-line flags or environmen
134
161
|`--debug`|`DEBUG`| A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False`|
135
162
136
163
137
-
# Enable Google Cloud Functions Events
164
+
##Enable Google Cloud Functions Events
138
165
139
166
The Functions Framework can unmarshall incoming
140
167
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
158
185
159
186
See the [running example](examples/cloud_run_event).
160
187
161
-
# Enable CloudEvents
188
+
##Enable CloudEvents
162
189
163
190
The Functions Framework can unmarshall incoming
164
191
[CloudEvent](http://cloudevents.io) payloads to a `cloudevent` object.
@@ -176,11 +203,11 @@ To enable automatic unmarshalling, set the function signature type to `cloudeven
176
203
177
204
See the [running example](examples/cloud_run_cloudevents).
178
205
179
-
# Advanced Examples
206
+
##Advanced Examples
180
207
181
208
More advanced guides can be found in the [`examples/`](https://github.com/GoogleCloudPlatform/functions-framework-python/blob/master/examples/) directory.
182
209
You can also find examples on using the CloudEvent Python SDK [here](https://github.com/cloudevents/sdk-python).
183
210
184
-
# Contributing
211
+
##Contributing
185
212
186
213
Contributions to this library are welcome and encouraged. See [CONTRIBUTING](CONTRIBUTING.md) for more information on how to get started.
0 commit comments