Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
320ff343e6
commit
94efc99d05
@ -9,7 +9,7 @@ use super::RustService;
|
|||||||
|
|
||||||
pub struct Assets {
|
pub struct Assets {
|
||||||
client: dagger_sdk::Query,
|
client: dagger_sdk::Query,
|
||||||
assets: Vec<PathBuf>,
|
assets: Vec<(PathBuf, PathBuf)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Assets {
|
impl Assets {
|
||||||
@ -20,8 +20,8 @@ impl Assets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_folders(mut self, folders: impl IntoIterator<Item = impl Into<PathBuf>>) -> Self {
|
fn with_folders(mut self, folders: impl IntoIterator<Item = (PathBuf, PathBuf)>) -> Self {
|
||||||
let mut folders = folders.into_iter().map(|f| f.into()).collect::<Vec<_>>();
|
let mut folders = folders.into_iter().collect::<Vec<(PathBuf, PathBuf)>>();
|
||||||
self.assets.append(&mut folders);
|
self.assets.append(&mut folders);
|
||||||
|
|
||||||
self
|
self
|
||||||
@ -31,10 +31,14 @@ impl Assets {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl DaggerMiddleware for Assets {
|
impl DaggerMiddleware for Assets {
|
||||||
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
||||||
let container = self.assets.iter().fold(container, |container, asset_path| {
|
let container =
|
||||||
let rel_path = asset_path.display().to_string();
|
self.assets
|
||||||
let path = self.client.host().directory(&rel_path);
|
.iter()
|
||||||
container.with_directory(&rel_path, path)
|
.fold(container, |container, (src_asset_path, dest_asset_path)| {
|
||||||
|
let src_path = src_asset_path.display().to_string();
|
||||||
|
let dest_path = dest_asset_path.display().to_string();
|
||||||
|
let path = self.client.host().directory(&src_path);
|
||||||
|
container.with_directory(&dest_path, path)
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(container)
|
Ok(container)
|
||||||
@ -42,13 +46,13 @@ impl DaggerMiddleware for Assets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait AssetsExt {
|
pub trait AssetsExt {
|
||||||
fn with_assets(&mut self, folders: impl IntoIterator<Item = impl Into<PathBuf>>) -> &mut Self {
|
fn with_assets(&mut self, folders: impl IntoIterator<Item = (PathBuf, PathBuf)>) -> &mut Self {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssetsExt for RustService {
|
impl AssetsExt for RustService {
|
||||||
fn with_assets(&mut self, folders: impl IntoIterator<Item = impl Into<PathBuf>>) -> &mut Self {
|
fn with_assets(&mut self, folders: impl IntoIterator<Item = (PathBuf, PathBuf)>) -> &mut Self {
|
||||||
self.with_stage(super::RustServiceStage::AfterPackage(Arc::new(
|
self.with_stage(super::RustServiceStage::AfterPackage(Arc::new(
|
||||||
Assets::new(self.client.clone()).with_folders(folders),
|
Assets::new(self.client.clone()).with_folders(folders),
|
||||||
)))
|
)))
|
||||||
|
Loading…
Reference in New Issue
Block a user