You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by cr...@apache.org on 2020/03/13 16:26:14 UTC

[incubator-superset] branch master updated: Docker-Compose Memory Issue Fix? (#9285)

This is an automated email from the ASF dual-hosted git repository.

craigrueda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new e9b0095  Docker-Compose Memory Issue Fix? (#9285)
e9b0095 is described below

commit e9b0095754d130df30c25d0c64d78cadbfe595ca
Author: Craig Rueda <cr...@craigrueda.com>
AuthorDate: Fri Mar 13 09:25:54 2020 -0700

    Docker-Compose Memory Issue Fix? (#9285)
    
    * Adding free memory nag / running npm build with development options in compose
    
    * Adding license
---
 Dockerfile                     |  9 ++++++--
 docker-compose.yml             |  2 ++
 docker/frontend-mem-nag.sh     | 49 ++++++++++++++++++++++++++++++++++++++++++
 superset-frontend/package.json |  1 +
 4 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 33be492..9f14b07 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -41,18 +41,23 @@ RUN cd /app \
 ######################################################################
 FROM node:10-jessie AS superset-node
 
+ARG NPM_BUILD_CMD="build"
+ENV BUILD_CMD=${NPM_BUILD_CMD}
+
 # NPM ci first, as to NOT invalidate previous steps except for when package.json changes
 RUN mkdir -p /app/superset-frontend
 RUN mkdir -p /app/superset/assets
+COPY ./docker/frontend-mem-nag.sh /
 COPY ./superset-frontend/package* /app/superset-frontend/
-RUN cd /app/superset-frontend \
+RUN /frontend-mem-nag.sh \
+        && cd /app/superset-frontend \
         && npm ci
 
 # Next, copy in the rest and let webpack do its thing
 COPY ./superset-frontend /app/superset-frontend
 # This is BY FAR the most expensive step (thanks Terser!)
 RUN cd /app/superset-frontend \
-        && npm run build \
+        && npm run ${BUILD_CMD} \
         && rm -rf node_modules
 
 
diff --git a/docker-compose.yml b/docker-compose.yml
index 16deb6a..9f2e2d1 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -15,6 +15,8 @@
 # limitations under the License.
 #
 x-superset-build: &superset-build
+  args:
+    NPM_BUILD_CMD: build-dev
   context: ./
   dockerfile: Dockerfile
   target: dev
diff --git a/docker/frontend-mem-nag.sh b/docker/frontend-mem-nag.sh
new file mode 100755
index 0000000..4051721
--- /dev/null
+++ b/docker/frontend-mem-nag.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -e
+
+# We need at least 3GB of free mem...
+MIN_MEM_FREE_GB=3
+MIN_MEM_FREE_KB=$(($MIN_MEM_FREE_GB*1000000))
+
+echo_mem_warn() {
+  MEM_FREE_KB=$(awk '/MemFree/ { printf "%s \n", $2 }' /proc/meminfo)
+  MEM_FREE_GB=$(awk '/MemFree/ { printf "%s \n", $2/1024/1024 }' /proc/meminfo)
+
+  if [[ "${MEM_FREE_KB}" -lt "${MIN_MEM_FREE_KB}" ]]; then
+    cat <<EOF
+    ===============================================
+    ========  Memory Insufficient Warning =========
+    ===============================================
+
+    It looks like you only have ${MEM_FREE_GB}GB of
+    memory free. Please increase your Docker
+    resources to at least ${MIN_MEM_FREE_GB}GB
+
+    ===============================================
+    ========  Memory Insufficient Warning =========
+    ===============================================
+EOF
+  else
+    echo "Memory check Ok [${MEM_FREE_GB}GB free]"
+  fi
+}
+
+# Always nag if they're low on mem...
+echo_mem_warn
diff --git a/superset-frontend/package.json b/superset-frontend/package.json
index 90579c0..323c19f 100644
--- a/superset-frontend/package.json
+++ b/superset-frontend/package.json
@@ -14,6 +14,7 @@
     "dev": "webpack --mode=development --colors --progress --debug --watch",
     "dev-server": "node --max_old_space_size=4096 ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --mode=development --progress",
     "prod": "node --max_old_space_size=4096 ./node_modules/webpack/bin/webpack.js --mode=production --colors --progress",
+    "build-dev": "cross-env NODE_OPTIONS=--max_old_space_size=8192 NODE_ENV=development webpack --mode=development --colors --progress",
     "build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 NODE_ENV=production webpack --mode=production --colors --progress",
     "lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx,.ts,.tsx .",
     "lint-fix": "eslint --fix --ignore-path=.eslintignore --ext .js,.jsx,.ts,tsx . && npm run clean-css",