mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-04 01:24:09 +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
69
src/cloud.rs
69
src/cloud.rs
|
|
@ -1,7 +1,7 @@
|
|||
use crate::config::{HazeConfig, HazeVolumeConfig};
|
||||
use crate::database::Database;
|
||||
use crate::exec::{exec, exec_io, exec_tty, ExitCode};
|
||||
use crate::mapping::{default_mappings, Mapping};
|
||||
use crate::mapping::{for_config, Mapping};
|
||||
use crate::php::{PhpVersion, PHP_MEMORY_LIMIT};
|
||||
use crate::service::Service;
|
||||
use crate::service::ServiceTrait;
|
||||
|
|
@ -15,14 +15,14 @@ use flate2::read::GzDecoder;
|
|||
use futures_util::future::try_join_all;
|
||||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||
use petname::petname;
|
||||
use serde_json::Value;
|
||||
use serde_json::{Map, Value};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::fs;
|
||||
use std::fs::read_to_string;
|
||||
use std::fs::{read_to_string, write};
|
||||
use std::io::{stdout, Cursor, Read, Stdout, Write};
|
||||
use std::iter::Peekable;
|
||||
use std::iter::{once, Peekable};
|
||||
use std::net::IpAddr;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::str::FromStr;
|
||||
|
|
@ -286,11 +286,8 @@ impl Cloud {
|
|||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let mappings = config
|
||||
.volume
|
||||
.iter()
|
||||
.map(Mapping::from)
|
||||
.chain(default_mappings())
|
||||
|
||||
let mappings = for_config(config)
|
||||
.chain(app_volumes.iter().map(Mapping::from))
|
||||
.collect::<Vec<_>>();
|
||||
for mapping in &mappings {
|
||||
|
|
@ -300,6 +297,48 @@ impl Cloud {
|
|||
.wrap_err_with(|| format!("Failed to setup work directory {}", mapping.source))?;
|
||||
}
|
||||
|
||||
let mut nc_config = Value::Object(Map::new());
|
||||
nc_config["apps_paths"] = Value::Array(
|
||||
once("apps")
|
||||
.chain(
|
||||
config
|
||||
.app_directories
|
||||
.iter()
|
||||
.filter_map(|dir| dir.file_name()),
|
||||
)
|
||||
.map(|name| {
|
||||
[
|
||||
(
|
||||
String::from("path"),
|
||||
Value::from(format!("/var/www/html/{}", name)),
|
||||
),
|
||||
(String::from("url"), Value::from(format!("/{}", name))),
|
||||
(String::from("writable"), Value::from(false)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
})
|
||||
.chain(once(
|
||||
[
|
||||
(
|
||||
String::from("path"),
|
||||
Value::from("/var/www/html/store_apps"),
|
||||
),
|
||||
(String::from("url"), Value::from("/store_apps")),
|
||||
(String::from("writable"), Value::from(true)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
))
|
||||
.collect(),
|
||||
);
|
||||
write(
|
||||
workdir.join("config/nextcloud.json"),
|
||||
serde_json::to_string_pretty(&nc_config).unwrap(),
|
||||
)
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to write config json")?;
|
||||
|
||||
let network = docker
|
||||
.create_network(NetworkCreateRequest {
|
||||
name: id.clone(),
|
||||
|
|
@ -500,10 +539,7 @@ impl Cloud {
|
|||
pub async fn destroy(self, docker: &Docker) -> Result<()> {
|
||||
for container in self.containers {
|
||||
docker
|
||||
.kill_container(
|
||||
container.trim_start_matches('/'),
|
||||
None,
|
||||
)
|
||||
.kill_container(container.trim_start_matches('/'), None)
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to kill container")?;
|
||||
|
|
@ -802,12 +838,7 @@ impl Cloud {
|
|||
format!("/var/www/html/{path}").into()
|
||||
};
|
||||
|
||||
let mut mappings = config
|
||||
.volume
|
||||
.iter()
|
||||
.map(Mapping::from)
|
||||
.chain(default_mappings())
|
||||
.collect::<Vec<_>>();
|
||||
let mut mappings = for_config(config).collect::<Vec<_>>();
|
||||
mappings.sort_by_key(|mapping| usize::MAX - mapping.target.as_str().len());
|
||||
|
||||
for mapping in mappings {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue