microcks: Importer throws error when .proto dependency is not in current or sub-directory of imported .proto
Our organization uses a central repo that contains a large number of different libraries, which includes proto definitions for all our services (hundreds). However, there are also a number of separate proto definitions that are imported to the service definitions, that are stored in a wholly separate directory structure. I created an example repo that hopefully illustrates the problem. The directory structure looks like this:
> org
> shared
> lib
> grpcproto
> uuid.proto
> services
> auth
> authv2.proto
I created a sample repo to test with, which can be found here: https://github.com/molteninjabob/org.
In this example, authv2.proto imports uuid.proto from a completely separate branch in the org directory structure. I can create the importer successfully, but the import throws the following error:
microcks | protoc-jar: executing: [/tmp/protocjar8444733488152786468/bin/protoc.exe, -I/tmp/protocjar8444733488152786468/include, --include_imports, --proto_path=/tmp, --descriptor_set_out=/tmp/microcks-162613201891814477613584668397839.download.pbb, microcks-162613201891814477613584668397839.download]
microcks | org/shared/lib/grpcproto/uuid.proto: File not found.
microcks | microcks-162613201891814477613584668397839.download:6:1: Import "org/shared/lib/grpcproto/uuid.proto" was not found or had errors.
Attaching stack trace. stack.txt
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 20 (12 by maintainers)
Again, for reference, here’s how I am doing it with TestContainers. It’s not beautiful, but it for sure works.
With TestContainers it easier to copy files to the container than it is with docker-compose.
Notice that I have to code a workaround when the proto file is inside a jar file inside the classpath, because
importAsMainArtifact()accepts only java.io.File as input.Hi @lbroudoux,
I would like to add some feedback on this issue as we’re also using gRPC for many years with different languages and having same issue.
Most of our protos include internal but also “external” protos (like Google protos). In all cases, all include path starts from root path of our protos (recommended). For Google protos, we add an include path to our protoc command to find these protos. All our protos are prefixed by a root directory with company name, like google.
Maybe I missed something in Microcks, but it looks like tool can only import one file at a time. However, in order to have a successful import for gRPC protos, we need to have many files available during import (the ones which are included). This is true for all gRPC tools we use.
So, if I currently run an import Job on a specific file including my service, it will fail with things like this because these files are not available during the import process.
Ideally, what we would need is an Import Job of a file through a whole directory context (a git repository would be perfect). In others words, I think it would solve the issue if we could create an Import Job with a Git Repository including all our protos but also another field to specify path to the file with service we want to import.
It doesn’t solve issue for external protos like Google. Maybe external dependency in the import job with a git repository could be a solution too. (Need more investigation)
Currently, we found a workaround (a hack). As command you run with protoc has arg
--proto_path=/tmp, we mount in container in /tmp/xxxx our protos so our include pattern is working and we can finally import our protos.However, it would be great if gRPC protos import could support this pattern. If you want a really complex Protos repository, you can check the one from Google : https://github.com/googleapis/googleapis I believe it’s a good way to test future feature to import protos is working 😃
Feel free to contact me if you want to discuss more about gRPC
@lbroudoux
In order to easily test and reproduce to problem i have created a branch (
import) on this repo : https://github.com/hersentino/microcks-issue/blob/import/README.mdI also propose a solution with
include_dir/proto_pathoptionYes, accepting an URI would be nice. Just be aware that the URI is a file inside a jar, something like
jar:file:<path to the jar in the classpath>/consumer-wallet-protobuf-0.20.0.jar!/consumer_wallet_service.proto. An alternative would be to accept the content of the file as a byte array, in the same lines of TestContainerswithCopyToContainer().I will write a blog post in my company’s Medium, then I share it with you so you can reference it you microcks.io if you like.
Thank you, mate!
This is awesome! Nice concrete usage of the Testcontainer module! To ease your life, maybe we could add an
importAsMainArtifact()method that takes URI as a parameter?By the way, have you ever considered sharing this through tech-writing? I believe your insights could be valuable to a wider audience. Perhaps a blog post explaining this solution could be a great start. BTW we host external contributors blog post on microcks.io 😉
I am putting the
keep-openlabel as I really want to sort this out and see what can be improved. I’ll take time reading the above comments 😉For reference, here is dirty hack if one wants to import multiple services in the same instance.
Mounting the protos in the
/tmpfolder works indeed. The only issue is that microcks creates files in this folder, so I have to add them to.gitignore. The proto definitions I have are not following the best practices, but they for sure work. It would be very time consuming to alter all of them just so they would work with microcks.From your example, the import uses an URL. This would be complicated to implement in my situation, because the protos are available either in a private git repository, or in jar files in a maven repository. Currently, the best option by far is to mount a volume, but it would be wonderful to be able to do it using the importer, because it would fit better with TestContainers’ DSL.
Below I share my some details of my project just so you have an idea of how I am dealing with this issue.
The docker-compose.yaml
Thank you for the project either way. It’s helping me a bunch!
@lbroudoux No worries and sorry it took a bit to get back. I’ll keep playing around with things. I really love what you’re doing and we want to use microcks as our main tool for mocking endpoints. You’re doing great things!