Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dockerfile for community/mercari-grpc-federation #1022

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/community/mercari-grpc-federation/source.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
source:
# Disabling this plugin until it can be updated to work without invoking the
# Go toolchain for formatting. For more information, see:
# https://github.com/bufbuild/plugins/pull/1022#issuecomment-1908230254
disabled: true
github:
owner: mercari
repository: grpc-federation
2 changes: 2 additions & 0 deletions plugins/community/mercari-grpc-federation/v0.9.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
FROM scratch
COPY --from=build --link --chown=root:root /etc/passwd /etc/passwd
COPY --from=build --link --chown=root:root /go/bin/protoc-gen-grpc-federation .
COPY --from=build --link --chown=root:root /usr/local/go/bin/go /bin/go
ENV GOROOT /
USER nobody
ENTRYPOINT [ "/protoc-gen-grpc-federation" ]
17 changes: 12 additions & 5 deletions tests/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ exec docker run --log-driver=none --rm -i {{.ImageName}}:{{.Version}} "$@"
}
// Some plugins do not generate any code for the test protos, so we allow an empty plugin.sum file for these
// plugins.
allowedEmptyPluginSums = map[string]bool{
"buf.build/bufbuild/validate-java": true,
"buf.build/grpc-ecosystem/gateway": true,
allowedEmptyPluginSums = map[string]map[string]bool{
"buf.build/bufbuild/validate-java": {"eliza": true, "petapis": true},
"buf.build/grpc-ecosystem/gateway": {"eliza": true, "petapis": true},
"buf.build/community/mercari-grpc-federation": {"eliza": true, "petapis": true},
}
)

Expand Down Expand Up @@ -95,8 +96,11 @@ func TestGeneration(t *testing.T) {
// for these plugins. See grpc-ecosystem/gateway for an example.
genDirFiles, err := os.ReadDir(pluginGenDir)
require.NoError(t, err, "failed to read generated code directory")
if len(genDirFiles) == 0 && !allowedEmptyPluginSums[pluginMeta.Name] {
t.Fatalf("generated code directory is empty for %s", pluginMeta)
if len(genDirFiles) == 0 {
allowedEmptyImages, ok := allowedEmptyPluginSums[pluginMeta.Name]
if !ok || !allowedEmptyImages[image] {
t.Fatalf("generated code directory is empty for %s", pluginMeta)
}
}
genDirHash, err := dirhash.HashDir(pluginGenDir, "", dirhash.Hash1)
require.NoError(t, err, "failed to calculate directory hash of generated code")
Expand Down Expand Up @@ -135,6 +139,9 @@ func TestGeneration(t *testing.T) {
if toTest.Name == "buf.build/grpc-ecosystem/gateway" && semver.Compare(toTest.PluginVersion, "v2.16.0") >= 0 {
testPluginWithImage(t, toTest, "grpc-gateway")
}
if toTest.Name == "buf.build/community/mercari-grpc-federation" {
testPluginWithImage(t, toTest, "grpc-federation")
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1:d0P6WfW6ve00/zKIclE7fO8vZGCrQGOZnkhw9papifI=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the sum of the generated code from the sample image

// Code generated by protoc-gen-grpc-federation. DO NOT EDIT!
package gen

import (
	"context"
	"fmt"
	"io"
	"log/slog"
	"runtime/debug"

	"github.com/google/cel-go/cel"
	celtypes "github.com/google/cel-go/common/types"
	grpcfed "github.com/mercari/grpc-federation/grpc/federation"
	grpcfedcel "github.com/mercari/grpc-federation/grpc/federation/cel"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/trace"
	grpccodes "google.golang.org/grpc/codes"
	grpcstatus "google.golang.org/grpc/status"
)

// Federation_GetPostResponseArgument is argument for "federation.GetPostResponse" message.
type Federation_GetPostResponseArgument[T any] struct {
	Id     string
	Client T
}

// FederationServiceConfig configuration required to initialize the service that use GRPC Federation.
type FederationServiceConfig struct {
	// Resolver provides an interface to directly implement message resolver and field resolver not defined in Protocol Buffers.
	// If this interface is not provided, an error is returned during initialization.
	Resolver FederationServiceResolver // required
	// ErrorHandler Federation Service often needs to convert errors received from downstream services.
	// If an error occurs during method execution in the Federation Service, this error handler is called and the returned error is treated as a final error.
	ErrorHandler grpcfed.ErrorHandler
	// Logger sets the logger used to output Debug/Info/Error information.
	Logger *slog.Logger
}
[...]

20 changes: 20 additions & 0 deletions tests/testdata/images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,23 @@ The content must first be manually pushed to the local BSR instance from the grp
the host, logging into the registry, updating then pushing the module.

The BSR-hosted version of the repository is annotations only and does not produce valuable test output.

### grpc-federation.bin.gz

This is a sample image built from
https://github.com/mercari/grpc-federation/blob/v0.9.2/_examples/01_minimum/proto/federation/federation.proto,
and has a dependency on https://buf.build/mercari/grpc-federation.

Pull this file, add a buf.yaml file (`buf mod init`), then add this dependency and run `buf mod
update`:

```
deps:
- buf.build/mercari/grpc-federation
```

Build and commit the resulting image into tests/testdata/images:

```
buf build federation.proto -o grpc-federation.bin.gz
```
Binary file added tests/testdata/images/grpc-federation.bin.gz
Binary file not shown.
Loading