init repo

Signed-off-by: jingrui <jingrui@huawei.com>
This commit is contained in:
jingrui 2020-08-15 21:11:12 +08:00
commit b5971d5afb
15 changed files with 1377 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/rustime
target
*.so
*.wasm

405
Cargo.lock generated Normal file
View File

@ -0,0 +1,405 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hermit-abi 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.33.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cmd"
version = "0.1.0"
dependencies = [
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prctl 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"runtime 0.1.0",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syslog 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "error-chain"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hermit-abi"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nix"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "prctl"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-error"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-error-attr 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
"syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro2"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "runtime"
version = "0.1.0"
dependencies = [
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prctl 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syslog 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "structopt"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "structopt-derive"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn-mid"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syslog"
version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"error-chain 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thiserror"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"thiserror-impl 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thiserror-impl"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum cc 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)" = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
"checksum error-chain 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d371106cc88ffdfb1eabd7111e432da544f16f3e2d7bf1dfe8bf575f1df045cd"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum hermit-abi 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
"checksum itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)" = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9"
"checksum log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
"checksum nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363"
"checksum prctl 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "059a34f111a9dee2ce1ac2826a68b24601c4298cfeb1a587c3cb493d5ab46f52"
"checksum proc-macro-error 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fc175e9777c3116627248584e8f8b3e2987405cabe1c0adf7d1dd28f09dc7880"
"checksum proc-macro-error-attr 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3cc9795ca17eb581285ec44936da7fc2335a3f34f2ddd13118b6f4d515435c50"
"checksum proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
"checksum ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
"checksum serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
"checksum serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
"checksum serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)" = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum structopt 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "de2f5e239ee807089b62adce73e48c625e0ed80df02c7ab3f068f5db5281065c"
"checksum structopt-derive 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "510413f9de616762a4fbeab62509bf15c729603b72d7cd71280fbca431b1c118"
"checksum syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b"
"checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
"checksum syslog 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9a5d8ef1b679c07976f3ee336a436453760c470f54b5e7237556728b8589515d"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thiserror 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
"checksum thiserror-impl 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
"checksum unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
"checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

30
Cargo.toml Normal file
View File

@ -0,0 +1,30 @@
[package]
name = "runtime"
version = "0.1.0"
authors = ["caihaomin <caihaomin@huawei.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "runtime"
[dependencies]
thiserror = "1.0"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
log = "0.4"
syslog = "5.0"
structopt = "0.3.15"
nix = "0.17.0"
libc = "0.2"
prctl = "1.0.0"
[workspace]
members = [
"cmd",
]
default-members = ["cmd"]

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# 说明
目前容器运行时以OCI runtime spec为标准runc是该标准下应用最为广泛的运行时之一。
runc基于golang实现由于golang自带语言运行时开销为了进一步减少容器运行时的额
外开销提升容器启动性能本仓库基于rust编程语言实现OCI运行时命令行接口兼容
OCI规范。

24
cmd/Cargo.toml Normal file
View File

@ -0,0 +1,24 @@
[package]
name = "cmd"
version = "0.1.0"
authors = ["caihaomin <caihaomin@huawei.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "rustime"
path = "src/bin/rustime.rs"
[dependencies]
runtime = {path = "../"}
thiserror = "1.0"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
log = "0.4"
syslog = "5.0"
structopt = "0.3.15"
nix = "0.17.0"
libc = "0.2"
prctl = "1.0.0"

21
cmd/src/bin/rustime.rs Normal file
View File

@ -0,0 +1,21 @@
use std::fs;
use log::info;
use runtime::{commands, errors::Error, logger};
const RUN_PATH: &str = "/var/run/rustime";
fn main() -> Result<(), Error> {
let opt = commands::Opt::new();
logger::log_init(&opt.log.as_str())?;
info!("main {:?}", opt.cmd);
fs::create_dir_all(RUN_PATH)?;
if let Err(e) = commands::handle(&opt) {
info!("handle failed {:?}", e);
println!("failed: {:?}", e);
}
Ok(())
}

139
src/commands/commands.rs Normal file
View File

@ -0,0 +1,139 @@
use structopt::StructOpt;
use crate::errors::Error;
use crate::spec;
#[derive(StructOpt, Debug)]
#[structopt(name = "rustime", about = "container runtime by rust")]
pub struct Opt {
/// debug mode
#[structopt(long)]
pub debug: bool,
/// log file
#[structopt(long, default_value = "/dev/null")]
pub log: String,
/// log format
#[structopt(long, default_value = "text")]
pub log_format: String,
/// log level
#[structopt(long, default_value = "info")]
pub log_level: String,
/// root path
#[structopt(long, default_value = "/run/rustime")]
pub root: String,
/// subcommand
#[structopt(subcommand)]
pub cmd: Commands,
}
impl Opt {
pub fn new() -> Opt {
Opt::from_args()
}
}
#[derive(StructOpt, Debug)]
#[structopt(about = "container runtime by rust")]
pub enum Commands {
/// create container instance
#[structopt(name = "create")]
Create(CreateArgs),
/// init process
#[structopt(name = "init")]
Init(InitArgs),
/// start container instance
#[structopt(name = "start")]
Start(StartArgs),
/// delete container instance
#[structopt(name = "delete")]
Delete(DeleteArgs),
/// state container instance
#[structopt(name = "state")]
State(StateArgs),
}
#[derive(StructOpt, Debug)]
pub struct CreateArgs {
/// bundle path
#[structopt(short, long, default_value = ".")]
pub bundle: String,
/// file to write pid
#[structopt(long, default_value = "")]
pub pid_file: String,
/// console socket
#[structopt(long, default_value = "")]
pub console_socket: String,
#[structopt()]
pub id: String,
}
#[derive(StructOpt, Debug)]
pub struct InitArgs {
#[structopt()]
pub id: String,
}
#[derive(StructOpt, Debug)]
pub struct StartArgs {
#[structopt()]
pub id: String,
}
#[derive(StructOpt, Debug)]
pub struct DeleteArgs {
#[structopt(short, long)]
pub force: bool,
#[structopt()]
pub id: String,
}
#[derive(StructOpt, Debug)]
pub struct StateArgs {
#[structopt()]
pub id: String,
}
pub fn handle(opt: &Opt) -> Result<(), Error> {
match &opt.cmd {
Commands::Create(args) => return do_create(opt, args),
Commands::Init(args) => return do_init(opt, args),
Commands::Start(args) => return do_start(opt, args),
Commands::State(args) => return do_state(opt, args),
Commands::Delete(args) => return do_delete(opt, args),
};
}
pub fn do_create(_opt: &Opt, args: &CreateArgs) -> Result<(), Error> {
let fcfg = [&args.bundle, "config.json"].join("/");
let _spec = spec::load_spec(&fcfg)?;
Ok(())
}
pub fn do_init(_opt: &Opt, _args: &InitArgs) -> Result<(), Error> {
Ok(())
}
pub fn do_start(_opt: &Opt, _args: &StartArgs) -> Result<(), Error> {
Ok(())
}
fn do_state(_opt: &Opt, _args: &StateArgs) -> Result<(), Error> {
Ok(())
}
fn do_delete(_opt: &Opt, _args: &DeleteArgs) -> Result<(), Error> {
Ok(())
}

4
src/commands/mod.rs Normal file
View File

@ -0,0 +1,4 @@
pub mod commands;
pub use self::commands::handle;
pub use self::commands::Opt;

33
src/errors.rs Normal file
View File

@ -0,0 +1,33 @@
extern crate nix;
use log;
use std;
use thiserror::Error;
/// rustime errors.
#[derive(Debug, Error)]
pub enum Error {
#[error("Invalid argument: {0}")]
InvalidArgument(&'static str),
#[error("set logger error: {0}")]
SetLoggerError(#[from] log::SetLoggerError),
#[error("nix error: {0}")]
NixError(#[from] nix::Error),
#[error("io error: {0}")]
IOError(#[from] std::io::Error),
#[error("json error: {0}")]
JsonError(#[from] serde_json::error::Error),
#[error("ffi error: {0}")]
NulError(#[from] std::ffi::NulError),
#[error("parse int error: {0}")]
ParseIntError(#[from] std::num::ParseIntError),
#[error("Unsupported feature: {0}")]
Unsupported(String),
}

7
src/lib.rs Normal file
View File

@ -0,0 +1,7 @@
#[macro_use]
extern crate serde_derive;
pub mod commands;
pub mod errors;
pub mod logger;
pub mod spec;

21
src/logger.rs Normal file
View File

@ -0,0 +1,21 @@
use crate::errors::Error;
use log;
use syslog;
pub fn log_init(level: &str) -> Result<(), Error> {
let log_level = match level {
"debug" => log::LevelFilter::Info,
_ => log::LevelFilter::Info,
};
let formatter = syslog::Formatter3164 {
facility: syslog::Facility::LOG_USER,
hostname: None,
process: "rustime".into(),
pid: 0,
};
let logger = syslog::unix(formatter).expect("could not connect to syslog");
log::set_boxed_logger(Box::new(syslog::BasicLogger::new(logger)))
.map(|()| log::set_max_level(log_level))?;
Ok(())
}

3
src/runtime/mod.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod runtime;
pub use self::runtime::Runtime;

28
src/runtime/runtime.rs Normal file
View File

@ -0,0 +1,28 @@
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
#[derive(Debug, Serialize, Deserialize)]
pub struct Runtime {
pub cid: String,
pub workdir: String,
pub rootfs: String,
pub pid: String,
pub pid_file: String,
pub config: String,
}
impl Runtime {
pub fn new(cid: &str, workdir: &str, rootfs: &str) -> Result<Runtime, Error> {
Rustime::mkdir(cid);
Ok(Runtime {
cid: cid.to_string(),
workdir: workdir.to_string(),
rootfs: rootfs.to_string(),
pid: String::new(),
pid_file: String::new(),
config: String::new(),
})
}
}

2
src/spec/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod spec;
pub use self::spec::load_spec;

650
src/spec/spec.rs Normal file
View File

@ -0,0 +1,650 @@
#![allow(non_camel_case_types)]
use nix::unistd::Pid;
use std::collections::HashMap;
use std::fs::File;
use crate::errors::Error;
use serde_json::Value;
const OCI_VERSION: &str = "1.0.1";
fn is_false(b: &bool) -> bool {
!b
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Platform {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub os: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub arch: String,
}
#[derive(Default, PartialEq, Serialize, Deserialize, Debug)]
pub struct Box {
#[serde(default)]
pub height: u64,
#[serde(default)]
pub width: u64,
}
fn is_default<T: Default + PartialEq>(b: &T) -> bool {
*b == T::default()
}
#[derive(Serialize, Deserialize, Debug)]
pub struct User {
#[serde(default)]
pub uid: u32,
#[serde(default)]
pub gid: u32,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "additionalGids"
)]
pub additional_gids: Vec<u32>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub username: String,
}
// this converts directly to the correct int
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub enum LinuxRlimitType {
RLIMIT_CPU, // CPU time in sec
RLIMIT_FSIZE, // Maximum filesize
RLIMIT_DATA, // max data size
RLIMIT_STACK, // max stack size
RLIMIT_CORE, // max core file size
RLIMIT_RSS, // max resident set size
RLIMIT_NPROC, // max number of processes
RLIMIT_NOFILE, // max number of open files
RLIMIT_MEMLOCK, // max locked-in-memory address space
RLIMIT_AS, // address space limit
RLIMIT_LOCKS, // maximum file locks held
RLIMIT_SIGPENDING, // max number of pending signals
RLIMIT_MSGQUEUE, // maximum bytes in POSIX mqueues
RLIMIT_NICE, // max nice prio allowed to raise to
RLIMIT_RTPRIO, // maximum realtime priority
RLIMIT_RTTIME, // timeout for RT tasks in us
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxRlimit {
#[serde(rename = "type")]
pub typ: LinuxRlimitType,
#[serde(default)]
pub hard: u64,
#[serde(default)]
pub soft: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
#[repr(u8)]
pub enum LinuxCapabilityType {
CAP_CHOWN,
CAP_DAC_OVERRIDE,
CAP_DAC_READ_SEARCH,
CAP_FOWNER,
CAP_FSETID,
CAP_KILL,
CAP_SETGID,
CAP_SETUID,
CAP_SETPCAP,
CAP_LINUX_IMMUTABLE,
CAP_NET_BIND_SERVICE,
CAP_NET_BROADCAST,
CAP_NET_ADMIN,
CAP_NET_RAW,
CAP_IPC_LOCK,
CAP_IPC_OWNER,
CAP_SYS_MODULE,
CAP_SYS_RAWIO,
CAP_SYS_CHROOT,
CAP_SYS_PTRACE,
CAP_SYS_PACCT,
CAP_SYS_ADMIN,
CAP_SYS_BOOT,
CAP_SYS_NICE,
CAP_SYS_RESOURCE,
CAP_SYS_TIME,
CAP_SYS_TTY_CONFIG,
CAP_MKNOD,
CAP_LEASE,
CAP_AUDIT_WRITE,
CAP_AUDIT_CONTROL,
CAP_SETFCAP,
CAP_MAC_OVERRIDE,
CAP_MAC_ADMIN,
CAP_SYSLOG,
CAP_WAKE_ALARM,
CAP_BLOCK_SUSPEND,
CAP_AUDIT_READ,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxCapabilities {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub bounding: Vec<LinuxCapabilityType>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub effective: Vec<LinuxCapabilityType>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub inheritable: Vec<LinuxCapabilityType>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub permitted: Vec<LinuxCapabilityType>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub ambient: Vec<LinuxCapabilityType>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Process {
#[serde(default, skip_serializing_if = "is_false")]
pub terminal: bool,
#[serde(default, skip_serializing_if = "is_default", rename = "consoleSize")]
pub console_size: Box,
pub user: User,
pub args: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub env: Vec<String>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub cwd: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub capabilities: Option<LinuxCapabilities>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub rlimits: Vec<LinuxRlimit>,
#[serde(default, skip_serializing_if = "is_false", rename = "noNewPrivileges")]
pub no_new_privileges: bool,
#[serde(
default,
skip_serializing_if = "String::is_empty",
rename = "apparmorProfile"
)]
pub apparmor_profile: String,
#[serde(
default,
skip_serializing_if = "String::is_empty",
rename = "selinuxLabel"
)]
pub selinux_label: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Root {
#[serde(default)]
pub path: String,
#[serde(default, skip_serializing_if = "is_false")]
pub readonly: bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Mount {
#[serde(default)]
pub destination: String,
#[serde(default, skip_serializing_if = "String::is_empty", rename = "type")]
pub typ: String,
#[serde(default)]
pub source: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub options: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Hook {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub path: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub args: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub env: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<i64>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Hooks {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub prestart: Vec<Hook>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub poststart: Vec<Hook>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub poststop: Vec<Hook>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LinuxIDMapping {
#[serde(default, rename = "hostID")]
pub host_id: u32,
#[serde(default, rename = "containerID")]
pub container_id: u32,
#[serde(default)]
pub size: u32,
}
// a is for LinuxDeviceCgroup
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub enum LinuxDeviceType {
b,
c,
u,
p,
a,
}
impl Default for LinuxDeviceType {
fn default() -> LinuxDeviceType {
LinuxDeviceType::a
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxDeviceCgroup {
#[serde(default, skip_serializing_if = "is_false")]
pub allow: bool,
#[serde(default, rename = "type")]
pub typ: LinuxDeviceType,
#[serde(skip_serializing_if = "Option::is_none")]
pub major: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub minor: Option<i64>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub access: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxMemory {
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reservation: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub swap: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub kernel: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none", rename = "kernelTCP")]
pub kernel_tcp: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub swappiness: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxCPU {
#[serde(skip_serializing_if = "Option::is_none")]
pub shares: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quota: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub period: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none", rename = "realtimeRuntime")]
pub realtime_runtime: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none", rename = "realtimePeriod")]
pub realtime_period: Option<u64>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub cpus: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub mems: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxPids {
#[serde(default)]
pub limit: i64,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxWeightDevice {
#[serde(default)]
pub major: i64,
#[serde(default)]
pub minor: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub weight: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none", rename = "leafWeight")]
pub leaf_weight: Option<u16>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxThrottleDevice {
#[serde(default)]
pub major: i64,
#[serde(default)]
pub minor: i64,
#[serde(default)]
pub rate: u64,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxBlockIO {
#[serde(skip_serializing_if = "Option::is_none", rename = "blkioWeight")]
pub weight: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none", rename = "blkioLeafWeight")]
pub leaf_weight: Option<u16>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "blkioWeightDevice"
)]
pub weight_device: Vec<LinuxWeightDevice>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "blkioThrottleReadBpsDevice"
)]
pub throttle_read_bps_device: Vec<LinuxThrottleDevice>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "blkioThrottleWriteBpsDevice"
)]
pub throttle_write_bps_device: Vec<LinuxThrottleDevice>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "blkioThrottleReadIOPSDevice"
)]
pub throttle_read_iops_device: Vec<LinuxThrottleDevice>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "blkioThrottleWriteIOPSDevice"
)]
pub throttle_write_iops_device: Vec<LinuxThrottleDevice>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxHugepageLimit {
#[serde(default, skip_serializing_if = "String::is_empty", rename = "pageSize")]
pub page_size: String,
#[serde(default)]
pub limit: i64,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxInterfacePriority {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub name: String,
#[serde(default)]
pub priority: u32,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxNetwork {
#[serde(skip_serializing_if = "Option::is_none", rename = "classID")]
pub class_id: Option<u32>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub priorities: Vec<LinuxInterfacePriority>,
}
#[derive(Default, Serialize, Deserialize, Debug)]
pub struct LinuxResources {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub devices: Vec<LinuxDeviceCgroup>,
// NOTE: spec uses a pointer here, so perhaps this should be an Option, but
// false == unset so we don't bother.
#[serde(default, skip_serializing_if = "is_false", rename = "disableOOMKiller")]
pub disable_oom_killer: bool,
// NOTE: spec refers to this as an isize but the range is -1000 to 1000, so
// an i32 seems just fine
#[serde(skip_serializing_if = "Option::is_none", rename = "oomScoreAdj")]
pub oom_score_adj: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub memory: Option<LinuxMemory>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cpu: Option<LinuxCPU>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pids: Option<LinuxPids>,
#[serde(skip_serializing_if = "Option::is_none", rename = "blockIO")]
pub block_io: Option<LinuxBlockIO>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "hugepageLimits"
)]
pub hugepage_limits: Vec<LinuxHugepageLimit>,
#[serde(skip_serializing_if = "Option::is_none")]
pub network: Option<LinuxNetwork>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub enum LinuxNamespaceType {
mount = 0x00020000, /* New mount namespace group */
cgroup = 0x02000000, /* New cgroup namespace */
uts = 0x04000000, /* New utsname namespace */
ipc = 0x08000000, /* New ipc namespace */
user = 0x10000000, /* New user namespace */
pid = 0x20000000, /* New pid namespace */
network = 0x40000000, /* New network namespace */
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxNamespace {
#[serde(rename = "type")]
pub typ: LinuxNamespaceType,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub path: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxDevice {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub path: String,
#[serde(rename = "type")]
pub typ: LinuxDeviceType,
#[serde(default)]
pub major: u64,
#[serde(default)]
pub minor: u64,
#[serde(skip_serializing_if = "Option::is_none", rename = "fileMode")]
pub file_mode: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uid: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub gid: Option<u32>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
#[repr(u32)]
pub enum LinuxSeccompAction {
SCMP_ACT_KILL = 0x00000000,
SCMP_ACT_TRAP = 0x00030000,
SCMP_ACT_ERRNO = 0x00050001, /* ERRNO + EPERM */
SCMP_ACT_TRACE = 0x7ff00001, /* TRACE + EPERM */
SCMP_ACT_ALLOW = 0x7fff0000,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub enum Arch {
SCMP_ARCH_NATIVE = 0x00000000,
SCMP_ARCH_X86 = 0x40000003,
SCMP_ARCH_X86_64 = 0xc000003e,
SCMP_ARCH_X32 = 0x4000003e,
SCMP_ARCH_ARM = 0x40000028,
SCMP_ARCH_AARCH64 = 0xc00000b7,
SCMP_ARCH_MIPS = 0x00000008,
SCMP_ARCH_MIPS64 = 0x80000008,
SCMP_ARCH_MIPS64N32 = 0xa0000008,
SCMP_ARCH_MIPSEL = 0x40000008,
SCMP_ARCH_MIPSEL64 = 0xc0000008,
SCMP_ARCH_MIPSEL64N32 = 0xe0000008,
SCMP_ARCH_PPC = 0x00000014,
SCMP_ARCH_PPC64 = 0x80000015,
SCMP_ARCH_PPC64LE = 0xc0000015,
SCMP_ARCH_S390 = 0x00000016,
SCMP_ARCH_S390X = 0x80000016,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
#[repr(u32)]
pub enum LinuxSeccompOperator {
SCMP_CMP_NE = 1, /* not equal */
SCMP_CMP_LT = 2, /* less than */
SCMP_CMP_LE = 3, /* less than or equal */
SCMP_CMP_EQ = 4, /* equal */
SCMP_CMP_GE = 5, /* greater than or equal */
SCMP_CMP_GT = 6, /* greater than */
SCMP_CMP_MASKED_EQ = 7, /* masked equality */
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxSeccompArg {
#[serde(default)]
pub index: usize,
#[serde(default)]
pub value: u64,
#[serde(default, rename = "valueTwo")]
pub value_two: u64,
pub op: LinuxSeccompOperator,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxSyscall {
// old version used name
#[serde(default, skip_serializing_if = "String::is_empty")]
pub name: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub names: Vec<String>,
pub action: LinuxSeccompAction,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub args: Vec<LinuxSeccompArg>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LinuxSeccomp {
#[serde(rename = "defaultAction")]
pub default_action: LinuxSeccompAction,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub architectures: Vec<Arch>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub syscalls: Vec<LinuxSyscall>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Linux {
#[serde(default, skip_serializing_if = "Vec::is_empty", rename = "uidMappings")]
pub uid_mappings: Vec<LinuxIDMapping>,
#[serde(default, skip_serializing_if = "Vec::is_empty", rename = "gidMappings")]
pub gid_mappings: Vec<LinuxIDMapping>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub sysctl: HashMap<String, String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub resources: Option<LinuxResources>,
#[serde(
default,
skip_serializing_if = "String::is_empty",
rename = "cgroupsPath"
)]
pub cgroups_path: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub namespaces: Vec<LinuxNamespace>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub devices: Vec<LinuxDevice>,
#[serde(skip_serializing_if = "Option::is_none")]
pub seccomp: Option<LinuxSeccomp>,
#[serde(
default,
skip_serializing_if = "String::is_empty",
rename = "rootfsPropagation"
)]
pub rootfs_propagation: String,
#[serde(default, skip_serializing_if = "Vec::is_empty", rename = "maskedPaths")]
pub masked_paths: Vec<String>,
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
rename = "readonlyPaths"
)]
pub readonly_paths: Vec<String>,
#[serde(
default,
skip_serializing_if = "String::is_empty",
rename = "mountLabel"
)]
pub mount_label: String,
}
// NOTE: Solaris and Windows are ignored for the moment
pub type Solaris = Value;
pub type Windows = Value;
#[derive(Serialize, Deserialize, Debug)]
pub struct Spec {
#[serde(
default,
skip_serializing_if = "String::is_empty",
rename = "ociVersion"
)]
pub version: String,
// NOTE: Platform was removed, but keeping it as an option
// to support older docker versions
#[serde(skip_serializing_if = "Option::is_none")]
pub platform: Option<Platform>,
pub process: Process,
pub root: Root,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub hostname: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub mounts: Vec<Mount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hooks: Option<Hooks>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub annotations: HashMap<String, String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub linux: Option<Linux>,
#[serde(skip_serializing_if = "Option::is_none")]
pub solaris: Option<Solaris>,
#[serde(skip_serializing_if = "Option::is_none")]
pub windows: Option<Windows>,
}
impl Spec {
pub fn load(fname: &str) -> Result<Spec, Error> {
let file = File::open(fname)?;
Ok(serde_json::from_reader(&file)?)
}
pub fn save(&self, fname: &str) -> Result<(), Error> {
let mut file = File::create(fname)?;
Ok(serde_json::to_writer(&mut file, self)?)
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct State {
#[serde(
default,
skip_serializing_if = "String::is_empty",
rename = "ociVersion"
)]
pub version: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub id: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub status: String,
#[serde(default)]
pub pid: i32,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub bundle: String,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub annotations: HashMap<String, String>,
}
impl State {
pub fn to_string(&self) -> Result<String, Error> {
Ok(serde_json::to_string(self)?)
}
pub fn new(id: &str, status: &str, pid: Pid, bundle: &str) -> State {
State {
version: OCI_VERSION.to_string(),
id: id.to_string(),
status: status.to_string(),
pid: pid.into(),
bundle: bundle.to_string(),
annotations: HashMap::new(),
}
}
}
pub fn load_spec(fname: &str) -> Result<Spec, Error> {
let file = File::open(fname)?;
Ok(serde_json::from_reader(&file)?)
}