diff --git a/Dockerfile b/Dockerfile index a38e1580..de8b7272 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,4 +40,10 @@ RUN apt-get update -y \ COPY --from=builder /app/target/release/appflowy_cloud /usr/local/bin/appflowy_cloud ENV APP_ENVIRONMENT production ENV RUST_BACKTRACE 1 + +ARG APPFLOWY_APPLICATION_PORT +ARG PORT +ENV PORT=${APPFLOWY_APPLICATION_PORT:-${PORT:-8000}} +EXPOSE $PORT + CMD ["appflowy_cloud"] diff --git a/admin_frontend/Dockerfile b/admin_frontend/Dockerfile index 1203ca72..c2c28daa 100644 --- a/admin_frontend/Dockerfile +++ b/admin_frontend/Dockerfile @@ -40,4 +40,10 @@ COPY --from=builder /app/target/release/admin_frontend /usr/local/bin/admin_fron COPY --from=builder /app/admin_frontend/assets /app/assets ENV RUST_BACKTRACE 1 ENV RUST_LOG info + +ARG ADMIN_FRONTEND_PORT +ARG PORT +ENV PORT=${ADMIN_FRONTEND_PORT:-${PORT:-3000}} +EXPOSE $PORT + CMD ["admin_frontend"] diff --git a/admin_frontend/src/config.rs b/admin_frontend/src/config.rs index 057dc326..f9326e82 100644 --- a/admin_frontend/src/config.rs +++ b/admin_frontend/src/config.rs @@ -2,21 +2,26 @@ use tracing::warn; #[derive(Debug, Clone)] pub struct Config { + pub host: String, + pub port: u16, pub redis_url: String, pub gotrue_url: String, pub appflowy_cloud_url: String, } impl Config { - pub fn from_env() -> Self { - Config { + pub fn from_env() -> Result { + let cfg = Config { + host: get_or_default("ADMIN_FRONTEND_HOST", "0.0.0.0"), + port: get_or_default("ADMIN_FRONTEND_PORT", "3000").parse()?, redis_url: get_or_default("ADMIN_FRONTEND_REDIS_URL", "redis://localhost:6379"), gotrue_url: get_or_default("ADMIN_FRONTEND_GOTRUE_URL", "http://localhost:9999"), appflowy_cloud_url: get_or_default( "ADMIN_FRONTEND_APPFLOWY_CLOUD_URL", "http://localhost:8000", ), - } + }; + Ok(cfg) } } diff --git a/admin_frontend/src/main.rs b/admin_frontend/src/main.rs index 229ab9b3..cdf845ba 100644 --- a/admin_frontend/src/main.rs +++ b/admin_frontend/src/main.rs @@ -27,7 +27,7 @@ async fn main() { .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .init(); - let config = Config::from_env(); + let config = Config::from_env().unwrap(); info!("config loaded: {:?}", &config); let gotrue_client = gotrue::api::Client::new(reqwest::Client::new(), &config.gotrue_url); @@ -65,7 +65,8 @@ async fn main() { .nest_service("/web-api", web_api_router) .nest_service("/assets", ServeDir::new("assets")); - let listener = TcpListener::bind("0.0.0.0:3000") + let address = format!("{}:{}", config.host, config.port); + let listener = TcpListener::bind(address) .await .expect("failed to bind to port"); info!("listening on: {:?}", listener);