You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2024/05/31 00:24:35 UTC

(superset) branch docker-compose-mem created (now 5e11a08139)

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

maximebeauchemin pushed a change to branch docker-compose-mem
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 5e11a08139 feat: skip `npm run build` in docker-compose

This branch includes the following new commits:

     new 5e11a08139 feat: skip `npm run build` in docker-compose

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: feat: skip `npm run build` in docker-compose

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch docker-compose-mem
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 5e11a081392a16cae5fc8ec96f97a383f7a1bbd2
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Thu May 30 16:45:33 2024 -0700

    feat: skip `npm run build` in docker-compose
    
    When using docker-compose, we mount the local drive and fire up a `npm run dev` which is effectively webpack in --watch mode, so that it looks for changes in frontend files and compiles-as-you-change interactively.
    
    Now, somehow `npm run build` is in the Dockerfile, specifically in the superset-node layer which is used to compile and later COPY the static assets into a python-based layer, `lean`.
    
    Now in the context of docker-compose, we don't need all of it, and that `npm run build` has gotten expensive in terms of memory usage and takes a while to run.
    
    So in this PR I'm:
    - making `npm run build` optional with a dockerfile ARG (default is current behavior, but docker-compose skips it)
    - adding a `superset-node-base` layer for that superset-node service in docker-compose that runs `npm run dev`, ensuring the same base for both processes, but stopping/diverging prior to `npm ci`
    - making `npm install` run only if node_module is not present in the superset-node service. The user can simply `npm i` locally if/when they alter package.json. That speeds up firing up `docker-compose up` as unless you nuke node_modules/ it'll skip that step
---
 Dockerfile                          | 13 +++++++++++--
 docker-compose.yml                  |  8 +++++++-
 docker/docker-frontend.sh           |  5 ++---
 superset-frontend/webpack.config.js |  2 +-
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index fb8cb826a5..b165e45898 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -20,9 +20,12 @@
 ######################################################################
 ARG PY_VER=3.10-slim-bookworm
 
+# For development purposes, we can skip the node build stage
+ARG INCLUDE_NODE=true
+
 # if BUILDPLATFORM is null, set it to 'amd64' (or leave as is otherwise).
 ARG BUILDPLATFORM=${BUILDPLATFORM:-amd64}
-FROM --platform=${BUILDPLATFORM} node:18-bullseye-slim AS superset-node
+FROM --platform=${BUILDPLATFORM} node:18-bullseye-slim AS superset-node-base
 
 ARG NPM_BUILD_CMD="build"
 
@@ -39,6 +42,8 @@ WORKDIR /app/superset-frontend
 RUN --mount=type=bind,target=/frontend-mem-nag.sh,src=./docker/frontend-mem-nag.sh \
     /frontend-mem-nag.sh
 
+FROM superset-node-pre-build AS superset-node
+
 RUN --mount=type=bind,target=./package.json,src=./superset-frontend/package.json \
     --mount=type=bind,target=./package-lock.json,src=./superset-frontend/package-lock.json \
     npm ci
@@ -87,7 +92,11 @@ RUN --mount=type=cache,target=/root/.cache/pip \
     && apt-get autoremove -yqq --purge build-essential \
     && rm -rf /var/lib/apt/lists/*
 
-COPY --chown=superset:superset --from=superset-node /app/superset/static/assets superset/static/assets
+# Conditionally copy from the superset-node stage if INCLUDE_NODE is true
+RUN if [ "${INCLUDE_NODE}" = "true" ]; then \
+      COPY --chown=superset:superset --from=superset-node /app/superset/static/assets superset/static/assets; \
+    fi
+
 ## Lastly, let's install superset itself
 COPY --chown=superset:superset superset superset
 RUN --mount=type=cache,target=/root/.cache/pip \
diff --git a/docker-compose.yml b/docker-compose.yml
index de0f12db2e..17d4b5c773 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -38,6 +38,8 @@ x-common-build: &common-build
   target: dev
   cache_from:
     - apache/superset-cache:3.10-slim-bookworm
+  args:
+    INCLUDE_NODE: false
 
 services:
   nginx:
@@ -147,7 +149,11 @@ services:
       disable: true
 
   superset-node:
-    image: node:18
+    build:
+      context: .
+      target: superset-node-base
+      cache_from:
+        - type=registry,ref=apache/superset-cache:3.10-slim-bookworm
     environment:
       # set this to false if you have perf issues running the npm i; npm run dev in-docker
       # if you do so, you have to run this manually on the host, which should perform better!
diff --git a/docker/docker-frontend.sh b/docker/docker-frontend.sh
index c69fefd6d0..37ecbdc7f1 100755
--- a/docker/docker-frontend.sh
+++ b/docker/docker-frontend.sh
@@ -25,10 +25,9 @@ fi
 
 if [ "$BUILD_SUPERSET_FRONTEND_IN_DOCKER" = "true" ]; then
     cd /app/superset-frontend
-    npm install -f --no-optional --global webpack webpack-cli
-    npm install -f --no-optional
+    RUN if [ ! -d "node_modules" ]; then npm install; fi
 
-    echo "Running frontend"
+    echo "Running webpack in watch mode..."
     npm run dev
 else
     echo "Skipping frontend build steps - YOU RUN IT MANUALLY ON THE HOST!"
diff --git a/superset-frontend/webpack.config.js b/superset-frontend/webpack.config.js
index 118731754e..fb04a65dc5 100644
--- a/superset-frontend/webpack.config.js
+++ b/superset-frontend/webpack.config.js
@@ -496,7 +496,7 @@ const config = {
     'react/lib/ReactContext': true,
   },
   plugins,
-  devtool: 'source-map',
+  devtool: isDevMode ? 'source-map' : false,
 };
 
 // find all the symlinked plugins and use their source code for imports