mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
allow specifying extra mappings in config
This commit is contained in:
parent
55c6754646
commit
b4aec684c6
4 changed files with 56 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::config::HazeConfig;
|
||||
use crate::database::Database;
|
||||
use crate::exec::{exec, exec_tty};
|
||||
use crate::mapping::default_mappings;
|
||||
use crate::mapping::{default_mappings, Mapping};
|
||||
use crate::php::PhpVersion;
|
||||
use crate::service::Service;
|
||||
use bollard::container::{ListContainersOptions, RemoveContainerOptions};
|
||||
|
|
@ -130,7 +130,12 @@ impl Cloud {
|
|||
let id = format!("haze-{}", petname(2, "-"));
|
||||
|
||||
let workdir = config.work_dir.join(&id);
|
||||
let mappings = default_mappings();
|
||||
let mappings = config
|
||||
.volume
|
||||
.iter()
|
||||
.map(Mapping::from)
|
||||
.chain(default_mappings())
|
||||
.collect::<Vec<_>>();
|
||||
for mapping in &mappings {
|
||||
mapping
|
||||
.create(&id, config)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ pub struct HazeConfig {
|
|||
pub work_dir: Utf8PathBuf,
|
||||
#[serde(default)]
|
||||
pub auto_setup: HazeAutoSetupConfig,
|
||||
#[serde(default)]
|
||||
pub volume: Vec<HazeVolumeConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
@ -44,6 +46,16 @@ fn default_auto_setup_password() -> String {
|
|||
"admin".to_string()
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct HazeVolumeConfig {
|
||||
pub source: Utf8PathBuf,
|
||||
pub target: Utf8PathBuf,
|
||||
#[serde(default)]
|
||||
pub read_only: bool,
|
||||
#[serde(default)]
|
||||
pub create: bool,
|
||||
}
|
||||
|
||||
impl HazeConfig {
|
||||
pub fn load() -> Result<Self> {
|
||||
let dirs = ProjectDirs::from("nl", "icewind", "haze").unwrap();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::config::HazeConfig;
|
||||
use crate::config::{HazeConfig, HazeVolumeConfig};
|
||||
use camino::Utf8Path;
|
||||
use color_eyre::Result;
|
||||
use tokio::fs::{create_dir_all, write};
|
||||
|
|
@ -68,6 +68,7 @@ impl<'a> Mapping<'a> {
|
|||
MappingSourceType::WorkDir => config.work_dir.join(id).join(self.source),
|
||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
||||
MappingSourceType::Sources => return Ok(()),
|
||||
MappingSourceType::Absolute => self.source.into(),
|
||||
};
|
||||
match self.mapping_type {
|
||||
MappingType::Folder => create_dir_all(source).await?,
|
||||
|
|
@ -85,6 +86,7 @@ impl<'a> Mapping<'a> {
|
|||
MappingSourceType::WorkDir => config.work_dir.join(id).join(self.source),
|
||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
||||
MappingSourceType::Sources => config.sources_root.join(self.source),
|
||||
MappingSourceType::Absolute => self.source.into(),
|
||||
};
|
||||
Some(if self.read_only {
|
||||
format!("{}:{}:ro", source, self.target)
|
||||
|
|
@ -94,10 +96,10 @@ impl<'a> Mapping<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn default_mappings() -> Vec<Mapping<'static>> {
|
||||
pub fn default_mappings<'a>() -> impl IntoIterator<Item = Mapping<'a>> {
|
||||
use MappingSourceType::*;
|
||||
|
||||
vec![
|
||||
let mappings = [
|
||||
Mapping::new(Sources, "", "/var/www/html"),
|
||||
Mapping::new(WorkDir, "data", "/var/www/html/data"),
|
||||
Mapping::new(WorkDir, "config", "/var/www/html/config"),
|
||||
|
|
@ -149,7 +151,8 @@ pub fn default_mappings() -> Vec<Mapping<'static>> {
|
|||
Mapping::new(Sources, ".htaccess", "/var/www/html/.htaccess")
|
||||
.file()
|
||||
.read_only(),
|
||||
]
|
||||
];
|
||||
std::array::IntoIter::new(mappings)
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
|
@ -157,6 +160,7 @@ pub enum MappingSourceType {
|
|||
Sources,
|
||||
WorkDir,
|
||||
GlobalWorkDir,
|
||||
Absolute,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
|
@ -164,3 +168,22 @@ pub enum MappingType {
|
|||
Folder,
|
||||
File,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a HazeVolumeConfig> for Mapping<'a> {
|
||||
fn from(config: &'a HazeVolumeConfig) -> Self {
|
||||
let ty = if config.source.is_dir() {
|
||||
MappingType::Folder
|
||||
} else {
|
||||
MappingType::File
|
||||
};
|
||||
Mapping {
|
||||
source_type: MappingSourceType::Absolute,
|
||||
source: config.source.as_path(),
|
||||
target: config.target.as_path(),
|
||||
mapping_type: ty,
|
||||
read_only: config.read_only,
|
||||
map: true,
|
||||
create: config.create,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue