use compose_yml::v2 as dc;
use std::marker::PhantomData;
use crate::errors::*;
use crate::plugins;
use crate::plugins::{Operation, PluginNew, PluginTransform};
use crate::project::Project;
#[derive(Debug)]
#[allow(missing_copy_implementations)]
pub struct Plugin {
_placeholder: PhantomData<()>,
}
impl plugins::Plugin for Plugin {
fn name(&self) -> &'static str {
Self::plugin_name()
}
}
impl PluginNew for Plugin {
fn plugin_name() -> &'static str {
"labels"
}
fn new(_project: &Project) -> Result<Self> {
Ok(Plugin {
_placeholder: PhantomData,
})
}
}
impl PluginTransform for Plugin {
fn transform(
&self,
_op: Operation,
ctx: &plugins::Context<'_>,
file: &mut dc::File,
) -> Result<()> {
for service in &mut file.services.values_mut() {
let target = ctx.project.current_target().name();
service
.labels
.insert("io.fdy.cage.target".into(), dc::value(target.into()));
service
.labels
.insert("io.fdy.cage.pod".into(), dc::value(ctx.pod.name().into()));
}
Ok(())
}
}