Skip to content

Commit 18c61d7

Browse files
evan-graykev1n-peters
authored andcommitted
fly: adopt from example-fly-firestore
1 parent 70e276e commit 18c61d7

13 files changed

+3069
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ lastBlockByChain.json
88
serviceAccountKey.json
99
bigtableAccountKey.json
1010
tsconfig.tsbuildinfo
11+
serviceAccount.json

cloud-functions/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The cloud-functions can be run locally by:
2+
3+
```bash
4+
# Spin up a local development server for quick testing
5+
export GCP_PROJECT=""
6+
export GOOGLE_APPLICATION_CREDENTIALS=""
7+
go run cmd/main.go
8+
9+
# Invoke a function in response to a request
10+
curl localhost:8080/guardian-heartbeats
11+
```

cloud-functions/cmd/main.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"net/http"
7+
"os"
8+
9+
p "github.com/wormhole-foundation/example-fly-firestore/cloud-functions"
10+
11+
"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
12+
)
13+
14+
var mux = newMux()
15+
16+
// Entry is the cloud function entry point
17+
func Entry(w http.ResponseWriter, r *http.Request) {
18+
mux.ServeHTTP(w, r)
19+
}
20+
21+
func newMux() *http.ServeMux {
22+
mux := http.NewServeMux()
23+
mux.HandleFunc("/guardian-heartbeats", p.Heartbeats)
24+
mux.HandleFunc("/governor-status", p.GovernorStatus)
25+
mux.HandleFunc("/governor-configs", p.GovernorConfigs)
26+
return mux
27+
}
28+
29+
func main() {
30+
ctx := context.Background()
31+
if err := funcframework.RegisterHTTPFunctionContext(ctx, "/", Entry); err != nil {
32+
log.Fatalf("funcframework.RegisterHTTPFunctionContext: %v\n", err)
33+
}
34+
// Use PORT environment variable, or default to 8080.
35+
port := "8080"
36+
if envPort := os.Getenv("PORT"); envPort != "" {
37+
port = envPort
38+
}
39+
if err := funcframework.Start(port); err != nil {
40+
log.Fatalf("funcframework.Start: %v\n", err)
41+
}
42+
}

cloud-functions/deploy.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ -z "$GCP_PROJECT" ]; then
5+
echo "GCP_PROJECT must be specified"
6+
exit 1
7+
fi
8+
9+
if [ -z "$SERVICE_ACCOUNT" ]; then
10+
echo "SERVICE_ACCOUNT must be specified"
11+
exit 1
12+
fi
13+
14+
gcloud functions --project "$GCP_PROJECT" deploy guardian-heartbeats --region=europe-west3 --entry-point Heartbeats --memory=256MB --runtime go116 --trigger-http --allow-unauthenticated --service-account="$SERVICE_ACCOUNT" --update-env-vars GCP_PROJECT="$GCP_PROJECT"
15+
gcloud functions --project "$GCP_PROJECT" deploy governor-status --region=europe-west3 --entry-point GovernorStatus --memory=256MB --runtime go116 --trigger-http --allow-unauthenticated --service-account="$SERVICE_ACCOUNT" --update-env-vars GCP_PROJECT="$GCP_PROJECT"
16+
gcloud functions --project "$GCP_PROJECT" deploy governor-configs --region=europe-west3 --entry-point GovernorConfigs --memory=256MB --runtime go116 --trigger-http --allow-unauthenticated --service-account="$SERVICE_ACCOUNT" --update-env-vars GCP_PROJECT="$GCP_PROJECT"

cloud-functions/go.mod

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module github.com/wormhole-foundation/example-fly-firestore/cloud-functions
2+
3+
go 1.17
4+
5+
require (
6+
cloud.google.com/go/firestore v1.8.0
7+
firebase.google.com/go v3.13.0+incompatible
8+
github.com/GoogleCloudPlatform/functions-framework-go v1.6.1
9+
google.golang.org/api v0.98.0
10+
)
11+
12+
require (
13+
cloud.google.com/go v0.104.0 // indirect
14+
cloud.google.com/go/compute v1.7.0 // indirect
15+
cloud.google.com/go/functions v1.7.0 // indirect
16+
cloud.google.com/go/iam v0.3.0 // indirect
17+
cloud.google.com/go/storage v1.23.0 // indirect
18+
github.com/cloudevents/sdk-go/v2 v2.6.1 // indirect
19+
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
20+
github.com/golang/protobuf v1.5.2 // indirect
21+
github.com/google/go-cmp v0.5.8 // indirect
22+
github.com/google/uuid v1.3.0 // indirect
23+
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
24+
github.com/googleapis/gax-go/v2 v2.5.1 // indirect
25+
github.com/googleapis/go-type-adapters v1.0.0 // indirect
26+
github.com/json-iterator/go v1.1.10 // indirect
27+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
28+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
29+
go.opencensus.io v0.23.0 // indirect
30+
go.uber.org/atomic v1.4.0 // indirect
31+
go.uber.org/multierr v1.1.0 // indirect
32+
go.uber.org/zap v1.10.0 // indirect
33+
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
34+
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
35+
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
36+
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
37+
golang.org/x/text v0.3.7 // indirect
38+
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
39+
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
40+
google.golang.org/appengine v1.6.7 // indirect
41+
google.golang.org/genproto v0.0.0-20221010155953-15ba04fc1c0e // indirect
42+
google.golang.org/grpc v1.49.0 // indirect
43+
google.golang.org/protobuf v1.28.1 // indirect
44+
)

0 commit comments

Comments
 (0)