Skip to content

Commit da7a33f

Browse files
committed
proto: Add support for Process.User's Any
To avoid: go run ./example.go go/config.pb.go:26:8: cannot find package "google/protobuf" in any of: /usr/lib/go/src/google/protobuf (from $GOROOT) /home/wking/.local/lib/go/src/google/protobuf (from $GOPATH) Makefile:31: recipe for target 'example' failed The Dockerfile changes will compile Google's any.proto to Go and install it in the GOPATH. Unfortunately, the jsonpb rendering isn't quite right, since it's spitting out: "user": { "type_url": "oci.LinuxUser", "value": "qAYBsAYBuAYFuAYG" }, When it should be spitting out [1]: "user": { "@type": "type.googleapis.com/oci.LinuxUser", "uid": 1, "gid": 1, "additionalGids": [ 5, 6 ] }, [1]: https://developers.google.com/protocol-buffers/docs/proto3#json Signed-off-by: W. Trevor King <[email protected]>
1 parent 459cecb commit da7a33f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

proto/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ RUN dnf install -y golang git hg bzr
1313
ENV GOPATH /gopath
1414
ENV GOBIN /usr/bin
1515
RUN go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
16+
WORKDIR protobuf-${PROTO_VERSION}
17+
RUN protoc --go_out=${GOPATH} src/google/protobuf/any.proto
18+
WORKDIR /
1619
VOLUME /proto /output
1720
CMD bash /proto/run.sh

proto/example.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
oci "./go/"
1010
"github.com/golang/protobuf/jsonpb"
11+
"github.com/golang/protobuf/proto"
12+
google_protobuf "google/protobuf"
1113
)
1214

1315
func main() {
@@ -21,12 +23,22 @@ func main() {
2123
},
2224
}
2325

26+
user := &oci.LinuxUser{Uid: 1, Gid: 1, AdditionalGids: []int32{5, 6}}
27+
userBytes, err := proto.Marshal(user)
28+
if err != nil {
29+
log.Fatal(err)
30+
}
31+
s.Spec.Process.User = &google_protobuf.Any{
32+
TypeUrl: "oci.LinuxUser",
33+
Value: userBytes,
34+
}
35+
2436
marshaler := jsonpb.Marshaler{
2537
EnumsAsString: true,
2638
Indent: " ",
2739
}
2840

29-
err := marshaler.Marshal(os.Stdout, s)
41+
err = marshaler.Marshal(os.Stdout, s)
3042
if err != nil {
3143
log.Fatal(err)
3244
}

0 commit comments

Comments
 (0)