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
10
README.md
10
README.md
|
|
@ -109,4 +109,14 @@ work_dir = "/path/to/temp/dir" # path to temporary directory. optional, defaults
|
||||||
enabled = false # whether or not to automatically install nextcloud on `haze start`. optional, defaults to false
|
enabled = false # whether or not to automatically install nextcloud on `haze start`. optional, defaults to false
|
||||||
username = "foo" # username for admin user during auto setup. optional, defaults to "admin"
|
username = "foo" # username for admin user during auto setup. optional, defaults to "admin"
|
||||||
password = "bar" # password for admin user during auto setup. optional, defaults to "admin"
|
password = "bar" # password for admin user during auto setup. optional, defaults to "admin"
|
||||||
|
|
||||||
|
[[volume]]
|
||||||
|
source = "/tmp/haze-shared"
|
||||||
|
target = "/shared"
|
||||||
|
create = true
|
||||||
|
|
||||||
|
[[volume]]
|
||||||
|
source = "/home/me/Downloads"
|
||||||
|
target = "/Downloads"
|
||||||
|
read_only = true
|
||||||
```
|
```
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::config::HazeConfig;
|
use crate::config::HazeConfig;
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::exec::{exec, exec_tty};
|
use crate::exec::{exec, exec_tty};
|
||||||
use crate::mapping::default_mappings;
|
use crate::mapping::{default_mappings, Mapping};
|
||||||
use crate::php::PhpVersion;
|
use crate::php::PhpVersion;
|
||||||
use crate::service::Service;
|
use crate::service::Service;
|
||||||
use bollard::container::{ListContainersOptions, RemoveContainerOptions};
|
use bollard::container::{ListContainersOptions, RemoveContainerOptions};
|
||||||
|
|
@ -130,7 +130,12 @@ impl Cloud {
|
||||||
let id = format!("haze-{}", petname(2, "-"));
|
let id = format!("haze-{}", petname(2, "-"));
|
||||||
|
|
||||||
let workdir = config.work_dir.join(&id);
|
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 {
|
for mapping in &mappings {
|
||||||
mapping
|
mapping
|
||||||
.create(&id, config)
|
.create(&id, config)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ pub struct HazeConfig {
|
||||||
pub work_dir: Utf8PathBuf,
|
pub work_dir: Utf8PathBuf,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub auto_setup: HazeAutoSetupConfig,
|
pub auto_setup: HazeAutoSetupConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub volume: Vec<HazeVolumeConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
@ -44,6 +46,16 @@ fn default_auto_setup_password() -> String {
|
||||||
"admin".to_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 {
|
impl HazeConfig {
|
||||||
pub fn load() -> Result<Self> {
|
pub fn load() -> Result<Self> {
|
||||||
let dirs = ProjectDirs::from("nl", "icewind", "haze").unwrap();
|
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 camino::Utf8Path;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use tokio::fs::{create_dir_all, write};
|
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::WorkDir => config.work_dir.join(id).join(self.source),
|
||||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
||||||
MappingSourceType::Sources => return Ok(()),
|
MappingSourceType::Sources => return Ok(()),
|
||||||
|
MappingSourceType::Absolute => self.source.into(),
|
||||||
};
|
};
|
||||||
match self.mapping_type {
|
match self.mapping_type {
|
||||||
MappingType::Folder => create_dir_all(source).await?,
|
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::WorkDir => config.work_dir.join(id).join(self.source),
|
||||||
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
MappingSourceType::GlobalWorkDir => config.work_dir.join(self.source),
|
||||||
MappingSourceType::Sources => config.sources_root.join(self.source),
|
MappingSourceType::Sources => config.sources_root.join(self.source),
|
||||||
|
MappingSourceType::Absolute => self.source.into(),
|
||||||
};
|
};
|
||||||
Some(if self.read_only {
|
Some(if self.read_only {
|
||||||
format!("{}:{}:ro", source, self.target)
|
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::*;
|
use MappingSourceType::*;
|
||||||
|
|
||||||
vec![
|
let mappings = [
|
||||||
Mapping::new(Sources, "", "/var/www/html"),
|
Mapping::new(Sources, "", "/var/www/html"),
|
||||||
Mapping::new(WorkDir, "data", "/var/www/html/data"),
|
Mapping::new(WorkDir, "data", "/var/www/html/data"),
|
||||||
Mapping::new(WorkDir, "config", "/var/www/html/config"),
|
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")
|
Mapping::new(Sources, ".htaccess", "/var/www/html/.htaccess")
|
||||||
.file()
|
.file()
|
||||||
.read_only(),
|
.read_only(),
|
||||||
]
|
];
|
||||||
|
std::array::IntoIter::new(mappings)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
|
@ -157,6 +160,7 @@ pub enum MappingSourceType {
|
||||||
Sources,
|
Sources,
|
||||||
WorkDir,
|
WorkDir,
|
||||||
GlobalWorkDir,
|
GlobalWorkDir,
|
||||||
|
Absolute,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
|
@ -164,3 +168,22 @@ pub enum MappingType {
|
||||||
Folder,
|
Folder,
|
||||||
File,
|
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