Skip to content

Commit

Permalink
Merge pull request #11 from AaronKutch/dev8
Browse files Browse the repository at this point in the history
Dev8
  • Loading branch information
AaronKutch authored Oct 18, 2023
2 parents dfa1eb6 + 190735c commit 2252419
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## [0.7.0] - TODO
## [0.8.0] - 2023-10-18
### Fixes
- Fixed that `no_uuid_for_host_name` was doing the opposite of what it was supposed to

### Additions
- Added environment variable args and some more methods to `Container`

## [0.7.0] - 2023-09-08
### Fixes
- Fixed that `ContainerNetwork`s were using the `name` for hostnames instead of the `host_name` that
was meant for that purpose
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "super_orchestrator"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
authors = ["Aaron Kutch <[email protected]>"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/AaronKutch/super_orchestrator"
documentation = "https://docs.rs/super_orchestrator"
keywords = ["container", "docker"]
description = "advanced container orchestration tools"
description = "programmable container orchestration tools"

[dependencies]
clap = { version = "4", features = ["derive"] }
Expand Down
6 changes: 6 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ impl Command {
self
}

/// Adds an environment variable
pub fn env(mut self, env_key: &str, env_val: &str) -> Self {
self.envs.push((env_key.to_owned(), env_val.to_owned()));
self
}

pub fn ci_mode(mut self, ci_mode: bool) -> Self {
self.ci = ci_mode;
self
Expand Down
49 changes: 48 additions & 1 deletion src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct Container {
/// note that the entrypoint binary is automatically included if
/// `extrypoint_path` is set
pub volumes: Vec<(String, String)>,
/// Environment variable pairs passed to docker
pub environment_vars: Vec<(String, String)>,
/// Path to the entrypoint binary locally
pub entrypoint_path: Option<String>,
/// passed in as ["arg1", "arg2", ...] with the bracket and quotations being
Expand All @@ -77,6 +79,7 @@ impl Container {
build_args: vec![],
create_args: vec![],
volumes: vec![],
environment_vars: vec![],
entrypoint_path: entrypoint_path.map(|s| s.to_owned()),
entrypoint_args: entrypoint_args.iter().fold(Vec::new(), |mut acc, e| {
acc.push(e.to_string());
Expand Down Expand Up @@ -111,9 +114,25 @@ impl Container {
self
}

pub fn environment_vars(mut self, environment_vars: &[(&str, &str)]) -> Self {
self.environment_vars = environment_vars.iter().fold(Vec::new(), |mut acc, e| {
acc.push((e.0.to_string(), e.1.to_string()));
acc
});
self
}

pub fn entrypoint_args(mut self, entrypoint_args: &[&str]) -> Self {
self.entrypoint_args = entrypoint_args.iter().fold(Vec::new(), |mut acc, e| {
acc.push(e.to_string());
acc
});
self
}

/// Turns of the default behavior of attaching the UUID to the hostname
pub fn no_uuid_for_host_name(mut self) -> Self {
self.no_uuid_for_host_name = false;
self.no_uuid_for_host_name = true;
self
}
}
Expand Down Expand Up @@ -277,6 +296,25 @@ impl ContainerNetwork {
}
}

pub fn add_container(&mut self, container: Container) -> Result<&mut Self> {
if self.dockerfile_write_dir.is_none()
&& matches!(container.dockerfile, Dockerfile::Contents(_))
{
return Err(Error::from(
"ContainerNetwork::new() a container is built with `Dockerfile::Contents`, but \
`dockerfile_write_dir` is unset",
))
}
if self.containers.contains_key(&container.name) {
return Err(Error::from(format!(
"ContainerNetwork::new() two containers were supplied with the same name \"{}\"",
container.name
)))
}
self.containers.insert(container.name.clone(), container);
Ok(self)
}

/// Adds the volumes to every container
pub fn add_common_volumes(&mut self, volumes: &[(&str, &str)]) -> &mut Self {
for container in self.containers.values_mut() {
Expand Down Expand Up @@ -515,6 +553,15 @@ impl ContainerNetwork {
&full_name,
];

let mut tmp = vec![];
for var in &container.environment_vars {
tmp.push(format!("{}={}", var.0, var.1));
}
for tmp in &tmp {
args.push("-e");
args.push(tmp);
}

// volumes
let mut volumes = container.volumes.clone();
// include the needed binary
Expand Down

0 comments on commit 2252419

Please sign in to comment.