-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deploy grpc gateway to cloud run with an apigee proxy
- Loading branch information
1 parent
328b46b
commit 1f81496
Showing
10 changed files
with
321 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tools/grpc-http-gateway-generator/templates/apiproxy/currency-v1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<!-- | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<APIProxy revision="1" name="currency-v1"> | ||
</APIProxy> |
21 changes: 21 additions & 0 deletions
21
tools/grpc-http-gateway-generator/templates/apiproxy/policies/AM.SetConversionPath.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<AssignMessage name="AM.SetConversionPath"> | ||
<AssignVariable> | ||
<Name>flow.target.pathsuffix</Name> | ||
<Value>/hipstershop.CurrencyService/Convert</Value> | ||
</AssignVariable> | ||
</AssignMessage> |
21 changes: 21 additions & 0 deletions
21
tools/grpc-http-gateway-generator/templates/apiproxy/policies/AM.SetCurrenciesPath.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<AssignMessage name="AM.SetCurrenciesPath"> | ||
<AssignVariable> | ||
<Name>flow.target.pathsuffix</Name> | ||
<Value>/hipstershop.CurrencyService/GetSupportedCurrencies</Value> | ||
</AssignVariable> | ||
</AssignMessage> |
20 changes: 20 additions & 0 deletions
20
tools/grpc-http-gateway-generator/templates/apiproxy/policies/HM.SetTargetMethod.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<HTTPModifier continueOnError="false" enabled="true" name="HM.SetTargetMethod"> | ||
<Set> | ||
<Verb>POST</Verb> | ||
</Set> | ||
</HTTPModifier> |
18 changes: 18 additions & 0 deletions
18
tools/grpc-http-gateway-generator/templates/apiproxy/policies/JS.SetTargetPath.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<Javascript timeLimit="200" name="JS.SetTargetPath"> | ||
<ResourceURL>jsc://set-target-path.js</ResourceURL> | ||
</Javascript> |
48 changes: 48 additions & 0 deletions
48
tools/grpc-http-gateway-generator/templates/apiproxy/proxies/default.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!-- | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<ProxyEndpoint name="default"> | ||
<Flows> | ||
<Flow> | ||
<Condition>request.verb = "GET" and proxy.pathsuffix = "/currencies"</Condition> | ||
<Request> | ||
<Step> | ||
<Name>AM.SetCurrenciesPath</Name> | ||
</Step> | ||
</Request> | ||
</Flow> | ||
<Flow> | ||
<Condition>request.verb = "POST" and proxy.pathsuffix = "/convert"</Condition> | ||
<Request> | ||
<Step> | ||
<Name>AM.SetConversionPath</Name> | ||
</Step> | ||
</Request> | ||
</Flow> | ||
</Flows> | ||
<PostFlow> | ||
<Request> | ||
<Step> | ||
<Name>HM.SetTargetMethod</Name> | ||
</Step> | ||
</Request> | ||
</PostFlow> | ||
<HTTPProxyConnection> | ||
<BasePath>/currency/v1</BasePath> | ||
</HTTPProxyConnection> | ||
<RouteRule name="default"> | ||
<TargetEndpoint>default</TargetEndpoint> | ||
</RouteRule> | ||
</ProxyEndpoint> |
29 changes: 29 additions & 0 deletions
29
tools/grpc-http-gateway-generator/templates/apiproxy/resources/jsc/set-target-path.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
context.setVariable("target.copy.pathsuffix", false) | ||
|
||
var existingTargetUrl = context.getVariable("target.url"); | ||
var targetPath = context.getVariable("flow.target.pathsuffix") || ""; // retrieve custom path, set by AM policies | ||
var queryString = context.getVariable("request.querystring") || ""; | ||
|
||
var updatedTargetUrl = existingTargetUrl + targetPath + (queryString ? "?"+queryString : ""); | ||
|
||
context.setVariable("target.url", | ||
existingTargetUrl + // use target base URL | ||
targetPath + // append custom path | ||
(queryString ? "?"+queryString : "") // conditionally append query params | ||
); |
32 changes: 32 additions & 0 deletions
32
tools/grpc-http-gateway-generator/templates/apiproxy/targets/default.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!-- | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<TargetEndpoint name="default"> | ||
<PreFlow> | ||
<Request> | ||
<Step> | ||
<Name>JS.SetTargetPath</Name> | ||
</Step> | ||
</Request> | ||
</PreFlow> | ||
<HTTPTargetConnection> | ||
<Authentication> | ||
<GoogleIDToken> | ||
<Audience>CLOUD_RUN_URL</Audience> | ||
</GoogleIDToken> | ||
</Authentication> | ||
<URL>CLOUD_RUN_URL</URL> | ||
</HTTPTargetConnection> | ||
</TargetEndpoint> |
53 changes: 53 additions & 0 deletions
53
tools/grpc-http-gateway-generator/templates/cloud-run-service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2024 Google LLC | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: serving.knative.dev/v1 | ||
kind: Service | ||
metadata: | ||
name: currency-service | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: grpc-gateway | ||
image: GRPC_GATEWAY_IMAGE | ||
ports: | ||
- name: http1 | ||
containerPort: 8080 | ||
resources: | ||
limits: | ||
cpu: 1000m | ||
memory: 512Mi | ||
startupProbe: | ||
timeoutSeconds: 240 | ||
periodSeconds: 240 | ||
failureThreshold: 1 | ||
tcpSocket: | ||
port: 8080 | ||
- name: currencyservice-1 | ||
image: gcr.io/google-samples/microservices-demo/currencyservice@sha256:e08a1f5d4e4b74fc3d6222d535a11615e8201e7075a090c1ba4436ef1f1cbe7b | ||
env: | ||
- name: PORT | ||
value: '9090' | ||
resources: | ||
limits: | ||
cpu: 1000m | ||
memory: 512Mi | ||
startupProbe: | ||
timeoutSeconds: 1 | ||
periodSeconds: 10 | ||
failureThreshold: 3 | ||
grpc: | ||
port: 9090 | ||
service: currencyservice-v1 |