Skip to content
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
50 changes: 50 additions & 0 deletions proto/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

DESTDIR ?= .
PROTO_FILES := $(wildcard *.proto)
GO_DIR := $(DESTDIR)/go
GO_FILES := $(patsubst %.proto,$(GO_DIR)/%.pb.go,$(PROTO_FILES))
PY_DIR := $(DESTDIR)/py
PY_FILES := $(patsubst %.proto,$(PY_DIR)/%_pb2.py,$(PROTO_FILES))
C_DIR := $(DESTDIR)/c
C_SOURCE := $(patsubst %.proto,$(C_DIR)/%.pb-c.c,$(PROTO_FILES))
C_HDR := $(patsubst %.proto,$(C_DIR)/%.pb-c.h,$(PROTO_FILES))
C_FILES := $(C_SOURCE) $(C_HDR)
CPP_DIR := $(DESTDIR)/cpp
CPP_SOURCE := $(patsubst %.proto,$(CPP_DIR)/%.pb.cc,$(PROTO_FILES))
CPP_HDR := $(patsubst %.proto,$(CPP_DIR)/%.pb.h,$(PROTO_FILES))
CPP_FILES := $(CPP_SOURCE) $(CPP_HDR)

default: example

all: go py c cpp

go: $(GO_FILES)

$(GO_DIR)/%.pb.go: %.proto
@mkdir -p $(GO_DIR)
protoc --go_out=$(GO_DIR) $^

example: go
go run ./example.go

c: $(C_FILES)

$(C_DIR)/%.pb-c.c: %.proto
@mkdir -p $(C_DIR)
protoc-c --c_out=$(C_DIR) $^

cpp: $(CPP_FILES)

$(CPP_DIR)/%.pb.cc: %.proto
@mkdir -p $(CPP_DIR)
protoc --cpp_out=$(CPP_DIR)/ $^

py: $(PY_FILES)

$(PY_DIR)/%_pb2.py: %.proto
@mkdir -p $(PY_DIR)
protoc --python_out=$(PY_DIR) $^

clean:
rm -rf *~ $(GO_FILES) $(C_FILES) $(PY_FILES) $(CPP_FILES)

106 changes: 106 additions & 0 deletions proto/config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package oci;

// 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;
// Platform is the host information for OS and Arch.
optional Platform platform = 2;
// Process is the container's main process.
optional Process process = 3;
// Root is the root information for the container's filesystem.
optional Root root = 4;
// Hostname is the container's host name.
optional string hostname = 5;
// Mounts profile configuration for adding mounts to the container's
// filesystem.
repeated MountPoint mounts = 6;
}


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

// LinuxConfig contains platform specific configuration for linux based
// containers.
message LinuxConfig {
// Capabilities are linux capabilities that are kept for the container.
repeated string capabilities = 1;
}

// Platform specifies OS and arch information for the host system that the
// container is created for.
message Platform {
// OS is the operating system.
optional string os = 1;
// Arch is the architecture
optional 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;
// User specifies user information for the process.
optional User user = 2;
// Args specifies the binary and arguments for the application to
// execute.
repeated string args = 3;
// 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;
}

// LinuxUser specifies linux specific user and group information for the
// container's main process.
extend User {
// Uid is the user id.
optional int32 uid = 101;
// Gid is the group id.
optional 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;
// Readonly makes the root filesystem for the container readonly before
// the process is executed.
optional bool readonly = 2;
}

// 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;
// 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;
}
103 changes: 103 additions & 0 deletions proto/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// +build ignore

package main

import (
"encoding/hex"
"encoding/json"
"log"

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

func main() {
s := &oci.LinuxSpec{
Spec: &oci.Spec{
Version: proto.String("0.3.0"),
Hostname: proto.String("darkstar"),
Platform: &oci.Platform{Os: proto.String("linux"), Arch: proto.String("x86_64")},
Process: &oci.Process{
Terminal: proto.Bool(true),
User: &oci.User{},
Cwd: proto.String("/"),
Args: []string{"/bin/sh"},
Env: []string{"TERM=linux"},
},
Root: &oci.Root{
Path: proto.String("/"),
Readonly: proto.Bool(false),
},
Mounts: []*oci.MountPoint{
&oci.MountPoint{
Name: proto.String("proc"),
Path: proto.String("/proc"),
},
&oci.MountPoint{
Name: proto.String("dev"),
Path: proto.String("/dev"),
},
&oci.MountPoint{
Name: proto.String("devpts"),
Path: proto.String("/dev/pts"),
},
&oci.MountPoint{
Name: proto.String("shm"),
Path: proto.String("/dev/shm"),
},
&oci.MountPoint{
Name: proto.String("mqueue"),
Path: proto.String("/dev/mqueue"),
},
&oci.MountPoint{
Name: proto.String("sysfs"),
Path: proto.String("/sys"),
},
&oci.MountPoint{
Name: proto.String("cgroup"),
Path: proto.String("/sys/fs/cgroup"),
},
},
},
LinuxConfig: &oci.LinuxConfig{
Capabilities: []string{
"CAP_AUDIT_WRITE",
"CAP_KILL",
"CAP_NET_BIND_SERVICE",
},
},
}

//proto.SetExtension(s.Spec, oci.E_Uid, 0)

println("## Using github.com/golang/protobuf/jsonpb to marshal")
m := jsonpb.Marshaler{}
jsonStr, err := m.MarshalToString(s)
if err != nil {
log.Fatal(err)
}
println(jsonStr)
print("## len: ")
println(len(jsonStr))
println("")

println("## Using encoding/json to marshal")
buf, err := json.MarshalIndent(s, "", " ")
if err != nil {
log.Fatal(err)
}
println(string(buf))
print("## len: ")
println(len(buf))
println("")

println("## Marshaling to protobuf binary message")
data, err := proto.Marshal(s)
if err != nil {
log.Fatal(err)
}
println(hex.Dump(data))
print("## len: ")
println(len(data))
}
Loading