mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
allow configuring additional app directories and add a writable app directory
fixes #15
This commit is contained in:
parent
862d33b017
commit
b7ea4e9760
6 changed files with 130 additions and 34 deletions
|
|
@ -1,13 +1,14 @@
|
|||
use crate::config::{HazeConfig, HazeVolumeConfig};
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use std::borrow::Cow;
|
||||
use tokio::fs::{create_dir_all, write};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Mapping<'a> {
|
||||
source_type: MappingSourceType,
|
||||
pub source: &'a Utf8Path,
|
||||
pub target: &'a Utf8Path,
|
||||
pub source: Cow<'a, Utf8Path>,
|
||||
pub target: Cow<'a, Utf8Path>,
|
||||
mapping_type: MappingType,
|
||||
read_only: bool,
|
||||
map: bool,
|
||||
|
|
@ -23,6 +24,26 @@ impl<'a> Mapping<'a> {
|
|||
where
|
||||
Target: Into<&'a Utf8Path>,
|
||||
Source: Into<&'a Utf8Path>,
|
||||
{
|
||||
Mapping {
|
||||
source_type,
|
||||
source: Cow::Borrowed(source.into()),
|
||||
target: Cow::Borrowed(target.into()),
|
||||
mapping_type: MappingType::Folder,
|
||||
read_only: false,
|
||||
map: true,
|
||||
create: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn owned<Source, Target>(
|
||||
source_type: MappingSourceType,
|
||||
source: Source,
|
||||
target: Target,
|
||||
) -> Self
|
||||
where
|
||||
Target: Into<Cow<'a, Utf8Path>>,
|
||||
Source: Into<Cow<'a, Utf8Path>>,
|
||||
{
|
||||
Mapping {
|
||||
source_type,
|
||||
|
|
@ -65,10 +86,10 @@ impl<'a> Mapping<'a> {
|
|||
return Ok(());
|
||||
}
|
||||
let source = match self.source_type {
|
||||
MappingSourceType::WorkDir => config.work_dir.join(id).join(self.source),
|
||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
||||
MappingSourceType::WorkDir => config.work_dir.join(id).join(self.source.as_ref()),
|
||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source.as_ref()),
|
||||
MappingSourceType::Sources => return Ok(()),
|
||||
MappingSourceType::Absolute => self.source.into(),
|
||||
MappingSourceType::Absolute => self.source.as_ref().into(),
|
||||
};
|
||||
match self.mapping_type {
|
||||
MappingType::Folder => create_dir_all(source).await.into_diagnostic()?,
|
||||
|
|
@ -80,10 +101,10 @@ impl<'a> Mapping<'a> {
|
|||
|
||||
pub fn source(&self, id: &str, config: &HazeConfig, source_root: &Utf8Path) -> Utf8PathBuf {
|
||||
match self.source_type {
|
||||
MappingSourceType::WorkDir => config.work_dir.join(id).join(self.source),
|
||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
||||
MappingSourceType::Sources => source_root.join(self.source),
|
||||
MappingSourceType::Absolute => self.source.into(),
|
||||
MappingSourceType::WorkDir => config.work_dir.join(id).join(self.source.as_ref()),
|
||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source.as_ref()),
|
||||
MappingSourceType::Sources => source_root.join(self.source.as_ref()),
|
||||
MappingSourceType::Absolute => self.source.as_ref().into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,6 +133,7 @@ pub fn default_mappings<'a>() -> impl IntoIterator<Item = Mapping<'a>> {
|
|||
Mapping::new(Sources, "", "/var/www/html"),
|
||||
Mapping::new(WorkDir, "data", "/var/www/html/data"),
|
||||
Mapping::new(WorkDir, "config", "/var/www/html/config"),
|
||||
Mapping::new(WorkDir, "store_app", "/var/www/html/store_app"),
|
||||
Mapping::new(WorkDir, "data-autotest", "/var/www/html/data-autotest"),
|
||||
Mapping::new(WorkDir, "skeleton", "/var/www/html/core/skeleton"),
|
||||
Mapping::new(
|
||||
|
|
@ -168,9 +190,30 @@ pub fn default_mappings<'a>() -> impl IntoIterator<Item = Mapping<'a>> {
|
|||
Mapping::new(WorkDir, "profiling", "/tmp/profiling"),
|
||||
Mapping::new(WorkDir, "php-config", "/config"),
|
||||
];
|
||||
|
||||
IntoIterator::into_iter(mappings)
|
||||
}
|
||||
|
||||
pub fn for_config<'a>(config: &'a HazeConfig) -> impl Iterator<Item = Mapping<'a>> {
|
||||
let app_dir_mappings = config.app_directories.iter().map(|dir| {
|
||||
Mapping::owned(
|
||||
MappingSourceType::Absolute,
|
||||
dir.as_path(),
|
||||
Cow::Owned(Utf8PathBuf::from(format!(
|
||||
"/var/www/html/{}",
|
||||
dir.file_name().unwrap()
|
||||
))),
|
||||
)
|
||||
});
|
||||
|
||||
config
|
||||
.volume
|
||||
.iter()
|
||||
.map(Mapping::from)
|
||||
.chain(app_dir_mappings)
|
||||
.chain(default_mappings())
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum MappingSourceType {
|
||||
Sources,
|
||||
|
|
@ -194,8 +237,8 @@ impl<'a> From<&'a HazeVolumeConfig> for Mapping<'a> {
|
|||
};
|
||||
Mapping {
|
||||
source_type: MappingSourceType::Absolute,
|
||||
source: config.source.as_path(),
|
||||
target: config.target.as_path(),
|
||||
source: Cow::Borrowed(config.source.as_path()),
|
||||
target: Cow::Borrowed(config.target.as_path()),
|
||||
mapping_type: ty,
|
||||
read_only: config.read_only,
|
||||
map: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue