mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 08:44:09 +02:00
Merge pull request 'feat(start): Print the database location on start' (#49) from artonge/haze:artonge/feat/print_db_location into main
Reviewed-on: https://codeberg.org/icewind/haze/pulls/49
This commit is contained in:
commit
457dcfe573
2 changed files with 47 additions and 11 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::config::HazeConfig;
|
||||||
use crate::exec::{exec, exec_tty, ExitCode};
|
use crate::exec::{exec, exec_tty, ExitCode};
|
||||||
use crate::image::pull_image;
|
use crate::image::pull_image;
|
||||||
use bollard::config::ContainerCreateBody;
|
use bollard::config::ContainerCreateBody;
|
||||||
|
|
@ -7,7 +8,7 @@ use bollard::Docker;
|
||||||
use maplit::hashmap;
|
use maplit::hashmap;
|
||||||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||||
use std::io::{stdout, Stdout};
|
use std::io::{stdout, Stdout};
|
||||||
use std::net::IpAddr;
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use strum::{Display, EnumIter, EnumProperty, IntoStaticStr};
|
use strum::{Display, EnumIter, EnumProperty, IntoStaticStr};
|
||||||
|
|
@ -414,6 +415,37 @@ impl Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn location(
|
||||||
|
&self,
|
||||||
|
docker: &Docker,
|
||||||
|
cloud_id: &str,
|
||||||
|
config: &HazeConfig,
|
||||||
|
) -> Result<String> {
|
||||||
|
let ip = match self.family() {
|
||||||
|
DatabaseFamily::Mysql
|
||||||
|
| DatabaseFamily::MariaDB
|
||||||
|
| DatabaseFamily::Postgres
|
||||||
|
| DatabaseFamily::Oracle => self
|
||||||
|
.ip(docker, cloud_id)
|
||||||
|
.await
|
||||||
|
.ok_or_else(|| Report::msg("Failed to get the IP of the database container"))?,
|
||||||
|
DatabaseFamily::Sqlite => IpAddr::V4(Ipv4Addr::LOCALHOST),
|
||||||
|
};
|
||||||
|
|
||||||
|
match self.family() {
|
||||||
|
DatabaseFamily::Mysql | DatabaseFamily::MariaDB => {
|
||||||
|
Ok(format!("mysql://haze:haze@{ip}/haze"))
|
||||||
|
}
|
||||||
|
DatabaseFamily::Postgres => Ok(format!("postgresql://haze:haze@{ip}/haze")),
|
||||||
|
DatabaseFamily::Oracle => Ok(format!("oracle://system:haze@{ip}:1521/XE")),
|
||||||
|
DatabaseFamily::Sqlite => Ok(config
|
||||||
|
.work_dir
|
||||||
|
.join(cloud_id)
|
||||||
|
.join("data/haze.db")
|
||||||
|
.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn is_healthy(&self, docker: &Docker, cloud_id: &str, postfix: &str) -> Result<bool> {
|
pub async fn is_healthy(&self, docker: &Docker, cloud_id: &str, postfix: &str) -> Result<bool> {
|
||||||
match self.family() {
|
match self.family() {
|
||||||
DatabaseFamily::Sqlite => Ok(true),
|
DatabaseFamily::Sqlite => Ok(true),
|
||||||
|
|
|
||||||
24
src/main.rs
24
src/main.rs
|
|
@ -422,21 +422,15 @@ async fn main() -> Result<ExitCode> {
|
||||||
let ip = cloud
|
let ip = cloud
|
||||||
.ip
|
.ip
|
||||||
.ok_or_else(|| Report::msg(format!("{} is not running", cloud.id)))?;
|
.ok_or_else(|| Report::msg(format!("{} is not running", cloud.id)))?;
|
||||||
let db_type = match cloud.db().family() {
|
match cloud.db().family() {
|
||||||
DatabaseFamily::Sqlite => {
|
DatabaseFamily::Sqlite => {
|
||||||
return Err(Report::msg("sqlite is not supported with `haze env`"));
|
return Err(Report::msg("sqlite is not supported with `haze env`"));
|
||||||
}
|
}
|
||||||
DatabaseFamily::Oracle => {
|
DatabaseFamily::Oracle => {
|
||||||
return Err(Report::msg("oracle is not supported with `haze env`"));
|
return Err(Report::msg("oracle is not supported with `haze env`"));
|
||||||
}
|
}
|
||||||
DatabaseFamily::Mysql | DatabaseFamily::MariaDB => "mysql",
|
_ => {}
|
||||||
DatabaseFamily::Postgres => "postgresql",
|
}
|
||||||
};
|
|
||||||
let db_ip = cloud
|
|
||||||
.db()
|
|
||||||
.ip(&docker, &cloud.id)
|
|
||||||
.await
|
|
||||||
.ok_or_else(|| Report::msg(format!("{}-db is not running", cloud.id)))?;
|
|
||||||
|
|
||||||
let mut command = Command::new(command);
|
let mut command = Command::new(command);
|
||||||
command
|
command
|
||||||
|
|
@ -445,7 +439,7 @@ async fn main() -> Result<ExitCode> {
|
||||||
.env("NEXTCLOUD_URL", &cloud.address)
|
.env("NEXTCLOUD_URL", &cloud.address)
|
||||||
.env(
|
.env(
|
||||||
"DATABASE_URL",
|
"DATABASE_URL",
|
||||||
format!("{}://haze:haze@{}/haze", db_type, db_ip),
|
cloud.db().location(&docker, &cloud.id, &config).await?,
|
||||||
);
|
);
|
||||||
|
|
||||||
if cloud.services().contains(&Service::RedisTls(RedisTls)) {
|
if cloud.services().contains(&Service::RedisTls(RedisTls)) {
|
||||||
|
|
@ -552,6 +546,16 @@ async fn setup(
|
||||||
let cloud = Cloud::create(docker, options, config).await?;
|
let cloud = Cloud::create(docker, options, config).await?;
|
||||||
println!("{}", cloud.address);
|
println!("{}", cloud.address);
|
||||||
let host = cloud.address.split_once("://").expect("no address?").1;
|
let host = cloud.address.split_once("://").expect("no address?").1;
|
||||||
|
|
||||||
|
match cloud.db().location(docker, &cloud.id, config).await {
|
||||||
|
Ok(value) => {
|
||||||
|
println!("Database: {}", value);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to print DB location: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if always_setup || config.auto_setup.enabled {
|
if always_setup || config.auto_setup.enabled {
|
||||||
println!("Waiting for servers to start");
|
println!("Waiting for servers to start");
|
||||||
cloud.wait_for_start(docker).await?;
|
cloud.wait_for_start(docker).await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue