From ba52695f351b15792aed3e45984bc40f1fd267e5 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 1 Dec 2022 21:52:52 -0500 Subject: [PATCH] root directory option for downloader --- .env-download-job | 2 -- .../src/google_drive_download_command.rs | 29 ++++++++++--------- crates/service/download_job/src/main.rs | 4 +++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.env-download-job b/.env-download-job index def03d6262..032eac7e27 100644 --- a/.env-download-job +++ b/.env-download-job @@ -15,5 +15,3 @@ HIFIGAN_MODEL_CHECK_ROOT_DIRECTORY=/models/tts HIFIGAN_MODEL_CHECK_MAYBE_VENV_COMMAND="source python/bin/activate" HIFIGAN_MODEL_CHECK_COMMAND=./vocodes_model_check_hifigan.py HIFIGAN_MODEL_CHECK_MAYBE_DOCKER_IMAGE=5642d0fd7fc1 - - diff --git a/crates/lib/google_drive_common/src/google_drive_download_command.rs b/crates/lib/google_drive_common/src/google_drive_download_command.rs index cc7a05dd84..fe8774ec28 100644 --- a/crates/lib/google_drive_common/src/google_drive_download_command.rs +++ b/crates/lib/google_drive_common/src/google_drive_download_command.rs @@ -20,21 +20,29 @@ use tempdir::TempDir; /// --output_filename (local download filename) #[derive(Clone)] pub struct GoogleDriveDownloadCommand { + /// The python downloader script. download_script: String, + + /// If present, change to this directory before doing anything. + maybe_change_to_directory: Option, + + /// If a virtual environment is necessary, this is the name of the activation script (which will be sourced.) maybe_venv_activation_script: Option, - /// If this is run under Docker (eg. in development), these are the options. + /// If this is run under Docker (eg. in development), these are the options for Docker (GPU, mount, etc.) maybe_docker_options: Option, } impl GoogleDriveDownloadCommand { pub fn new( download_script: &str, + maybe_change_to_directory: Option<&str>, maybe_venv_activation_script: Option<&str>, maybe_docker_options: Option ) -> Self { Self { download_script: download_script.to_string(), + maybe_change_to_directory: maybe_change_to_directory.map(|s| s.to_string()), maybe_venv_activation_script: maybe_venv_activation_script.map(|s| s.to_string()), maybe_docker_options, } @@ -43,23 +51,12 @@ impl GoogleDriveDownloadCommand { pub fn new_production(download_script: &str) -> Self { Self { download_script: download_script.to_string(), + maybe_change_to_directory: None, maybe_venv_activation_script: None, maybe_docker_options: None, } } - pub fn new_local_dev_docker( - download_script: &str, - venv_activation_script: &str, - docker_options: DockerOptions - ) -> Self { - Self { - download_script: download_script.to_string(), - maybe_venv_activation_script: Some(venv_activation_script.to_string()), - maybe_docker_options: Some(docker_options), - } - } - /// Download file from Google Drive into the `TempDir`. /// Return the local filesystem filename. pub async fn download_file(&self, @@ -88,6 +85,12 @@ impl GoogleDriveDownloadCommand { &command); } + if let Some(change_to_directory) = self.maybe_change_to_directory.as_deref() { + command = format!("cd {} && {}", + change_to_directory, + &command); + } + if let Some(docker_options) = self.maybe_docker_options.as_ref() { command = docker_options.to_command_string(&command); } diff --git a/crates/service/download_job/src/main.rs b/crates/service/download_job/src/main.rs index 69e93aa06b..fe9117413d 100644 --- a/crates/service/download_job/src/main.rs +++ b/crates/service/download_job/src/main.rs @@ -95,6 +95,9 @@ async fn main() -> AnyhowResult<()> { // =============== Configure Python "Sidecars" =============== let google_drive_downloader = { + let maybe_root_directory = easyenv::get_env_string_optional( + "WEB_DOWNLOADER_MAYBE_ROOT_DIRECTORY"); + let downloader_command= easyenv::get_env_string_or_default( "WEB_DOWNLOADER_COMMAND", // TODO: Was "DOWNLOAD_SCRIPT" in old apps "./download_internet_file.py"); @@ -114,6 +117,7 @@ async fn main() -> AnyhowResult<()> { GoogleDriveDownloadCommand::new( &downloader_command, + maybe_root_directory.as_deref(), maybe_downloader_venv_script.as_deref(), docker_options, )