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 2025/01/29 02:54:22 UTC
(superset) branch docker_plus_plus created (now 062e935768)
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a change to branch docker_plus_plus
in repository https://gitbox.apache.org/repos/asf/superset.git
at 062e935768 feat: improve docker images to support running in userspace
This branch includes the following new commits:
new 062e935768 feat: improve docker images to support running in userspace
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: improve docker images to support running in userspace
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch docker_plus_plus
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 062e935768e2381755f7ac92ef56e2b00006ea24
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Mon Jan 27 23:59:18 2025 -0800
feat: improve docker images to support running in userspace
Recently realized that running docker-compose as `superset` didn't work out of the image box. docker-compose.yml sets `root` as the user, and when switching to user `superset`, there were some permission issues around excecuting certain scripts and such.
Here I'm fixing up some things, paying attention to a few layers, and avoiding doing any sorts of installation of anything while starting the app as the `superset` user.
---
.gitignore | 1 +
Dockerfile | 73 +++++++++++++++++++++--------------------
docker-compose.yml | 5 +--
docker/docker-bootstrap.sh | 8 +++--
docker/entrypoints/docker-ci.sh | 2 +-
5 files changed, 48 insertions(+), 41 deletions(-)
diff --git a/.gitignore b/.gitignore
index 2652502a02..67bc771f84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -124,3 +124,4 @@ docker/*local*
# Jest test report
test-report.html
superset/static/stats/statistics.html
+.aider*
diff --git a/Dockerfile b/Dockerfile
index 76983ae773..54537b3f7f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -76,8 +76,7 @@ COPY superset-frontend /app/superset-frontend
FROM superset-node-ci AS superset-node
# Build the frontend if not in dev mode
-RUN --mount=type=cache,target=/app/superset-frontend/.temp_cache \
- --mount=type=cache,target=/root/.npm \
+RUN --mount=type=cache,target=$/root/.npm \
if [ "$DEV_MODE" = "false" ]; then \
echo "Running 'npm run ${BUILD_CMD}'"; \
npm run ${BUILD_CMD}; \
@@ -100,21 +99,14 @@ RUN if [ "$BUILD_TRANSLATIONS" = "true" ]; then \
# Base python layer
######################################################################
FROM python:${PY_VER} AS python-base
-ARG BUILD_TRANSLATIONS="false" # Include translations in the final build
-ENV BUILD_TRANSLATIONS=${BUILD_TRANSLATIONS}
-ARG DEV_MODE="false" # Skip frontend build in dev mode
-ENV DEV_MODE=${DEV_MODE}
-
-ENV LANG=C.UTF-8 \
- LC_ALL=C.UTF-8 \
- SUPERSET_ENV=production \
- FLASK_APP="superset.app:create_app()" \
- PYTHONPATH="/app/pythonpath" \
- SUPERSET_HOME="/app/superset_home" \
- SUPERSET_PORT=8088
+ARG SUPERSET_HOME="/app/superset_home"
+ENV SUPERSET_HOME=${SUPERSET_HOME}
-RUN useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset
+RUN mkdir -p $SUPERSET_HOME
+RUN useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset \
+ && chmod -R 1777 $SUPERSET_HOME \
+ && chown -R superset:superset $SUPERSET_HOME
# Some bash scripts needed throughout the layers
COPY --chmod=755 docker/*.sh /app/docker/
@@ -125,19 +117,6 @@ RUN pip install --no-cache-dir --upgrade uv
RUN uv venv /app/.venv
ENV PATH="/app/.venv/bin:${PATH}"
-# Install Playwright and optionally setup headless browsers
-ARG INCLUDE_CHROMIUM="true"
-ARG INCLUDE_FIREFOX="false"
-RUN --mount=type=cache,target=/root/.cache/uv\
- if [ "$INCLUDE_CHROMIUM" = "true" ] || [ "$INCLUDE_FIREFOX" = "true" ]; then \
- uv pip install playwright && \
- playwright install-deps && \
- if [ "$INCLUDE_CHROMIUM" = "true" ]; then playwright install chromium; fi && \
- if [ "$INCLUDE_FIREFOX" = "true" ]; then playwright install firefox; fi; \
- else \
- echo "Skipping browser installation"; \
- fi
-
######################################################################
# Python translation compiler layer
######################################################################
@@ -145,7 +124,7 @@ FROM python-base AS python-translation-compiler
# Install Python dependencies using docker/pip-install.sh
COPY requirements/translations.txt requirements/
-RUN --mount=type=cache,target=/root/.cache/uv \
+RUN --mount=type=cache,target=${SUPERSET_HOME}/.cache/uv \
/app/docker/pip-install.sh --requires-build-essential -r requirements/translations.txt
COPY superset/translations/ /app/translations_mo/
@@ -159,13 +138,20 @@ RUN if [ "$BUILD_TRANSLATIONS" = "true" ]; then \
# Python APP common layer
######################################################################
FROM python-base AS python-common
+
+ENV SUPERSET_HOME="/app/superset_home" \
+ HOME="/app/superset_home" \
+ SUPERSET_ENV="production" \
+ FLASK_APP="superset.app:create_app()" \
+ PYTHONPATH="/app/pythonpath" \
+ SUPERSET_PORT="8088"
+
# Copy the entrypoints, make them executable in userspace
COPY --chmod=755 docker/entrypoints /app/docker/entrypoints
WORKDIR /app
# Set up necessary directories and user
RUN mkdir -p \
- ${SUPERSET_HOME} \
${PYTHONPATH} \
superset/static \
requirements \
@@ -174,6 +160,19 @@ RUN mkdir -p \
requirements \
&& touch superset/static/version_info.json
+# Install Playwright and optionally setup headless browsers
+ARG INCLUDE_CHROMIUM="true"
+ARG INCLUDE_FIREFOX="false"
+RUN --mount=type=cache,target=${SUPERSET_HOME}/.cache/uv \
+ if [ "$INCLUDE_CHROMIUM" = "true" ] || [ "$INCLUDE_FIREFOX" = "true" ]; then \
+ uv pip install playwright && \
+ playwright install-deps && \
+ if [ "$INCLUDE_CHROMIUM" = "true" ]; then playwright install chromium; fi && \
+ if [ "$INCLUDE_FIREFOX" = "true" ]; then playwright install firefox; fi; \
+ else \
+ echo "Skipping browser installation"; \
+ fi
+
# Copy required files for Python build
COPY pyproject.toml setup.py MANIFEST.in README.md ./
COPY superset-frontend/package.json superset-frontend/
@@ -214,12 +213,11 @@ FROM python-common AS lean
# Install Python dependencies using docker/pip-install.sh
COPY requirements/base.txt requirements/
-RUN --mount=type=cache,target=/root/.cache/uv \
+RUN --mount=type=cache,target=${SUPERSET_HOME}/.cache/uv \
/app/docker/pip-install.sh --requires-build-essential -r requirements/base.txt
# Install the superset package
-RUN --mount=type=cache,target=/root/.cache/uv \
+RUN --mount=type=cache,target=${SUPERSET_HOME}/.cache/uv \
uv pip install .
-
RUN python -m compileall /app/superset
USER superset
@@ -238,12 +236,13 @@ RUN /app/docker/apt-install.sh \
# Copy development requirements and install them
COPY requirements/*.txt requirements/
# Install Python dependencies using docker/pip-install.sh
-RUN --mount=type=cache,target=/root/.cache/uv \
+RUN --mount=type=cache,target=${SUPERSET_HOME}/.cache/uv \
/app/docker/pip-install.sh --requires-build-essential -r requirements/development.txt
# Install the superset package
-RUN --mount=type=cache,target=/root/.cache/uv \
+RUN --mount=type=cache,target=${SUPERSET_HOME}/.cache/uv \
uv pip install .
+RUN uv pip install .[postgres]
RUN python -m compileall /app/superset
USER superset
@@ -252,5 +251,7 @@ USER superset
# CI image...
######################################################################
FROM lean AS ci
-
+USER root
+RUN uv pip install .[postgres]
+USER superset
CMD ["/app/docker/entrypoints/docker-ci.sh"]
diff --git a/docker-compose.yml b/docker-compose.yml
index 19c91f74a6..543f5e94e3 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -27,12 +27,13 @@ x-superset-volumes: &superset-volumes
- ./docker:/app/docker
- ./superset:/app/superset
- ./superset-frontend:/app/superset-frontend
- - superset_home:/app/superset_home
- ./tests:/app/tests
+ #- superset_home:/app/superset_home
x-common-build: &common-build
context: .
- target: ${SUPERSET_BUILD_TARGET:-dev} # can use `dev` (default) or `lean`
+ #target: ${SUPERSET_BUILD_TARGET:-dev} # can use `dev` (default) or `lean`
+ target: ci
cache_from:
- apache/superset-cache:3.10-slim-bookworm
args:
diff --git a/docker/docker-bootstrap.sh b/docker/docker-bootstrap.sh
index 5bcad1f4fe..19a056e5fa 100755
--- a/docker/docker-bootstrap.sh
+++ b/docker/docker-bootstrap.sh
@@ -18,9 +18,12 @@
set -eo pipefail
+# Ensure the temporary directory exists
+mkdir -p /tmp/superset_temp
+
# Make python interactive
if [ "$DEV_MODE" == "true" ]; then
- if command -v uv > /dev/null 2>&1; then
+ if [ "$(whoami)" = "root" ] && command -v uv > /dev/null 2>&1; then
echo "Reinstalling the app in editable mode"
uv pip install -e .
fi
@@ -34,7 +37,8 @@ if [ "$CYPRESS_CONFIG" == "true" ]; then
export SUPERSET__SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://superset:superset@db:5432/superset_cypress
PORT=8081
fi
-if [[ "$DATABASE_DIALECT" == postgres* ]] ; then
+if [[ "$DATABASE_DIALECT" == postgres* ]] && [ "$(whoami)" = "root" ]; then
+ # older images may not have the postgres dev requirements installed
echo "Installing postgres requirements"
if command -v uv > /dev/null 2>&1; then
# Use uv in newer images
diff --git a/docker/entrypoints/docker-ci.sh b/docker/entrypoints/docker-ci.sh
index 9e97cbbad4..198933312a 100755
--- a/docker/entrypoints/docker-ci.sh
+++ b/docker/entrypoints/docker-ci.sh
@@ -23,4 +23,4 @@
export SERVER_THREADS_AMOUNT=8
# start up the web server
-/usr/bin/run-server.sh
+/app/docker/entrypoints/run-server.sh