-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shimpei is an OCI shim wrapper around `oci-add-hooks`, whose sole porpuse is to call `oci-add-hooks` with additional parameters that can't be provided by containerd. Signed-off-by: Arnaldo Garcia Rincon <[email protected]>
- Loading branch information
1 parent
a9e29b9
commit b3c4509
Showing
9 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,9 @@ members = [ | |
|
||
"webpki-roots-shim", | ||
|
||
"constants" | ||
"constants", | ||
|
||
"shimpei" | ||
] | ||
|
||
[profile.release] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "shimpei" | ||
version = "0.1.0" | ||
authors = ["Arnaldo Garcia Rincon <[email protected]>"] | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2018" | ||
publish = false | ||
# Don't rebuild crate just because of changes to README. | ||
exclude = ["README.md"] | ||
|
||
[dependencies] | ||
log = "0.4" | ||
simplelog = "0.10" | ||
snafu = "0.6" | ||
nix = "0.23" | ||
|
||
[build-dependencies] | ||
cargo-readme = "3.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# shimpei | ||
|
||
Current version: 0.1.0 | ||
|
||
shimpei is an OCI compatible shim wrapper around `oci-add-hooks`. Its sole purpose is | ||
to call `oci-add-hooks` with the additional `--hook-config-path` and `--runtime-path` | ||
parameters that can't be provided by containerd. | ||
|
||
## Colophon | ||
|
||
This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# {{crate}} | ||
|
||
Current version: {{version}} | ||
|
||
{{readme}} | ||
|
||
## Colophon | ||
|
||
This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Automatically generate README.md from rustdoc. | ||
|
||
use std::env; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
// Check for environment variable "SKIP_README". If it is set, | ||
// skip README generation | ||
if env::var_os("SKIP_README").is_some() { | ||
return; | ||
} | ||
|
||
let mut source = File::open("src/main.rs").unwrap(); | ||
let mut template = File::open("README.tpl").unwrap(); | ||
|
||
let content = cargo_readme::generate_readme( | ||
&PathBuf::from("."), // root | ||
&mut source, // source | ||
Some(&mut template), // template | ||
// The "add x" arguments don't apply when using a template. | ||
true, // add title | ||
false, // add badges | ||
false, // add license | ||
true, // indent headings | ||
) | ||
.unwrap(); | ||
|
||
let mut readme = File::create("README.md").unwrap(); | ||
readme.write_all(content.as_bytes()).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/*! | ||
shimpei is an OCI compatible shim wrapper around `oci-add-hooks`. Its sole purpose is | ||
to call `oci-add-hooks` with the additional `--hook-config-path` and `--runtime-path` | ||
parameters that can't be provided by containerd. | ||
*/ | ||
|
||
#![deny(rust_2018_idioms)] | ||
|
||
#[macro_use] | ||
extern crate log; | ||
|
||
use nix; | ||
use simplelog::{Config as LogConfig, LevelFilter, SimpleLogger}; | ||
use snafu::{OptionExt, ResultExt}; | ||
use std::env; | ||
use std::ffi::CString; | ||
use std::path::Path; | ||
use std::process; | ||
|
||
/// Path to runc binary | ||
const RUNC_BIN_PATH: &str = "/usr/bin/runc"; | ||
|
||
/// Path to hooks definitions | ||
const HOOK_CONFIG_BASE_PATH: &str = "/usr/share/oci-add-hooks"; | ||
|
||
/// Path to oci-add-hooks | ||
const OCI_ADD_HOOKS: &str = "/usr/bin/oci-add-hooks"; | ||
|
||
fn run() -> Result<()> { | ||
setup_logger()?; | ||
let mut args = env::args(); | ||
let prefix = args.next().context(error::MissingArg { what: "name" })?; | ||
let hook_path = Path::new(HOOK_CONFIG_BASE_PATH).join(format!("{}-hook.json", prefix)); | ||
|
||
let mut oci_add_hooks_args: Vec<CString> = vec![ | ||
CString::new("oci-add-hooks").expect("Coulnd't create CString from 'oci-add-hooks'"), | ||
CString::new("--hook-config-path") | ||
.expect("Couldn't create CString from '--hook-config-path'"), | ||
CString::new(hook_path.display().to_string()).context(error::InvalidString { | ||
input: hook_path.display().to_string(), | ||
})?, | ||
CString::new("--runtime-path").expect("Couldn't create CString from '--runtime-path'"), | ||
CString::new(RUNC_BIN_PATH).context(error::InvalidString { | ||
input: RUNC_BIN_PATH.to_string(), | ||
})?, | ||
]; | ||
for arg in args { | ||
oci_add_hooks_args | ||
.push(CString::new(arg.as_bytes()).context(error::InvalidString { input: arg })?); | ||
} | ||
|
||
// Use the `execv` syscall instead of `std::process::Command`, since | ||
// it will call `posix_spawn` under the hood, which forks instead of | ||
// replacing the current process | ||
|
||
nix::unistd::execv( | ||
&CString::new(OCI_ADD_HOOKS).context(error::InvalidString { | ||
input: OCI_ADD_HOOKS.to_string(), | ||
})?, | ||
&oci_add_hooks_args, | ||
) | ||
.context(error::Execv { | ||
program: OCI_ADD_HOOKS.to_string(), | ||
})?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn setup_logger() -> Result<()> { | ||
SimpleLogger::init(LevelFilter::Info, LogConfig::default()).context(error::Logger) | ||
} | ||
|
||
fn main() { | ||
if let Err(e) = run() { | ||
error!("{}", e); | ||
process::exit(1); | ||
} | ||
} | ||
|
||
/// <コ:ミ くコ:彡 <コ:ミ くコ:彡 <コ:ミ くコ:彡 <コ:ミ くコ:彡 <コ:ミ くコ:彡 <コ:ミ くコ:彡 | ||
mod error { | ||
use snafu::Snafu; | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(visibility = "pub(super)")] | ||
pub(super) enum Error { | ||
#[snafu(display("Failed to setup logger: {}", source))] | ||
Logger { source: log::SetLoggerError }, | ||
|
||
#[snafu(display("Invalid log level '{}'", log_level))] | ||
LogLevel { | ||
log_level: String, | ||
source: log::ParseLevelError, | ||
}, | ||
|
||
#[snafu(display("Couldn't create CString from '{}': {}", input, source))] | ||
InvalidString { | ||
input: String, | ||
source: std::ffi::NulError, | ||
}, | ||
|
||
#[snafu(display("Failed to exec '{}' : {}", program, source))] | ||
Execv { program: String, source: nix::Error }, | ||
|
||
#[snafu(display("Missing argument '{}'", what))] | ||
MissingArg { what: String }, | ||
} | ||
} | ||
|
||
type Result<T> = std::result::Result<T, error::Error>; |