Work-in-progress reworking in Rust

This commit is contained in:
R Tyler Croy 2020-02-01 03:54:18 -08:00
parent 1012975f35
commit 688e0cbe86
5 changed files with 1958 additions and 11 deletions

8
.gitignore vendored
View File

@ -1,2 +1,10 @@
*.sw*
node_modules/
#Added by cargo
#
#already existing elements are commented out
/target
**/*.rs.bk

1849
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

20
Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "contaminate"
version = "0.1.0"
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
edition = "2018"
[dependencies]
# Used for serving the website
tide = "~0.5.1"
async-std = "~1.4.0"
# Logging
log = "~0.4.8"
pretty_env_logger = "~0.3.1"
# Handling configuration overlays
config = { version = "~0.10.1", features = ["yaml"] }
# Used for making http requests to the upstream docker registry
surf = "~1.0.3"

View File

@ -1,27 +1,51 @@
= Contaminate
Hunting the white whale of a mutable immutable infrastructure.
Contaminate is a caching proxy masquerading as Docker registry. It can modify
Docker images and manifests on the fly, for those who need a little more mutability in their immutable infrastructure.
== Environment Variables
== Configuration
[%header, cols="^1,<.^4,^1,^1"]
Contaminate can be configured with a `contaminate.yml` file, or via specific
environment variables which can override configuration values.
=== YAML Keys
[cols="^1,<.^4,^1,^1"]
|===
.^| Name
.^| Default Value
.^| Notes
| `layers_dir`
| `./layers.d`
| A directory containing the layers to override on images passing through Contaminate.
| `registry`
| https://registry-1.docker.io
| A Registry HTTP V2 compliant URL, reachable by Contaminate.
|===
=== Environment Variables
[cols="^1,<.^4,^1,^1"]
|===
.^| Name
.^| Default Value
.^| Notes
| `LAYERS_DIR`
| `RUST_LOG`
| `warn`
| Log level for Contaminate logs to be printed
| `CT_LAYERS_DIR`
| `./layers.d`
| A directory containing the layers to override on images passing through Ahab
| A directory containing the layers to override on images passing through Contaminate.
| `LOG_LEVEL`
| `info`
| Log level for Ahab logs to be printed
| `UPSTREAM_REGISTRY`
| `CT_REGISTRY`
| https://registry-1.docker.io
| A Registry HTTP V2 compliant URL, reachable by Ahab.
| A Registry HTTP V2 compliant URL, reachable by Contaminate.
|===

46
src/main.rs Normal file
View File

@ -0,0 +1,46 @@
/**
* The main server entrypoint for Contaminate
*/
extern crate config;
extern crate pretty_env_logger;
use async_std::task;
use log::*;
/**
* Load the settings based on the hierarchy.
*
* First we load the configuration file (contaminate.yml) if it exists
* Then we look at environment variables.
*/
fn load_settings() -> config::Config {
let mut settings = config::Config::default();
settings.set_default("registry", "https://registry-1.docker.io")
.expect("Could not set the default for `registry`");
settings.set_default("layers_dir", "./layers.d")
.expect("Could not set the default for `layers_dir`");
settings
.merge(config::File::with_name("contaminate").required(false))
.expect("Failed to load settings in contaminate.ymll")
.merge(config::Environment::with_prefix("CT"))
.expect("Failed to load settings defined by CT_* env vars");
return settings;
}
fn main() -> Result<(), std::io::Error> {
pretty_env_logger::init();
task::block_on(async {
let mut app = tide::new();
app.at("/").get(|_| async move { "Hello, world!" });
app.listen("127.0.0.1:9000").await?;
Ok(())
})
}
#[cfg(test)]
mod tests {
}