devnet: simplify cloud function setup
Change-Id: I931501aa5162569785cb078a546dc44a3741de08 commit-id:26e9ff05
This commit is contained in:
parent
fd35514a53
commit
fc1e162f3b
72
Tiltfile
72
Tiltfile
|
@ -327,63 +327,7 @@ if e2e:
|
||||||
|
|
||||||
# bigtable
|
# bigtable
|
||||||
|
|
||||||
def build_cloud_function(container_name, go_func_name, path, builder):
|
|
||||||
# Invokes Tilt's custom_build(), with a Pack command.
|
|
||||||
# inspired by https://github.com/tilt-dev/tilt-extensions/tree/master/pack
|
|
||||||
tag = "latest"
|
|
||||||
caching_ref = container_name + ":" + tag
|
|
||||||
|
|
||||||
pack_build_cmd = " ".join([
|
|
||||||
"./tools/bin/pack build",
|
|
||||||
caching_ref,
|
|
||||||
"--path " + path,
|
|
||||||
"--builder " + builder,
|
|
||||||
"--run-image devnet-cloud-function",
|
|
||||||
"--env " + "GOOGLE_FUNCTION_TARGET=%s" % go_func_name,
|
|
||||||
"--env " + "GOOGLE_FUNCTION_SIGNATURE_TYPE=http",
|
|
||||||
])
|
|
||||||
|
|
||||||
disable_push = True
|
|
||||||
skips_local_docker = True
|
|
||||||
if ci:
|
|
||||||
# inherit the DOCKER_HOST socket provided by custom_build.
|
|
||||||
pack_build_cmd = pack_build_cmd + " --docker-host inherit"
|
|
||||||
|
|
||||||
# do not attempt to access Docker cache in CI
|
|
||||||
# pack_build_cmd = pack_build_cmd + " --clear-cache"
|
|
||||||
# don't try to pull previous container versions in CI
|
|
||||||
pack_build_cmd = pack_build_cmd + " --pull-policy never"
|
|
||||||
|
|
||||||
# push to kubernetes registry
|
|
||||||
disable_push = False
|
|
||||||
skips_local_docker = False
|
|
||||||
|
|
||||||
docker_tag_cmd = "tilt docker -- tag " + caching_ref + " $EXPECTED_REF"
|
|
||||||
custom_build(
|
|
||||||
container_name,
|
|
||||||
pack_build_cmd + " && " + docker_tag_cmd,
|
|
||||||
[path],
|
|
||||||
tag = tag,
|
|
||||||
skips_local_docker = skips_local_docker,
|
|
||||||
disable_push = disable_push,
|
|
||||||
)
|
|
||||||
|
|
||||||
if explorer:
|
if explorer:
|
||||||
local_resource(
|
|
||||||
name = "devnet-cloud-function",
|
|
||||||
cmd = "tilt docker -- build -f ./event_database/cloud_functions/Dockerfile.run . -t devnet-cloud-function --label builtby=tilt",
|
|
||||||
env = {"DOCKER_BUILDKIT": "1"},
|
|
||||||
labels = ["explorer"],
|
|
||||||
trigger_mode = trigger_mode,
|
|
||||||
)
|
|
||||||
|
|
||||||
local_resource(
|
|
||||||
name = "pack-bin",
|
|
||||||
cmd = "go build -mod=readonly -o bin/pack github.com/buildpacks/pack/cmd/pack",
|
|
||||||
dir = "tools",
|
|
||||||
labels = ["explorer"],
|
|
||||||
trigger_mode = trigger_mode,
|
|
||||||
)
|
|
||||||
|
|
||||||
k8s_yaml_with_ns("devnet/bigtable.yaml")
|
k8s_yaml_with_ns("devnet/bigtable.yaml")
|
||||||
|
|
||||||
|
@ -394,16 +338,18 @@ if explorer:
|
||||||
trigger_mode = trigger_mode,
|
trigger_mode = trigger_mode,
|
||||||
)
|
)
|
||||||
|
|
||||||
build_cloud_function(
|
docker_build(
|
||||||
container_name = "bigtable-functions",
|
ref = "cloud-functions",
|
||||||
go_func_name = "Entry",
|
context = "./event_database/cloud_functions",
|
||||||
path = "./event_database/cloud_functions",
|
dockerfile = "./event_database/cloud_functions/Dockerfile",
|
||||||
builder = "gcr.io/buildpacks/builder:v1",
|
live_update = [
|
||||||
|
sync("./event_database/cloud_functions", "/app"),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
k8s_resource(
|
k8s_resource(
|
||||||
"bigtable-functions",
|
"cloud-functions",
|
||||||
resource_deps = ["proto-gen", "bigtable-emulator"],
|
resource_deps = ["proto-gen", "bigtable-emulator"],
|
||||||
port_forwards = [port_forward(8090, name = "BigTable Functions [:8090]", host = webHost)],
|
port_forwards = [port_forward(8090, name = "Cloud Functions [:8090]")],
|
||||||
labels = ["explorer"],
|
labels = ["explorer"],
|
||||||
trigger_mode = trigger_mode,
|
trigger_mode = trigger_mode,
|
||||||
)
|
)
|
||||||
|
|
|
@ -79,22 +79,22 @@ apiVersion: apps/v1
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: bigtable-functions
|
app: cloud-functions
|
||||||
name: bigtable-functions
|
name: cloud-functions
|
||||||
spec:
|
spec:
|
||||||
serviceName: bigtable-functions
|
serviceName: cloud-functions
|
||||||
replicas: 1
|
replicas: 1
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: bigtable-functions
|
app: cloud-functions
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: bigtable-functions
|
app: cloud-functions
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: bigtable-functions
|
- name: cloud-functions
|
||||||
image: bigtable-functions
|
image: cloud-functions
|
||||||
env:
|
env:
|
||||||
- name: BIGTABLE_EMULATOR_HOST
|
- name: BIGTABLE_EMULATOR_HOST
|
||||||
value: bigtable-emulator:8086
|
value: bigtable-emulator:8086
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
# syntax=docker.io/docker/dockerfile:experimental@sha256:de85b2f3a3e8a2f7fe48e8e84a65f6fdd5cd5183afa6412fff9caa6871649c44
|
||||||
|
FROM docker.io/golang:1.17.0@sha256:06e92e576fc7a7067a268d47727f3083c0a564331bfcbfdde633157fc91fb17d
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ADD . .
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache --mount=type=cache,target=/go \
|
||||||
|
go build -mod=readonly -o /functions cmd/main.go
|
||||||
|
|
||||||
|
CMD ["/functions"]
|
|
@ -1,5 +0,0 @@
|
||||||
# syntax=docker.io/docker/dockerfile:1.3@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
|
|
||||||
FROM gcr.io/buildpacks/gcp/run@sha256:04f2e841ebbcc140c9f817e274caf8ae8ae0341008c4e01d8ef84cb8aa8c312a
|
|
||||||
|
|
||||||
# the "builtby=tilt" label is how Tilt determines which containters can be purged.
|
|
||||||
LABEL builtby=tilt
|
|
|
@ -4,22 +4,32 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
|
"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
|
||||||
p "github.com/certusone/wormhole/event_database/cloud_functions"
|
p "github.com/certusone/wormhole/event_database/cloud_functions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.Background()
|
var wg sync.WaitGroup
|
||||||
if err := funcframework.RegisterHTTPFunctionContext(ctx, "/", p.Entry); err != nil {
|
|
||||||
log.Fatalf("funcframework.RegisterHTTPFunctionContext: %v\n", err)
|
// http functions
|
||||||
}
|
wg.Add(1)
|
||||||
// Use PORT environment variable, or default to 8080.
|
go func() {
|
||||||
port := "8080"
|
defer wg.Done()
|
||||||
if envPort := os.Getenv("PORT"); envPort != "" {
|
ctx := context.Background()
|
||||||
port = envPort
|
if err := funcframework.RegisterHTTPFunctionContext(ctx, "/", p.Entry); err != nil {
|
||||||
}
|
log.Fatalf("funcframework.RegisterHTTPFunctionContext: %v\n", err)
|
||||||
if err := funcframework.Start(port); err != nil {
|
}
|
||||||
log.Fatalf("funcframework.Start: %v\n", err)
|
// Use PORT environment variable, or default to 8080.
|
||||||
}
|
port := "8080"
|
||||||
|
if envPort := os.Getenv("PORT"); envPort != "" {
|
||||||
|
port = envPort
|
||||||
|
}
|
||||||
|
if err := funcframework.Start(port); err != nil {
|
||||||
|
log.Fatalf("funcframework.Start: %v\n", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue