diff --git a/Dockerfile b/Dockerfile index 33be492299..9f14b07aaa 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 16deb6a909..9f2e2d1e4d 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 0000000000..40517216b6 --- /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 <