From 49133b0ac9bef3d09e0e36230835e72339356b26 Mon Sep 17 00:00:00 2001 From: George Leung Date: Tue, 8 Oct 2024 13:41:20 -0400 Subject: [PATCH] generate infra map on build (#1813) --- apps/framework-cli/src/cli.rs | 2 +- .../src/cli/routines/docker_packager.rs | 39 ++++++++++++++++++- .../src/framework/core/infrastructure_map.rs | 13 +++++++ apps/framework-cli/src/framework/core/plan.rs | 10 ++++- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/apps/framework-cli/src/cli.rs b/apps/framework-cli/src/cli.rs index d29507628..c67a64afd 100644 --- a/apps/framework-cli/src/cli.rs +++ b/apps/framework-cli/src/cli.rs @@ -302,7 +302,7 @@ async fn top_command_handler( // TODO get rid of the routines and use functions instead create_dockerfile(&project_arc)?.show(); - let _ = build_dockerfile(&project_arc, *amd64, *arm64)?; + let _: RoutineSuccess = build_dockerfile(&project_arc, *amd64, *arm64).await?; wait_for_usage_capture(capture_handle).await; diff --git a/apps/framework-cli/src/cli/routines/docker_packager.rs b/apps/framework-cli/src/cli/routines/docker_packager.rs index dde71ffdf..71352aa14 100644 --- a/apps/framework-cli/src/cli/routines/docker_packager.rs +++ b/apps/framework-cli/src/cli/routines/docker_packager.rs @@ -1,6 +1,8 @@ use super::{RoutineFailure, RoutineSuccess}; use crate::cli::display::with_spinner; use crate::cli::routines::util::ensure_docker_running; +use crate::framework::core::infrastructure_map::InfrastructureMap; +use crate::framework::core::primitive_map::PrimitiveMap; use crate::framework::languages::SupportedLanguages; use crate::utilities::constants::{ APP_DIR, CLI_INTERNAL_VERSIONS_DIR, OLD_PROJECT_CONFIG_FILE, PACKAGE_JSON, PROJECT_CONFIG_FILE, @@ -73,6 +75,8 @@ COPY --chown=moose:moose ./project.tom[l] ./project.toml COPY --chown=moose:moose ./moose.config.tom[l] ./moose.config.toml COPY --chown=moose:moose ./versions .moose/versions +COPY --chown=moose:moose ./infrastructure_map.json .moose/infrastructure_map.json + # Placeholder for the language specific install command INSTALL_COMMAND @@ -174,7 +178,7 @@ pub fn create_dockerfile(project: &Project) -> Result Result<(), std::io::Error> { + let json = serde_json::to_string(self)?; + fs::write(path, json) + } + + pub fn load_from_json(path: &Path) -> Result { + let json = fs::read_to_string(path)?; + let infra_map = serde_json::from_str(&json)?; + Ok(infra_map) + } } #[cfg(test)] diff --git a/apps/framework-cli/src/framework/core/plan.rs b/apps/framework-cli/src/framework/core/plan.rs index 28ff39bf0..122a833d6 100644 --- a/apps/framework-cli/src/framework/core/plan.rs +++ b/apps/framework-cli/src/framework/core/plan.rs @@ -12,6 +12,7 @@ use crate::{ use clickhouse_rs::ClientHandle; use rdkafka::error::KafkaError; use std::collections::HashMap; +use std::path::Path; #[derive(Debug, thiserror::Error)] pub enum PlanningError { @@ -43,8 +44,13 @@ pub async fn plan_changes( client: &mut ClientHandle, project: &Project, ) -> Result { - let primitive_map = PrimitiveMap::load(project).await?; - let target_infra_map = InfrastructureMap::new(primitive_map); + let target_infra_map = if project.is_production { + let json_path = Path::new(".moose/infrastructure_map.json"); + InfrastructureMap::load_from_json(json_path).map_err(|e| PlanningError::Other(e.into()))? + } else { + let primitive_map = PrimitiveMap::load(project).await?; + InfrastructureMap::new(primitive_map) + }; let current_infra_map = { // in the rest of this block of code,