Skip to content

Commit

Permalink
Merge pull request #145 from railwayapp/jr/label-flag
Browse files Browse the repository at this point in the history
Flag to add additional labels to resulting image
  • Loading branch information
coffee-cup authored May 26, 2022
2 parents b020d84 + 25c5193 commit c6318b9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub fn gen_plan(
out_dir: None,
plan_path: None,
tags: Vec::new(),
labels: Vec::new(),
quiet: false,
};

Expand All @@ -72,6 +73,7 @@ pub fn build(
plan_path: Option<String>,
out_dir: Option<String>,
tags: Vec<&str>,
labels: Vec<&str>,
quiet: bool,
) -> Result<()> {
let logger = Logger::new();
Expand All @@ -85,6 +87,7 @@ pub fn build(
out_dir,
plan_path,
tags: tags.iter().map(|s| s.to_string()).collect(),
labels: labels.iter().map(|s| s.to_string()).collect(),
quiet,
};

Expand Down
23 changes: 18 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ fn main() -> Result<()> {
.help("Additional tags to add to the output image")
.takes_value(true)
.multiple_values(true),
)
.arg(
Arg::new("label")
.long("label")
.short('l')
.help("Additional labels to add to the output image")
.takes_value(true)
.multiple_values(true),
),
)
.arg(
Expand Down Expand Up @@ -116,14 +124,19 @@ fn main() -> Result<()> {
let plan_path = matches.value_of("plan").map(|n| n.to_string());
let output_dir = matches.value_of("out").map(|n| n.to_string());

let tags: Vec<_> = match matches.values_of("tag") {
Some(values) => values.collect(),
None => Vec::new(),
};
let tags = matches
.values_of("tag")
.map(|values| values.collect())
.unwrap_or_default();

let labels = matches
.values_of("label")
.map(|values| values.collect())
.unwrap_or_default();

build(
path, name, pkgs, build_cmd, start_cmd, pin_pkgs, envs, plan_path, output_dir,
tags, false,
tags, labels, false,
)?;
}
_ => eprintln!("Invalid command"),
Expand Down
9 changes: 8 additions & 1 deletion src/nixpacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct AppBuilderOptions {
pub out_dir: Option<String>,
pub plan_path: Option<String>,
pub tags: Vec<String>,
pub labels: Vec<String>,
pub quiet: bool,
}

Expand All @@ -55,6 +56,7 @@ impl AppBuilderOptions {
out_dir: None,
plan_path: None,
tags: Vec::new(),
labels: Vec::new(),
quiet: false,
}
}
Expand Down Expand Up @@ -173,10 +175,15 @@ impl<'a> AppBuilder<'a> {
.arg(format!("{}={}", name, value));
}

// Add user defined tags to the image
// Add user defined tags and labels to the image
for t in self.options.tags.clone() {
docker_build_cmd.arg("-t").arg(t);
}
for l in self.options.labels.clone() {
docker_build_cmd.arg("--label").arg(l);
}

println!("{:?}", docker_build_cmd);

let build_result = docker_build_cmd.spawn()?.wait().context("Building image")?;

Expand Down
3 changes: 3 additions & 0 deletions tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn simple_build(path: &str) -> String {
None,
None,
Vec::new(),
Vec::new(),
true,
)
.unwrap();
Expand Down Expand Up @@ -190,6 +191,7 @@ fn test_rust_custom_version() {
None,
None,
Vec::new(),
Vec::new(),
true,
)
.unwrap();
Expand Down Expand Up @@ -233,6 +235,7 @@ fn test_cowsay() {
None,
None,
Vec::new(),
Vec::new(),
true,
)
.unwrap();
Expand Down

0 comments on commit c6318b9

Please sign in to comment.