1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

store services for instance

This commit is contained in:
Robin Appelman 2025-05-02 12:15:01 +02:00
commit d87ee6ccc9
4 changed files with 28 additions and 13 deletions

1
Cargo.lock generated
View file

@ -648,6 +648,7 @@ dependencies = [
"hyper",
"hyper-reverse-proxy",
"hyper-util",
"itertools",
"maplit",
"miette",
"opener",

View file

@ -32,6 +32,7 @@ tracing = "0.1.40"
tracing-subscriber = "0.3.18"
atty = "0.2.14"
git2 = { version = "0.20.0", default-features = false }
itertools = { version = "0.14.0", features = ["use_alloc"] }
hyper-reverse-proxy = { version = "0.5.2-dev", git = "https://github.com/chpio/hyper-reverse-proxy", rev = "6934877eb74465204f605cc1c05ca5a9772db7c0" }
hyper = "1.6.0"

View file

@ -1,14 +1,14 @@
use crate::config::{HazeConfig, HazeVolumeConfig, Preset};
use crate::database::Database;
use crate::exec::{ExitCode, exec, exec_io, exec_tty};
use crate::mapping::{Mapping, default_mappings};
use crate::php::{PHP_MEMORY_LIMIT, PhpVersion};
use crate::exec::{exec, exec_io, exec_tty, ExitCode};
use crate::mapping::{default_mappings, Mapping};
use crate::php::{PhpVersion, PHP_MEMORY_LIMIT};
use crate::service::Service;
use crate::service::ServiceTrait;
use bollard::Docker;
use bollard::container::{ListContainersOptions, RemoveContainerOptions, UpdateContainerOptions};
use bollard::models::ContainerState;
use bollard::network::CreateNetworkOptions;
use bollard::Docker;
use camino::Utf8PathBuf;
use flate2::read::GzDecoder;
use futures_util::future::try_join_all;
@ -18,7 +18,7 @@ use serde_json::Value;
use std::collections::HashMap;
use std::fmt::Display;
use std::fs;
use std::io::{Cursor, Read, Stdout, Write, stdout};
use std::io::{stdout, Cursor, Read, Stdout, Write};
use std::iter::Peekable;
use std::net::IpAddr;
use std::os::unix::fs::MetadataExt;
@ -333,7 +333,16 @@ impl Cloud {
let container = match options
.php
.spawn(docker, &id, env, &options.db, &network, volumes, gateway)
.spawn(
docker,
&id,
env,
&options.db,
&network,
volumes,
gateway,
&options.services,
)
.await
.wrap_err("Failed to start php container")
{
@ -571,14 +580,13 @@ impl Cloud {
let labels = cloud.labels?;
let db = labels.get("haze-db")?.parse().ok()?;
let php = labels.get("haze-php")?.parse().ok()?;
let found_services = services
.iter()
.flat_map(|container| &container.labels)
.flat_map(|labels| labels.get("haze-type"))
.map(String::as_str)
.flat_map(|ty| Service::from_type(&[], ty))
.flatten()
let found_services = labels
.get("haze-services")?
.split(',')
.flat_map(|service| Service::from_type(&config.preset, service).into_iter().flatten())
.collect();
let mut service_ids: Vec<String> = services
.iter()
.filter_map(|service| service.names.as_ref()?.first().cloned())

View file

@ -1,10 +1,13 @@
use crate::database::Database;
use crate::image::pull_image;
use crate::network::ensure_network_exists;
use crate::service::Service;
use crate::service::ServiceTrait;
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
use bollard::models::{EndpointSettings, HostConfig};
use bollard::network::ConnectNetworkOptions;
use bollard::Docker;
use itertools::Itertools;
use maplit::hashmap;
use miette::{IntoDiagnostic, Report, Result, WrapErr};
use reqwest::{Client, Url};
@ -105,6 +108,7 @@ impl PhpVersion {
network: &str,
volumes: Vec<String>,
host: &str,
services: &[Service],
) -> Result<String> {
ensure_network_exists(docker, "haze").await?;
pull_image(docker, self.image()).await?;
@ -136,6 +140,7 @@ impl PhpVersion {
"haze-db".to_string() => db.name().to_string(),
"haze-php".to_string() => self.name().to_string(),
"haze-cloud-id".to_string() => id.to_string(),
"haze-services".to_string() => services.iter().map(|s| s.name()).join(","),
}),
..Default::default()
};