Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(convert_service): migrate to doppler (#4063)
Will Hutchinsonc48d03ec35df
diff --git a/.github/workspace-dep-closures.json b/.github/workspace-dep-closures.jsonindex d5d6d020ee..9c2556d545 100644--- a/.github/workspace-dep-closures.json+++ b/.github/workspace-dep-closures.json@@ -822,11 +822,14 @@"lambda_client","macro_auth","macro_aws_config",+ "macro_config",+ "macro_config_derive","macro_cors","macro_db_client","macro_entrypoint","macro_env","macro_env_var",+ "macro_env_vars/database_env_vars","macro_middleware","macro_user_id","macro_uuid",diff --git a/infra/stacks/convert-service/Pulumi.dev.yaml b/infra/stacks/convert-service/Pulumi.dev.yamlindex 613ea1beb1..f7691e6cdf 100644--- a/infra/stacks/convert-service/Pulumi.dev.yaml+++ b/infra/stacks/convert-service/Pulumi.dev.yaml@@ -2,4 +2,3 @@ config:aws-native:region: us-east-1aws:region: us-east-1convert-service:internal_api_key: document-storage-service-auth-key-dev- convert-service:macro_db_secret_key: macro-db-devdiff --git a/infra/stacks/convert-service/Pulumi.prod.yaml b/infra/stacks/convert-service/Pulumi.prod.yamlindex 5eed90ce2b..feb43b8dba 100644--- a/infra/stacks/convert-service/Pulumi.prod.yaml+++ b/infra/stacks/convert-service/Pulumi.prod.yaml@@ -2,4 +2,3 @@ config:aws-native:region: us-east-1aws:region: us-east-1convert-service:internal_api_key: document-storage-service-auth-key-prod- convert-service:macro_db_secret_key: macro-db-proddiff --git a/infra/stacks/convert-service/index.ts b/infra/stacks/convert-service/index.tsindex 05107584af..d20138009f 100644--- a/infra/stacks/convert-service/index.ts+++ b/infra/stacks/convert-service/index.ts@@ -26,22 +26,12 @@ const internalApiKeyArn: pulumi.Output<string> = aws.secretsmanager.getSecretVersionOutput({ secretId: INTERNAL_API_SECRET_KEY }).apply((secret) => secret.arn);-const DATABASE_URL = aws.secretsmanager- .getSecretVersionOutput({- secretId: config.require(`macro_db_secret_key`),- })- .apply((secret) => secret.secretString);-const secretKeyArns = [pulumi.interpolate`${internalApiKeyArn}`];const cloudStorageStack = new pulumi.StackReference('cloud-storage-stack', {name: `macro-inc/document-storage/${stack}`,});-const documentStorageBucketId: pulumi.Output<string> = cloudStorageStack- .getOutput('documentStorageBucketId')- .apply((id) => id as string);-const cloudStorageClusterArn: pulumi.Output<string> = cloudStorageStack.getOutput('cloudStorageClusterArn').apply((arn) => arn as string);@@ -71,38 +61,10 @@ export const jobUpdateHandlerLambdaName = jobUpdateHandlerLambdaArn.apply();let containerEnvVars = [- {- name: 'RUST_LOG',- value: `convert_service=${stack === 'prod' ? 'info' : 'debug'},tower_http=info`,- },{name: 'ENVIRONMENT',value: stack,},- {- name: 'INTERNAL_API_SECRET_KEY',- value: pulumi.interpolate`${INTERNAL_API_SECRET_KEY}`,- },- {- name: 'CONVERT_QUEUE',- value: pulumi.interpolate`${convertQueueName}`,- },- {- name: 'LOK_PATH',- value: '/app/lok/instdir/program',- },- {- name: 'DOCUMENT_STORAGE_BUCKET',- value: pulumi.interpolate`${documentStorageBucketId}`,- },- {- name: 'DATABASE_URL',- value: pulumi.interpolate`${DATABASE_URL}`,- },- {- name: 'WEB_SOCKET_RESPONSE_LAMBDA',- value: pulumi.interpolate`${jobUpdateHandlerLambdaName}`,- },// OpenTelemetry / Datadog tracing configuration{name: 'DD_SERVICE',diff --git a/infra/stacks/convert-service/service.ts b/infra/stacks/convert-service/service.tsindex f1a29cd29c..578a277157 100644--- a/infra/stacks/convert-service/service.ts+++ b/infra/stacks/convert-service/service.ts@@ -13,10 +13,11 @@ import { EcrImage } from '../../packages/service';import {BASE_DOMAIN,CLOUD_TRAIL_SNS_TOPIC_ARN,+ DopplerEcsEnvironment,stack,} from '../../packages/shared';-const BASE_NAME = 'convert-service';+const BASE_NAME = pulumi.getProject();const BASE_PATH = '../../../rust/cloud-storage';export const SERVICE_DOMAIN_NAME = `convert-service${stack === 'prod' ? '' : `-${stack}`@@ -205,6 +206,12 @@ export class ConvertService extends pulumi.ComponentResource {this.lb = lb;this.listener = listener;+ const dopplerEcsEnvironment = new DopplerEcsEnvironment(+ BASE_NAME,+ { tags: this.tags },+ { parent: this }+ );+// Fargate Serviceconst service = new awsx.ecs.FargateService(`${BASE_NAME}`,@@ -224,6 +231,9 @@ export class ConvertService extends pulumi.ComponentResource {taskRole: {roleArn: this.role.arn,},+ executionRole: {+ roleArn: dopplerEcsEnvironment.executionRole.arn,+ },containers: {log_router: fargateLogRouterSidecarContainer,datadog_agent: datadogAgentContainer,@@ -240,6 +250,7 @@ export class ConvertService extends pulumi.ComponentResource {value: this.domain,},],+ secrets: [...dopplerEcsEnvironment.containerSecrets],logConfiguration: {logDriver: 'awsfirelens',options: {diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 06d4f0264a..2463c2d1c9 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -2646,14 +2646,17 @@ dependencies = ["aws-sdk-secretsmanager","aws-sdk-sqs","axum",+ "database_env_vars","futures","http-body-util","lambda_client","macro_aws_config",+ "macro_config","macro_cors","macro_db_client","macro_entrypoint","macro_env",+ "macro_env_var","macro_middleware","macro_uuid","model",diff --git a/rust/cloud-storage/convert_service/Cargo.toml b/rust/cloud-storage/convert_service/Cargo.tomlindex 57f107fc6f..59db50fbf4 100644--- a/rust/cloud-storage/convert_service/Cargo.toml+++ b/rust/cloud-storage/convert_service/Cargo.toml@@ -16,14 +16,17 @@ aws-sdk-s3 = { workspace = true }aws-sdk-secretsmanager = { workspace = true }aws-sdk-sqs = { workspace = true }axum = { workspace = true }+database_env_vars = { path = "../macro_env_vars/database_env_vars" }futures = { workspace = true }http-body-util = { workspace = true }lambda_client = { path = "../lambda_client" }macro_aws_config = { path = "../macro_aws_config", features = ["s3"] }macro_cors = { path = "../macro_cors" }+macro_config = { path = "../macro_config" }macro_db_client = { path = "../macro_db_client" }macro_entrypoint = { path = "../macro_entrypoint" }macro_env = { path = "../macro_env" }+macro_env_var = { path = "../macro_env_var" }macro_middleware = { path = "../macro_middleware", default-features = false, features = ["auth",] }diff --git a/rust/cloud-storage/convert_service/src/api/backfill/backfill_docx.rs b/rust/cloud-storage/convert_service/src/api/backfill/backfill_docx.rsindex ce0f531c77..b14016a399 100644--- a/rust/cloud-storage/convert_service/src/api/backfill/backfill_docx.rs+++ b/rust/cloud-storage/convert_service/src/api/backfill/backfill_docx.rs@@ -65,7 +65,7 @@ pub async fn handler(let chunk_result = futures::stream::iter(chunk.iter()).then(|doc| {let s3_client = ctx.s3_client.clone();- let document_storage_bucket = ctx.config.document_storage_bucket.clone();+ let document_storage_bucket = ctx.config.document_storage_bucket.to_string();async move { process_docx(&s3_client, &document_storage_bucket, doc).await }})diff --git a/rust/cloud-storage/convert_service/src/config.rs b/rust/cloud-storage/convert_service/src/config.rsindex 2db11f528c..03ab985f11 100644--- a/rust/cloud-storage/convert_service/src/config.rs+++ b/rust/cloud-storage/convert_service/src/config.rs@@ -1,13 +1,28 @@-use anyhow::Context;-use macro_env::Environment;use std::sync::LazyLock;+use anyhow::Context;+use database_env_vars::DatabaseUrl;+pub use macro_env::Environment;+use macro_env_var::env_vars;+/// The path to the LibreOffice binary-pub static LOK_PATH: LazyLock<String> = LazyLock::new(|| std::env::var("LOK_PATH").unwrap());+pub static LOK_PATH: LazyLock<String> = LazyLock::new(|| {+ macro_config::required_config_value("LOK_PATH")+ .expect("LOK_PATH must be provided via APP_SECRETS_JSON or env")+});/// The websocket response lambda-pub static WEB_SOCKET_RESPONSE_LAMBDA: LazyLock<String> =- LazyLock::new(|| std::env::var("WEB_SOCKET_RESPONSE_LAMBDA").unwrap());+pub static WEB_SOCKET_RESPONSE_LAMBDA: LazyLock<String> = LazyLock::new(|| {+ macro_config::required_config_value("WEB_SOCKET_RESPONSE_LAMBDA")+ .expect("WEB_SOCKET_RESPONSE_LAMBDA must be provided via APP_SECRETS_JSON or env")+});++env_vars! {+ pub struct ConvertQueue;+ pub struct LokPath;+ pub struct DocumentStorageBucket;+ pub struct WebSocketResponseLambda;+}/// The configuration parameters for the application.///@@ -16,77 +31,42 @@ pub static WEB_SOCKET_RESPONSE_LAMBDA: LazyLock<String> =/// populate the Docker container////// See `.env.sample` in document-storage-service root for details.+#[derive(macro_config::MacroConfig)]+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]pub struct Config {/// The SQS queue for convert jobs- pub convert_queue: String,+ pub convert_queue: ConvertQueue,/// The queue max messages per poll+ #[macro_config_default(5)]pub queue_max_messages: i32,/// The queue wait time seconds+ #[macro_config_default(5)]pub queue_wait_time_seconds: i32,/// The path to the LibreOffice binary- #[allow(dead_code)]- pub lok_path: String,+ pub lok_path: LokPath,/// The url of macrodb- pub database_url: String,+ pub database_url: DatabaseUrl,/// The name of the document storage bucket- pub document_storage_bucket: String,+ pub document_storage_bucket: DocumentStorageBucket,/// The lambda function to send job responses to for conversion#[allow(dead_code)]- pub web_socket_response_lambda: String,+ pub web_socket_response_lambda: WebSocketResponseLambda,/// The port to listen for HTTP requests on.+ #[macro_config_default(8080)]pub port: usize,/// The environment we are in+ #[macro_config_default(Environment::new_or_prod())]pub environment: Environment,}impl Config {pub fn from_env() -> anyhow::Result<Self> {- let port: usize = std::env::var("PORT")- .unwrap_or("8080".to_string())- .parse::<usize>()- .context("should be valid port number")?;-- let convert_queue =- std::env::var("CONVERT_QUEUE").context("CONVERT_QUEUE must be provided")?;-- let queue_max_messages: i32 = std::env::var("QUEUE_MAX_MESSAGES")- .unwrap_or("5".to_string()) // For the convert queue, we can safely handle ~5 conversions at a time- .parse::<i32>()- .unwrap();-- let queue_wait_time_seconds: i32 = std::env::var("QUEUE_WAIT_TIME_SECONDS")- .unwrap_or("5".to_string())- .parse::<i32>()- .unwrap();-- let lok_path = std::env::var("LOK_PATH").context("LOK_PATH must be provided")?;-- let database_url =- std::env::var("DATABASE_URL").context("DATABASE_URL must be provided")?;-- let document_storage_bucket = std::env::var("DOCUMENT_STORAGE_BUCKET")- .context("DOCUMENT_STORAGE_BUCKET must be provided")?;-- let web_socket_response_lambda = std::env::var("WEB_SOCKET_RESPONSE_LAMBDA")- .context("WEB_SOCKET_RESPONSE_LAMBDA must be provided")?;-- let environment = Environment::new_or_prod();-- Ok(Config {- convert_queue,- queue_max_messages,- queue_wait_time_seconds,- lok_path,- database_url,- document_storage_bucket,- web_socket_response_lambda,- port,- environment,- })+ macro_config::ConfigLoader::load::<Config>()+ .context("failed to load convert service config")}}diff --git a/rust/cloud-storage/convert_service/src/main.rs b/rust/cloud-storage/convert_service/src/main.rsindex 68284c2da6..b43b5df0b0 100644--- a/rust/cloud-storage/convert_service/src/main.rs+++ b/rust/cloud-storage/convert_service/src/main.rs@@ -1,9 +1,8 @@#![recursion_limit = "256"]use crate::api::context::ApiContext;use anyhow::Context;-use config::Config;+use config::{Config, Environment};use macro_entrypoint::MacroEntrypoint;-use macro_env::Environment;use macro_middleware::auth::internal_access::InternalApiSecretKey;use process::runner::run_worker;use secretsmanager_client::SecretManager;@@ -62,8 +61,10 @@ async fn main() -> anyhow::Result<()> {let env = Environment::new_or_prod();MacroEntrypoint::new(env).init();- let lok_path = std::env::var("LOK_PATH").context("LOK_PATH must be provided")?;- smoke_test_lok(&lok_path)?;+ // Parse our configuration from the environment.+ let config = Config::from_env().context("expected to be able to generate config")?;++ smoke_test_lok(&config.lok_path)?;let aws_config = macro_aws_config::get_macro_aws_config().await;@@ -72,12 +73,9 @@ async fn main() -> anyhow::Result<()> {);let internal_auth_key = secretsmanager_client- .get_maybe_secret_value(env, InternalApiSecretKey::new()?)+ .get_maybe_secret_value(config.environment, InternalApiSecretKey::new()?).await?;- // Parse our configuration from the environment.- let config = Config::from_env().context("expected to be able to generate config")?;-let db = PgPoolOptions::new().min_connections(1).max_connections(5)@@ -100,7 +98,7 @@ async fn main() -> anyhow::Result<()> {let sqs_client = aws_sdk_sqs::Client::new(&queue_aws_config);let sqs_worker = sqs_worker::SQSWorker::new(sqs_client,- config.convert_queue.clone(),+ config.convert_queue.to_string(),config.queue_max_messages,config.queue_wait_time_seconds,);