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

proto: Port *.proto to proto3 #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions proto/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ RUN dnf install -y golang git hg bzr
ENV GOPATH /gopath
ENV GOBIN /usr/bin
RUN go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
WORKDIR protobuf-${PROTO_VERSION}
RUN protoc --go_out=${GOPATH} src/google/protobuf/any.proto
WORKDIR /
VOLUME /proto /output
CMD bash /proto/run.sh
57 changes: 23 additions & 34 deletions proto/config.proto
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
syntax = "proto3";

package oci;

import "google/protobuf/any.proto";

// Spec is the base configuration for the container. It specifies platform
// independent configuration.
message Spec {
// Version is the version of the specification that is supported.
optional string version = 1;
string version = 1;
// Platform is the host information for OS and Arch.
optional Platform platform = 2;
Platform platform = 2;
// Process is the container's main process.
optional Process process = 3;
Process process = 3;
// Root is the root information for the container's filesystem.
optional Root root = 4;
Root root = 4;
// Hostname is the container's host name.
optional string hostname = 5;
string hostname = 5;
// Mounts profile configuration for adding mounts to the container's
// filesystem.
repeated MountPoint mounts = 6;
Copy link

Choose a reason for hiding this comment

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

I'm not sure if google is moving away from this, but the general protobuf standard has been to not use plural names for repeated fields, so this would be mount or mount_point.

Expand All @@ -21,10 +25,10 @@ message Spec {

// LinuxSpec is the full specification for linux containers.
message LinuxSpec {
optional Spec spec = 1;
Spec spec = 1;
// LinuxConfig is platform specific configuration for linux based
// containers.
optional LinuxConfig linux_config = 2;
LinuxConfig linux_config = 2;
}

// LinuxConfig contains platform specific configuration for linux based
Expand All @@ -38,69 +42,54 @@ message LinuxConfig {
// container is created for.
message Platform {
// OS is the operating system.
optional string os = 1;
string os = 1;
Copy link

Choose a reason for hiding this comment

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

since this is pretty static, and validation would be nice, it might be worth considering an enum:

enum OS {
  OS_NONE = 0; // I always have a zero value to denote the field not being set, proto3 requires a zero value.
  OS_DARWIN = 1;
  ...
}

enum Arch {
  ARCH_NONE = 0; // also note proto uses c++ enum name rules, so my general practice is to preface any enum names with the type name to avoid future issues.
 ...
}

// Arch is the architecture
optional string arch = 2;
string arch = 2;
}

// Process contains information to start a specific application inside the
// container.
message Process {
// Terminal creates an interactive terminal for the container.
optional bool terminal = 1;
bool terminal = 1;
// User specifies user information for the process.
optional User user = 2;
google.protobuf.Any user = 2;
// Args specifies the binary and arguments for the application to
// execute.
repeated string args = 3;
Copy link

Choose a reason for hiding this comment

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

same comment, arg

// Env populates the process environment for the process.
repeated string env = 4;
// Cwd is the current working directory for the process and must be
// relative to the container's root.
optional string cwd = 5;
}

enum PlatformType {
UNKNOWN = 0;
LINUX = 1;
}

// User specifies user information for the process.
message User {
// Type so that receivers of this message can `switch` for the fields
// expected
optional PlatformType type = 1;

//optional LinuxUser linux_type = 2;
extensions 100 to 499;
string cwd = 5;
}

// LinuxUser specifies linux specific user and group information for the
// container's main process.
extend User {
message LinuxUser {
// Uid is the user id.
optional int32 uid = 101;
int32 uid = 101;
// Gid is the group id.
optional int32 gid = 102;
int32 gid = 102;
repeated int32 additional_gids = 103;
}

// Root contains information about the container's root filesystem on the host.
message Root {
// Path is the absolute path to the container's root filesystem.
optional string path = 1;
string path = 1;
// Readonly makes the root filesystem for the container readonly before
// the process is executed.
optional bool readonly = 2;
bool readonly = 2;
Copy link

Choose a reason for hiding this comment

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

might want to consider enum FileMode, but that may be getting silly

}

// MountPoint describes a directory that may be fullfilled by a mount in the
// runtime.json.
message MountPoint {
// Name is a unique descriptive identifier for this mount point.
optional string name = 1;
string name = 1;
// Path specifies the path of the mount. The path and child directories
// MUST exist, a runtime MUST NOT create directories automatically to a
// mount point.
optional string path = 2;
string path = 2;
}
27 changes: 21 additions & 6 deletions proto/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,42 @@
package main

import (
"encoding/json"
"log"
"os"

oci "./go/"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
google_protobuf "google/protobuf"
)

func main() {
s := oci.LinuxSpec{
s := &oci.LinuxSpec{
Spec: &oci.Spec{
Platform: &oci.Platform{Os: proto.String("linux"), Arch: proto.String("x86_64")},
Platform: &oci.Platform{Os: "linux", Arch: "x86_64"},
Process: &oci.Process{
Cwd: proto.String("/"),
Cwd: "/",
Env: []string{"TERM=linux"},
},
},
}

buf, err := json.MarshalIndent(s, "", " ")
user := &oci.LinuxUser{Uid: 1, Gid: 1, AdditionalGids: []int32{5, 6}}
userBytes, err := proto.Marshal(user)
if err != nil {
log.Fatal(err)
}
s.Spec.Process.User = &google_protobuf.Any{
TypeUrl: "oci.LinuxUser",
Value: userBytes,
}

marshaler := jsonpb.Marshaler{
Indent: " ",
}

err = marshaler.Marshal(os.Stdout, s)
if err != nil {
log.Fatal(err)
}
println(string(buf))
}
Loading