functions_framework 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/docs/deploying-functions.md +14 -1
- data/docs/overview.md +1 -1
- data/docs/writing-functions.md +6 -5
- data/lib/functions_framework/legacy_event_converter.rb +10 -1
- data/lib/functions_framework/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f82e8f7fb76005b4b61225b3ca02e31e52caecb2742604b88b6b60ced2945d84
|
4
|
+
data.tar.gz: 5f274cc6bdd13c7367d55212d1fb39f26432d8d00a6d607c09543e3818637c49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6470be9c192f2231a610830bf51563638ce27e4330f071dd28b41a8fc15811704ace7025cede45ea54a13b4862d86153401360523d6bb479735793e1ed1e00c4
|
7
|
+
data.tar.gz: c7fd524f8c7c4819a6cb6a95d7e7ec0aa371e4211c8b521efe42d63ab3ca794dbfad490613633660c89aaa01479cbfe4d5e98683454e6bd4cdc382f1978da396
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -60,7 +60,7 @@ Create a `Gemfile` listing the Functions Framework as a dependency:
|
|
60
60
|
```ruby
|
61
61
|
# Gemfile
|
62
62
|
source "https://rubygems.org"
|
63
|
-
gem "functions_framework", "~> 0.
|
63
|
+
gem "functions_framework", "~> 0.3"
|
64
64
|
```
|
65
65
|
|
66
66
|
Create a file called `app.rb` and include the following code. This defines a
|
data/docs/deploying-functions.md
CHANGED
@@ -30,12 +30,21 @@ Google Cloud Functions is Google's scalable pay-as-you-go Functions-as-a-Service
|
|
30
30
|
Functions Framework is designed especially for functions that can be hosted on
|
31
31
|
Cloud Functions.
|
32
32
|
|
33
|
+
You can run Ruby functions on Google Cloud Functions by selecting the `ruby26`
|
34
|
+
runtime. This runtime uses a recent release of Ruby 2.6. Support for other
|
35
|
+
versions of Ruby may be added in the future.
|
36
|
+
|
37
|
+
> **Note:** Ruby support on Cloud Functions is currently in limited preview.
|
38
|
+
> It is not yet suitable for production workloads, and support is best-effort
|
39
|
+
> only. Access is currently limited to selected early-access users.
|
40
|
+
|
33
41
|
### Deploying and updating your function
|
34
42
|
|
35
43
|
Before you can deploy to Cloud Functions, make sure your bundle, and in
|
36
44
|
particular your `Gemfile.lock` file, is up to date. The easiest way to do this
|
37
45
|
is to `bundle install` or `bundle update` and run your local tests prior to
|
38
|
-
deploying.
|
46
|
+
deploying. Cloud Functions will not accept your function unless an up-to-date
|
47
|
+
`Gemfile.lock` is present.
|
39
48
|
|
40
49
|
Choose a name for your function. This function name is how it will appear in the
|
41
50
|
cloud console, and will also be part of the function's URL. (It's different from
|
@@ -126,6 +135,10 @@ You must use your project ID, but you can choose an app name and build ID. The
|
|
126
135
|
command may ask you for permission to enable the Cloud Build API for the project
|
127
136
|
if it isn't already enabled.
|
128
137
|
|
138
|
+
Because you provide your own Docker image when deploying to Cloud Run, you can
|
139
|
+
use any version of Ruby supported by the Functions Framework, from 2.4 through
|
140
|
+
2.7.
|
141
|
+
|
129
142
|
### Deploying an image to Cloud Run
|
130
143
|
|
131
144
|
To deploy to Cloud Run, specify the same image URL that you built above. For
|
data/docs/overview.md
CHANGED
@@ -64,7 +64,7 @@ Create a `Gemfile` listing the Functions Framework as a dependency:
|
|
64
64
|
```ruby
|
65
65
|
# Gemfile
|
66
66
|
source "https://rubygems.org"
|
67
|
-
gem "functions_framework", "~> 0.
|
67
|
+
gem "functions_framework", "~> 0.3"
|
68
68
|
```
|
69
69
|
|
70
70
|
Create a file called `app.rb` and include the following code. This defines a
|
data/docs/writing-functions.md
CHANGED
@@ -156,7 +156,7 @@ the [CloudEvents spec](https://github.com/cloudevents/spec/blob/v1.0/spec.md).
|
|
156
156
|
Some Google Cloud services send events in a legacy event format that was defined
|
157
157
|
prior to CloudEvents. The Functions Framework will convert these legacy events
|
158
158
|
to an equivalent CloudEvents type, so your function will always receive a
|
159
|
-
CloudEvent when it is sent an event from Google Cloud.
|
159
|
+
CloudEvent object when it is sent an event from Google Cloud.
|
160
160
|
|
161
161
|
## Error handling
|
162
162
|
|
@@ -188,9 +188,10 @@ end
|
|
188
188
|
|
189
189
|
A Functions Framework based "project" or "application" is a typical Ruby
|
190
190
|
application. It should include a `Gemfile` that specifies the gem dependencies
|
191
|
-
(including the `functions_framework` gem itself), and
|
192
|
-
|
193
|
-
|
191
|
+
(including the `functions_framework` gem itself), and any other dependencies
|
192
|
+
needed by the function. It must include at least one Ruby source file that
|
193
|
+
defines functions, and can also include additional Ruby files defining classes
|
194
|
+
and methods that assist in the function implementation.
|
194
195
|
|
195
196
|
The "entrypoint" to the project, also called the "source", is a Ruby file. It
|
196
197
|
can define any number of functions (with distinct names), although it is often
|
@@ -221,7 +222,7 @@ A simple project might look like this:
|
|
221
222
|
```ruby
|
222
223
|
# Gemfile
|
223
224
|
source "https://rubygems.org"
|
224
|
-
gem "functions_framework", "~> 0.
|
225
|
+
gem "functions_framework", "~> 0.3"
|
225
226
|
```
|
226
227
|
|
227
228
|
```ruby
|
@@ -84,12 +84,13 @@ module FunctionsFramework
|
|
84
84
|
source, subject = convert_source context[:service], context[:resource]
|
85
85
|
type = LEGACY_TYPE_TO_CE_TYPE[context[:type]]
|
86
86
|
return nil unless type && source
|
87
|
+
ce_data = convert_data context[:service], data
|
87
88
|
CloudEvents::Event.new id: context[:id],
|
88
89
|
source: source,
|
89
90
|
type: type,
|
90
91
|
spec_version: "1.0",
|
91
92
|
data_content_type: "application/json",
|
92
|
-
data:
|
93
|
+
data: ce_data,
|
93
94
|
subject: subject,
|
94
95
|
time: context[:timestamp]
|
95
96
|
end
|
@@ -104,6 +105,14 @@ module FunctionsFramework
|
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
108
|
+
def convert_data service, data
|
109
|
+
if service == "pubsub.googleapis.com"
|
110
|
+
{ "message" => data, "subscription" => nil }
|
111
|
+
else
|
112
|
+
data
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
107
116
|
LEGACY_TYPE_TO_SERVICE = {
|
108
117
|
%r{^providers/cloud\.firestore/} => "firestore.googleapis.com",
|
109
118
|
%r{^providers/cloud\.pubsub/} => "pubsub.googleapis.com",
|