From 7b9c85b1a25d190cc096402f45a42317ef21fb47 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Thu, 3 Aug 2023 09:16:17 +0000 Subject: [PATCH 1/3] Optimize: Avoid Chromium redundancy (Docker) --- Dockerfile | 2 +- metagpt/utils/mermaid.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e8f717b7c..2000b49a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apt update &&\ # Install Mermaid CLI globally ENV CHROME_BIN="/usr/bin/chromium" \ - AM_I_IN_A_DOCKER_CONTAINER="true" + PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" RUN npm install -g @mermaid-js/mermaid-cli &&\ npm cache clean --force diff --git a/metagpt/utils/mermaid.py b/metagpt/utils/mermaid.py index 3850faae3..0fbc9f621 100644 --- a/metagpt/utils/mermaid.py +++ b/metagpt/utils/mermaid.py @@ -13,7 +13,7 @@ from metagpt.const import PROJECT_ROOT from metagpt.logs import logger from metagpt.utils.common import check_cmd_exists -IS_DOCKER = os.environ.get('AM_I_IN_A_DOCKER_CONTAINER', 'false').lower() +IS_DOCKER = os.environ.get('PUPPETEER_SKIP_CHROMIUM_DOWNLOAD', 'false').lower() def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height=2048) -> int: From 1c3a714ad34a297cd478434d50369c4823d52270 Mon Sep 17 00:00:00 2001 From: "hy.li" Date: Thu, 3 Aug 2023 19:31:21 +0800 Subject: [PATCH 2/3] new env:NO_GUI --- Dockerfile | 1 + metagpt/utils/mermaid.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2000b49a3..7c13edc50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN apt update &&\ # Install Mermaid CLI globally ENV CHROME_BIN="/usr/bin/chromium" \ + NO_GUI="true"\ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" RUN npm install -g @mermaid-js/mermaid-cli &&\ npm cache clean --force diff --git a/metagpt/utils/mermaid.py b/metagpt/utils/mermaid.py index 0fbc9f621..406ad00ee 100644 --- a/metagpt/utils/mermaid.py +++ b/metagpt/utils/mermaid.py @@ -13,7 +13,7 @@ from metagpt.const import PROJECT_ROOT from metagpt.logs import logger from metagpt.utils.common import check_cmd_exists -IS_DOCKER = os.environ.get('PUPPETEER_SKIP_CHROMIUM_DOWNLOAD', 'false').lower() +IS_DOCKER = os.environ.get('NO_GUI', 'false').lower() def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height=2048) -> int: From e48ecfd9fd227bae432ee3756b709f60ea929d7f Mon Sep 17 00:00:00 2001 From: "hy.li" Date: Fri, 4 Aug 2023 16:32:43 +0800 Subject: [PATCH 3/3] remove:NO_GUI, IS_DOCKER --- Dockerfile | 2 +- metagpt/utils/mermaid.py | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7c13edc50..520d6517d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apt update &&\ # Install Mermaid CLI globally ENV CHROME_BIN="/usr/bin/chromium" \ - NO_GUI="true"\ + PUPPETEER_CONFIG="/app/metagpt/config/puppeteer-config.json"\ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" RUN npm install -g @mermaid-js/mermaid-cli &&\ npm cache clean --force diff --git a/metagpt/utils/mermaid.py b/metagpt/utils/mermaid.py index 406ad00ee..3788b4743 100644 --- a/metagpt/utils/mermaid.py +++ b/metagpt/utils/mermaid.py @@ -13,8 +13,6 @@ from metagpt.const import PROJECT_ROOT from metagpt.logs import logger from metagpt.utils.common import check_cmd_exists -IS_DOCKER = os.environ.get('NO_GUI', 'false').lower() - def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height=2048) -> int: """suffix: png/svg/pdf @@ -38,16 +36,13 @@ def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height output_file = f'{output_file_without_suffix}.{suffix}' # Call the `mmdc` command to convert the Mermaid code to a PNG logger.info(f"Generating {output_file}..") - if IS_DOCKER == 'true': - subprocess.run(['mmdc', '-p', '/app/metagpt/config/puppeteer-config.json', '-i', - str(tmp), '-o', output_file, '-w', str(width), '-H', str(height)]) + + if CONFIG.puppeteer_config: + subprocess.run([CONFIG.mmdc, '-p', CONFIG.puppeteer_config, '-i', str(tmp), '-o', + output_file, '-w', str(width), '-H', str(height)]) else: - if CONFIG.puppeteer_config: - subprocess.run([CONFIG.mmdc, '-p', CONFIG.puppeteer_config, '-i', str(tmp), '-o', - output_file, '-w', str(width), '-H', str(height)]) - else: - subprocess.run([CONFIG.mmdc, '-i', str(tmp), '-o', - output_file, '-w', str(width), '-H', str(height)]) + subprocess.run([CONFIG.mmdc, '-i', str(tmp), '-o', + output_file, '-w', str(width), '-H', str(height)]) return 0