debug r2 client in dev, fix startup

This commit is contained in:
Brandon Thomas
2025-01-23 21:02:36 -05:00
parent 2cdf9ce41f
commit a67f60d09e
7 changed files with 43 additions and 9 deletions
@@ -4,11 +4,13 @@ use std::time::Duration;
use anyhow::anyhow;
use anyhow::bail;
use log::warn;
use log::{error, warn};
use log::{debug, info};
use s3::bucket::Bucket;
use s3::creds::Credentials;
use s3::error::S3Error;
use s3::region::Region;
use s3::request::ResponseData;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
@@ -143,7 +145,13 @@ impl BucketClient {
let object_name = self.get_rooted_object_name(object_name);
info!("Rooted filename for bucket: {}", object_name);
let response = self.bucket.put_object_with_content_type(&object_name, bytes, content_type).await?;
let response = self.bucket.put_object_with_content_type(&object_name, bytes, content_type).await;
if let Err(err) = &response {
error!("S3 Upload Error for bucket name {}: {:?}", &self.bucket.name, err);
}
let response = response?;
let body_bytes = response.bytes();
let code = response.status_code();
+10 -1
View File
@@ -15,6 +15,11 @@ pub struct BootstrapArgs<'a, P: AsRef<Path>> {
/// Where to look for env conf files.
pub config_search_directories: &'a [P],
/// If true, ignore the root '.env' file.
/// TODO(bt,2025-01-23): Make this the default behavior, then remove reading from '.env' entirely,
/// There are too many apps that share this file.
pub ignore_legacy_dot_env_file: bool,
}
/// Information about how the application is deployed.
@@ -45,7 +50,11 @@ pub struct ContainerEnvironment {
const SERVER_ENVIRONMENT : &str = "SERVER_ENVIRONMENT";
pub fn bootstrap<P: AsRef<Path>>(args: BootstrapArgs<'_, P>) -> AnyhowResult<ContainerEnvironment> {
easyenv::init_all_with_default_logging(args.default_logging_override);
if args.ignore_legacy_dot_env_file {
easyenv::init_env_logger(args.default_logging_override);
} else {
easyenv::init_all_with_default_logging(args.default_logging_override);
}
info!("Bootstrapping application {}", &args.app_name);
@@ -52,7 +52,7 @@ pub async fn download_file_for_studio(
let suffix = get_suffix(&input_media_file);
let filesystem_path = args.input_paths.input_dir
let filesystem_path = args.input_paths.input_dir.path()
.join(format!("{}{}", args.filename_without_extension, suffix));
info!("Downloading input file to {:?}", &filesystem_path);
@@ -24,12 +24,11 @@ python inference_advanced.py \
--gradient_checkpointing
*/
use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::time::Duration;
use log::{debug, info, warn};
use tokio::io::{AsyncBufReadExt, AsyncWriteExt};
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::process::Command;
use errors::AnyhowResult;
use filesys::path_to_string::path_to_string;
@@ -40,7 +39,7 @@ use crate::util::get_filtered_env_vars::get_filtered_env_vars_hashmap;
#[derive(Clone)]
pub struct StableAnimatorCommand {
/// Where the code lives
comfy_root_code_directory: PathBuf,
root_code_directory: PathBuf,
/// A single executable script or a much larger bash command.
executable_or_command: ExecutableOrCommand,
@@ -84,6 +83,16 @@ pub struct InferenceArgs<'s> {
}
impl StableAnimatorCommand {
pub fn new_from_env() -> AnyhowResult<Self> {
Ok(Self {
root_code_directory: PathBuf::from("/home/bt/dev/storyteller/storyteller-ml/animation/StableAnimator"),
executable_or_command: ExecutableOrCommand::Executable(PathBuf::from("inference_advanced.py")),
maybe_virtual_env_activation_command: Some(String::from("source venv/bin/activate")),
maybe_docker_options: None,
maybe_execution_timeout: None,
})
}
pub async fn execute_inference<'a, 'b>(
&'a self,
args: InferenceArgs<'b>,
@@ -91,7 +100,7 @@ impl StableAnimatorCommand {
info!("InferenceArgs: {:?}", &args);
let mut command = String::new();
command.push_str(&format!("cd {}", path_to_string(&self.comfy_root_code_directory)));
command.push_str(&format!("cd {}", path_to_string(&self.root_code_directory)));
if let Some(venv_command) = self.maybe_virtual_env_activation_command.as_deref() {
command.push_str(" && ");
@@ -28,7 +28,7 @@ impl StudioGen2Dependencies {
model_path: PathBuf::from("/tmp/model.pt"),
input_directory: PathBuf::from("/tmp/input"),
output_directory: PathBuf::from("/tmp/output"),
command: StableAnimatorCommand::new(),
command: StableAnimatorCommand::new_from_env()?,
// TODO
pretrained_model_name_or_path: Default::default(),
@@ -1,5 +1,8 @@
# storyteller-web default .env configurations (these can be overridden with k8s)
# Development
SERVER_ENVIRONMENT='development'
# We can't serve HTTPS locally without self-signed certificate nonsense.
COOKIE_SECURE=false
COOKIE_DOMAIN=.jungle.horse
@@ -34,3 +37,7 @@ REDIS_0_URL="redis://localhost/0"
#REDIS_1_URL="redis://localhost/1"
GC_ENABLED_PUBLIC_BUCKET_NAME="REPLACE_ME"
# Legacy configs
AUDIO_UPLOADS_BUCKET_ROOT=/user_uploaded_w2l_audio
@@ -132,6 +132,7 @@ async fn main() -> AnyhowResult<()> {
app_name: "storyteller-web",
default_logging_override: Some(DEFAULT_RUST_LOG),
config_search_directories: &[".", "./config", "crates/service/web/storyteller_web/config"],
ignore_legacy_dot_env_file: true,
})?;
let common_env = CommonEnv::read_from_env()?;