Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For all commands, exlucde non-targeted pods on docker-compose.yml output #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,10 @@ impl Project {

/// Process our pods, flattening and transforming them using our
/// plugins, and output them to the specified directory.
fn output_helper(&self, op: Operation, subcommand: &str, export_dir: &Path) -> Result<()> {
fn output_helper(&self, pods: Vec<&Pod>, op: Operation, subcommand: &str, export_dir: &Path) -> Result<()> {
// Output each pod. This isn't especially slow (except maybe the
// Vault plugin), but parallelizing things is easy.
self.pods.par_iter()
// Don't export pods which aren't enabled. However, we currently
// need to output these for `Operation::Output` in case the user
// wants to `run` a task using one of these pod definitions.
.filter(|pod| {
pod.enabled_in(&self.current_target) ||
op == Operation::Output
})
pods.par_iter()
// Process each pod in parallel.
.map(|pod| -> Result<()> {
// Figure out where to put our pod.
Expand Down Expand Up @@ -452,6 +445,10 @@ impl Project {
/// Delete our existing output and replace it with a processed and
/// expanded version of our pod definitions.
pub fn output(&self, subcommand: &str) -> Result<()> {
let pods = self.pods.iter().filter(|pod| {
pod.enabled_in(&self.current_target)
}).collect::<Vec<&_>>();

// Get a path to our output pods directory (and delete it if it
// exists).
let out_pods = self.output_pods_dir();
Expand All @@ -460,13 +457,17 @@ impl Project {
.map_err(|e| err!("Cannot delete {}: {}", out_pods.display(), e)));
}

self.output_helper(Operation::Output, subcommand, &out_pods)
self.output_helper(pods, Operation::Output, subcommand, &out_pods)
}

/// Export this project (with the specified target applied) as a set
/// of standalone `*.yml` files with no environment variable
/// interpolations and no external dependencies.
pub fn export(&self, export_dir: &Path) -> Result<()> {
let pods = self.pods.iter().filter(|pod| {
pod.enabled_in(&self.current_target)
}).collect::<Vec<&_>>();

// Don't clobber an existing directory.
if export_dir.exists() {
return Err(err!("The directory {} already exists", export_dir.display()));
Expand All @@ -477,8 +478,10 @@ impl Project {
warn!("Exporting project without --default-tags");
}

self.output_helper(Operation::Export, "export", export_dir)
self.output_helper(pods, Operation::Export, "export", export_dir)
}


}

/// Convert to JSON for use in generator templates.
Expand Down