From 44b4415b169efd439f424495bf42fb6a4a82549f Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Fri, 4 Sep 2015 23:47:13 +0800 Subject: [PATCH 1/2] change the user of the Process to a json.RawMessage The type of `user` becomes `json.RawMessage` instead of platform aware structure, so the Spec becomes a platform-independent structure. It makes we can parse the config.json as a Spec before knowing the os, and allows we move the linux related *.go to linux/. The runtime should parse the user with the corresponding platform specific User structure. Signed-off-by: Lai Jiangshan --- config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 269e0cbe5..19f423e2b 100644 --- a/config.go +++ b/config.go @@ -1,5 +1,9 @@ package specs +import ( + "encoding/json" +) + // Spec is the base configuration for the container. It specifies platform // independent configuration. type Spec struct { @@ -21,8 +25,8 @@ type Spec struct { type Process struct { // Terminal creates an interactive terminal for the container. Terminal bool `json:"terminal"` - // User specifies user information for the process. - User User `json:"user"` + // User specifies user information for the process. It is a platform-specific structure. + User json.RawMessage `json:"user"` // Args specifies the binary and arguments for the application to execute. Args []string `json:"args"` // Env populates the process environment for the process. From e3028f52caa05d9dd17c1a4dea11426d9498720d Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Thu, 10 Sep 2015 00:16:45 +0800 Subject: [PATCH 2/2] Enable parsing the OCI linux configuration on non-linux platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What does this patch do? * Make the LinuxSpec be visible by golang on non-linux platforms when “go build” What did this patch change? * Add linux/ * Rename config_linux.go to linux/config.go * Rename config-linux.md to linux/config.md * Rename runtime_config_linux.go to linux/runtime-config.go * Rename runtime-config-linux.md to linux/runtime-config.md * Rename runtime-linux.md -> linux/runtime.md * Remove the “// +build linux” from linux/config.go * The package name of linux/*.go is changed to “linux” * Add import of the “specs” in the linux/*.go The type LinuxSpec (or say the OCI linux configuration) is a structure describing some information, there is no executable code bound to the linux, so the LinuxSpec should be naturally usable by any platform when needed. But the file names (ended with “_linux.go”) and the build tag disallow us to do so. The patch changes it. Removing the “_linux” and the build tag makes `go build` accept the LinuxSpec on any platform. The linux related files are also moved to the linux/ to eliminate the future possible name clashing (include the file names and the type names). After making the LinuxSpec be visible on non-linux platforms, anyone can do anything of the following in any platforms. (They are also the useful usecases) * 1) parse the OCI linux configuration (config.json & runtime.json) * 2) verify the OCI linux configuration or the bundle * 3) check or test the OCI linux configuration or even the bundle * 4) discover/build/deliver linux OCI bundle * 5) Run the container via the hypervisor-based runtime on non-linux platforms * etc.) The 5) is one thing of what we are focusing on. After this patch applied, anyone can build the runv[1] and run linux container on darwin. (Also after we update the opencontainers/spec under Godeps/ in our runv.git[1] project.) [1]: https://github.com/hyperhq/runv Signed-off-by: Lai Jiangshan --- config_linux.go => linux/config.go | 8 +++++--- config-linux.md => linux/config.md | 0 runtime_config_linux.go => linux/runtime-config.go | 10 +++++++--- runtime-config-linux.md => linux/runtime-config.md | 0 runtime-linux.md => linux/runtime.md | 0 5 files changed, 12 insertions(+), 6 deletions(-) rename config_linux.go => linux/config.go (92%) rename config-linux.md => linux/config.md (100%) rename runtime_config_linux.go => linux/runtime-config.go (98%) rename runtime-config-linux.md => linux/runtime-config.md (100%) rename runtime-linux.md => linux/runtime.md (100%) diff --git a/config_linux.go b/linux/config.go similarity index 92% rename from config_linux.go rename to linux/config.go index 4bfb78325..5338d7c9a 100644 --- a/config_linux.go +++ b/linux/config.go @@ -1,10 +1,12 @@ -// +build linux +package linux -package specs +import ( + "github.com/opencontainers/specs" +) // LinuxSpec is the full specification for linux containers. type LinuxSpec struct { - Spec + specs.Spec // Linux is platform specific configuration for linux based containers. Linux Linux `json:"linux"` } diff --git a/config-linux.md b/linux/config.md similarity index 100% rename from config-linux.md rename to linux/config.md diff --git a/runtime_config_linux.go b/linux/runtime-config.go similarity index 98% rename from runtime_config_linux.go rename to linux/runtime-config.go index 7ddffdd03..450338546 100644 --- a/runtime_config_linux.go +++ b/linux/runtime-config.go @@ -1,13 +1,17 @@ -package specs +package linux -import "os" +import ( + "os" + + "github.com/opencontainers/specs" +) // LinuxStateDirectory holds the container's state information const LinuxStateDirectory = "/run/opencontainer/containers" // LinuxRuntimeSpec is the full specification for linux containers. type LinuxRuntimeSpec struct { - RuntimeSpec + specs.RuntimeSpec // LinuxRuntime is platform specific configuration for linux based containers. Linux LinuxRuntime `json:"linux"` } diff --git a/runtime-config-linux.md b/linux/runtime-config.md similarity index 100% rename from runtime-config-linux.md rename to linux/runtime-config.md diff --git a/runtime-linux.md b/linux/runtime.md similarity index 100% rename from runtime-linux.md rename to linux/runtime.md