Skip to content

Commit

Permalink
Add connect-node-fastify server (#477)
Browse files Browse the repository at this point in the history
This adds a new Connect server using `connect-fastify` and
`connect-node`. It wires it into the docker-compose setup and allows for
serving HTTP/1.1 and HTTP/2 traffic using cleartext and TLS. Fastify
does not offer HTTP/3 support as of yet, so that path is not available.
Note: this does not yet use TLS, but can be added as a follow-up PR.

In addition, this also refactors a few things such as:
* adds TypeScript support to the web portion
* renames images, Dockerfiles, etc. to match the language so that adding
new languages can follow one pattern. For example,
`client-connect-to-server-connect-go-h2` becomes
`client-connect-go-to-server-connect-go-h2` and uses
`Dockerfile.crosstestgo` instead of `Dockerfile.crosstest`.
* updates to connect-go v1.9.0 for
https://github.com/bufbuild/connect-go/pull/528 which fixes an issue
with parsing response headers from a connect-node server.
* updates to connect-es v0.11.0 for
connectrpc/connect-es#695, which fixes an issue
with parsing response bodies for non-JSON content types.
  • Loading branch information
smaye81 authored Jun 29, 2023
1 parent bbc0af2 commit 3e4b5ac
Show file tree
Hide file tree
Showing 42 changed files with 4,371 additions and 4,777 deletions.
1 change: 1 addition & 0 deletions Dockerfile.crosstest → Dockerfile.crosstestgo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ARG TEST_CONNECT_GO_BRANCH
COPY go.mod go.sum /workspace/
COPY cmd /workspace/cmd
COPY internal /workspace/internal
COPY proto /workspace/proto
COPY cert /workspace/cert
RUN if [ ! -z "$TEST_CONNECT_GO_BRANCH" ]; then go get github.com/bufbuild/connect-go@$TEST_CONNECT_GO_BRANCH; fi
RUN --mount=type=cache,target=/root/.cache/go-build \
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile.crosstestweb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ COPY web/package.json web/package-lock.json /workspace/
COPY web/tsconfig.json web/karma.conf.js /workspace/
COPY web/gen /workspace/gen
COPY web/spec /workspace/spec
RUN npm install --production
COPY web/server /workspace/server
COPY cert /workspace/cert
RUN npm install
RUN local_npm_packages="" && \
if [ ! -z "${TEST_PROTOBUF_ES_BRANCH}" ]; then \
git clone --branch "${TEST_PROTOBUF_ES_BRANCH}" --depth 1 https://github.com/bufbuild/protobuf-es.git ../protobuf-es && \
Expand Down
55 changes: 34 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
COPYRIGHT_YEARS := 2022
LICENSE_IGNORE := -e internal/proto/grpc -e internal/interopgrpc -e web/spec/grpc-web.spec.ts
LICENSE_IGNORE := -e proto/grpc -e internal/interopgrpc -e web/spec/grpc-web.spec.ts -e web/server/fastify/program.ts
# Set to use a different compiler. For example, `GO=go1.18rc1 make test`.
GO ?= go

Expand Down Expand Up @@ -81,30 +81,43 @@ checkgenerate:

.PHONY: dockercomposetestgo
dockercomposetestgo: dockercomposeclean
docker-compose run client-connect-to-server-connect-h1
docker-compose run client-connect-to-server-connect-h2
docker-compose run client-connect-to-server-connect-h3
docker-compose run client-connect-grpc-to-server-connect-h1
docker-compose run client-connect-grpc-to-server-connect-h2
docker-compose run client-connect-grpc-web-to-server-connect-h1
docker-compose run client-connect-grpc-web-to-server-connect-h2
docker-compose run client-connect-grpc-web-to-server-connect-h3
docker-compose run client-connect-grpc-web-to-envoy-server-connect-h1
docker-compose run client-connect-grpc-web-to-envoy-server-grpc-h1
docker-compose run client-connect-grpc-to-server-grpc
docker-compose run client-grpc-to-server-connect
docker-compose run client-grpc-to-server-grpc
docker-compose run client-connect-go-to-server-connect-go-h1
docker-compose run client-connect-go-to-server-connect-go-h2
docker-compose run client-connect-go-to-server-connect-go-h3
docker-compose run client-connect-go-to-server-connect-node-fastify-h1
docker-compose run client-connect-go-to-server-connect-node-fastify-h2
docker-compose run client-connect-go-grpc-to-server-connect-node-fastify-h1
docker-compose run client-connect-go-grpc-to-server-connect-node-fastify-h2
docker-compose run client-connect-go-grpc-web-to-server-connect-node-fastify-h1
docker-compose run client-connect-go-grpc-web-to-server-connect-node-fastify-h2
docker-compose run client-connect-go-grpc-to-server-connect-go-h1
docker-compose run client-connect-go-grpc-to-server-connect-go-h2
docker-compose run client-connect-go-grpc-web-to-server-connect-go-h1
docker-compose run client-connect-go-grpc-web-to-server-connect-go-h2
docker-compose run client-connect-go-grpc-web-to-server-connect-go-h3
docker-compose run client-connect-go-grpc-web-to-envoy-server-connect-go-h1
docker-compose run client-connect-go-grpc-web-to-envoy-server-grpc-go-h1
docker-compose run client-connect-go-grpc-web-to-envoy-server-connect-node-fastify-h1
docker-compose run client-connect-go-grpc-to-server-grpc-go
docker-compose run client-grpc-go-to-server-connect-go
docker-compose run client-grpc-go-to-server-grpc-go
docker-compose run client-grpc-go-to-server-connect-node-fastify
$(MAKE) dockercomposeclean

.PHONY: dockercomposetestweb
dockercomposetestweb: dockercomposeclean
docker-compose run client-web-connect-web-to-server-connect-h1
docker-compose run client-web-connect-grpc-web-to-server-connect-h1
docker-compose run client-web-connect-grpc-web-to-envoy-server-connect
docker-compose run client-web-connect-grpc-web-to-envoy-server-grpc
docker-compose run client-web-grpc-web-to-server-connect-h1
docker-compose run client-web-grpc-web-to-envoy-server-connect
docker-compose run client-web-grpc-web-to-envoy-server-grpc
docker-compose run client-connect-web-to-server-connect-go-h1
docker-compose run client-connect-web-grpc-web-to-server-connect-go-h1
docker-compose run client-connect-web-grpc-web-to-envoy-server-connect-go
docker-compose run client-connect-web-grpc-web-to-envoy-server-grpc-go
docker-compose run client-connect-web-grpc-web-to-envoy-server-connect-node-fastify
docker-compose run client-grpc-web-to-server-connect-go-h1
docker-compose run client-grpc-web-to-envoy-server-connect-go
docker-compose run client-grpc-web-to-envoy-server-grpc-go
docker-compose run client-grpc-web-to-envoy-server-connect-node-fastify
docker-compose run client-connect-web-to-server-connect-node-fastify-h1
docker-compose run client-connect-web-grpc-web-to-server-connect-node-fastify-h1
docker-compose run client-grpc-web-to-server-connect-node-fastify-h1
$(MAKE) dockercomposeclean

.PHONY: dockercomposetest
Expand Down
4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ plugins:
- name: connect-go
out: internal/gen/proto/connect
opt: paths=source_relative
- plugin: buf.build/bufbuild/es:v1.0.0
- plugin: buf.build/bufbuild/es:v1.2.1
out: web/gen/proto/connect-web
opt: target=ts
- plugin: buf.build/bufbuild/connect-es:v0.8.0
- plugin: buf.build/bufbuild/connect-es:v0.10.0
out: web/gen/proto/connect-web
opt: target=ts
- plugin: buf.build/protocolbuffers/js:v3.21.2
Expand Down
2 changes: 1 addition & 1 deletion buf.work.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version: v1
directories:
- internal/proto
- proto
11 changes: 9 additions & 2 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"golang.org/x/net/http2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"
)

Expand Down Expand Up @@ -138,23 +139,29 @@ func bind(cmd *cobra.Command, flags *flags) error {
func run(flags *flags) {
// tests for grpc client
if flags.implementation == grpcGo {
transportCredentials := credentials.NewTLS(newTLSConfig(flags.certFile, flags.keyFile))
var transportCredentials credentials.TransportCredentials
if !flags.insecure {
transportCredentials = credentials.NewTLS(newTLSConfig(flags.certFile, flags.keyFile))
} else {
transportCredentials = insecure.NewCredentials()
}
clientConn, err := grpc.Dial(
net.JoinHostPort(flags.host, flags.port),
grpc.WithTransportCredentials(transportCredentials),
)
if err != nil {
log.Fatalf("failed grpc dial: %v", err)
}
defer clientConn.Close()
unresolvableClientConn, err := grpc.Dial(
"unresolvable-host.some.domain",
grpc.WithTransportCredentials(transportCredentials),
)
if err != nil {
log.Fatalf("failed grpc dial: %v", err)
}
defer clientConn.Close()
defer unresolvableClientConn.Close()

testGrpc(clientConn, unresolvableClientConn)
return
}
Expand Down
Loading

0 comments on commit 3e4b5ac

Please sign in to comment.