Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docker refactor #31385

Merged
merged 42 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
af54c21
fix: docker-compose up ModuleNotFoundError: {...} superset
mistercrunch Dec 10, 2024
9d9fef1
rm uv
mistercrunch Dec 10, 2024
cb04472
rm --system
mistercrunch Dec 10, 2024
842e1ba
fix: simplify dockerfile with chown/chmod right before USER superset …
mistercrunch Dec 10, 2024
93f0761
bring uv back
mistercrunch Dec 10, 2024
08b048c
conditional playwright
mistercrunch Dec 10, 2024
6c42edf
kill FF install in favor of playwright
mistercrunch Dec 10, 2024
2a8f4f0
mv script from /usr/bin to /app/docker/run-server.sh
mistercrunch Dec 11, 2024
f55203f
/usr/bin
mistercrunch Dec 11, 2024
33ca069
usr.bin
mistercrunch Dec 11, 2024
f38af7b
more specific about venv location
mistercrunch Dec 11, 2024
e505d5c
move headless browsers up
mistercrunch Dec 11, 2024
9563d9b
login, why not?
mistercrunch Dec 11, 2024
3cf8fb7
fix pkg_resources
mistercrunch Dec 11, 2024
b3a1bd1
copy .env file
mistercrunch Dec 11, 2024
442e161
only sh files
mistercrunch Dec 11, 2024
d7e35b2
reinstall
mistercrunch Dec 11, 2024
cd1869e
dev mode uv install
mistercrunch Dec 11, 2024
6ea9994
fixin'
mistercrunch Dec 11, 2024
078f0a1
run -e . on startup
mistercrunch Dec 11, 2024
fbf2de1
volume back
mistercrunch Dec 11, 2024
9b7bf6a
splitting layers
mistercrunch Dec 11, 2024
728c3d9
750
mistercrunch Dec 11, 2024
4be6cff
reordering
mistercrunch Dec 11, 2024
235e750
more progress
mistercrunch Dec 11, 2024
c96fb87
more tweaks
mistercrunch Dec 11, 2024
be27ce8
add docker/docker-translate.sh
mistercrunch Dec 11, 2024
ca3687e
moving back to chown on the fly
mistercrunch Dec 11, 2024
93a8f14
compile
mistercrunch Dec 11, 2024
11beaa7
remove chown
mistercrunch Dec 11, 2024
3d36305
alter perms
mistercrunch Dec 11, 2024
74a86bd
updating.md
mistercrunch Dec 11, 2024
7a52adf
progress
mistercrunch Dec 12, 2024
4a7bd04
fix
mistercrunch Dec 12, 2024
5fb4bbe
translate
mistercrunch Dec 13, 2024
926b702
close to finish line
mistercrunch Dec 13, 2024
a211f7a
add missing reqs files
mistercrunch Dec 13, 2024
f5d6e25
tweaksies
mistercrunch Dec 13, 2024
13de8a1
translations
mistercrunch Dec 13, 2024
9318c28
remove unused bash script
mistercrunch Dec 13, 2024
e718d32
LAST TWEAKS DAMMIT
mistercrunch Dec 13, 2024
a95f546
cache\!
mistercrunch Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ephemeral-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ jobs:
- name: Setup supersetbot
uses: ./.github/actions/setup-supersetbot/

- name: Try to login to DockerHub
if: steps.check.outputs.python || steps.check.outputs.frontend || steps.check.outputs.docker
continue-on-error: true
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build ephemeral env image
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
104 changes: 44 additions & 60 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ FROM --platform=${BUILDPLATFORM} node:20-bullseye-slim AS superset-node
ARG NPM_BUILD_CMD="build"
ARG BUILD_TRANSLATIONS="false" # Include translations in the final build
ARG DEV_MODE="false" # Skip frontend build in dev mode
ARG INCLUDE_CHROMIUM="true" # Include headless Chromium for alerts & reports
ARG INCLUDE_FIREFOX="false" # Include headless Firefox if enabled
ENV DEV_MODE=${DEV_MODE}

# Install system dependencies required for node-gyp
RUN --mount=type=bind,source=./docker,target=/docker \
Expand Down Expand Up @@ -83,10 +82,30 @@ RUN if [ "$BUILD_TRANSLATIONS" = "true" ]; then \
/app/superset/translations/messages.pot


# Transition to Python base image
######################################################################
# Base python layer
######################################################################
FROM python:${PY_VER} AS python-base
RUN pip install --no-cache-dir --upgrade setuptools pip uv

# Using uv as it's faster/simpler than pip
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/pip \
if [ "$INCLUDE_CHROMIUM" = "true" ] || [ "$INCLUDE_FIREFOX" = "true" ]; then \
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


######################################################################
# Final lean image...
######################################################################
Expand All @@ -112,6 +131,7 @@ RUN --mount=type=bind,source=./docker,target=/docker \
superset-frontend \
apache_superset.egg-info \
requirements \
{SUPERSET_HOME} \
mistercrunch marked this conversation as resolved.
Show resolved Hide resolved
&& useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset \
&& /docker/apt-install.sh \
curl \
Expand All @@ -121,47 +141,45 @@ RUN --mount=type=bind,source=./docker,target=/docker \
libecpg-dev \
libldap2-dev \
&& touch superset/static/version_info.json \
&& chown -R superset:superset ./* \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

# Copy required files for Python build
COPY --chown=superset:superset pyproject.toml setup.py MANIFEST.in README.md ./
COPY --chown=superset:superset superset-frontend/package.json superset-frontend/
COPY --chown=superset:superset requirements/base.txt requirements/
COPY --chown=superset:superset scripts/check-env.py scripts/
COPY pyproject.toml setup.py MANIFEST.in README.md ./
COPY superset-frontend/package.json superset-frontend/
COPY requirements/base.txt requirements/
COPY scripts/check-env.py scripts/
COPY docker/*.sh /app/docker/
COPY --chmod=755 ./docker/run-server.sh /usr/bin/

# Install Python dependencies using docker/pip-install.sh
RUN --mount=type=bind,source=./docker,target=/docker \
--mount=type=cache,target=/root/.cache/pip \
/docker/pip-install.sh --requires-build-essential -r requirements/base.txt
RUN --mount=type=cache,target=/root/.cache/pip \
/app/docker/pip-install.sh --requires-build-essential -r requirements/base.txt

# Copy the compiled frontend assets from the node image
COPY --chown=superset:superset --from=superset-node /app/superset/static/assets superset/static/assets
COPY --from=superset-node /app/superset/static/assets superset/static/assets

# Copy the main Superset source code
COPY --chown=superset:superset superset superset
COPY superset superset

# Install Superset itself using docker/pip-install.sh
RUN --mount=type=bind,source=./docker,target=/docker \
--mount=type=cache,target=/root/.cache/pip \
/docker/pip-install.sh -e .
RUN --mount=type=cache,target=/root/.cache/pip \
uv pip install .

# Copy .json translations from the node image
COPY --chown=superset:superset --from=superset-node /app/superset/translations superset/translations
COPY --from=superset-node /app/superset/translations superset/translations

# Compile backend translations and clean up
COPY ./scripts/translations/generate_mo_files.sh ./scripts/translations/
RUN if [ "$BUILD_TRANSLATIONS" = "true" ]; then \
./scripts/translations/generate_mo_files.sh \
&& chown -R superset:superset superset/translations; \
./scripts/translations/generate_mo_files.sh; \
fi \
&& rm -rf superset/translations/messages.pot \
superset/translations/*/LC_MESSAGES/*.po
superset/translations/*/LC_MESSAGES/*.po;

# Add server run script
COPY --chmod=755 ./docker/run-server.sh /usr/bin/

# Set user and healthcheck
RUN chown -R superset:superset /app && chmod -R 775 /app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: test if 755 is enough, even 750 should work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing things so that superset user can't modify things, it's going to have pretty much just readonly the the whole image, execute on a few things it needs, and write on its home directory

USER superset
HEALTHCHECK CMD curl -f "http://localhost:${SUPERSET_PORT}/health"

Expand All @@ -177,61 +195,27 @@ FROM lean AS dev

USER root

# Install dev dependencies
# Convenience libs for development
RUN --mount=type=bind,source=./docker,target=/docker \
/docker/apt-install.sh \
libnss3 \
libdbus-glib-1-2 \
libgtk-3-0 \
libx11-xcb1 \
libasound2 \
libxtst6 \
git \
pkg-config

# Install Playwright and its dependencies
RUN --mount=type=cache,target=/root/.cache/pip \
uv pip install --system playwright \
&& playwright install-deps

# Optionally install Chromium
RUN if [ "$INCLUDE_CHROMIUM" = "true" ]; then \
playwright install chromium; \
else \
echo "Skipping Chromium installation in dev mode"; \
fi

# Install GeckoDriver WebDriver and Firefox (if required)
ARG GECKODRIVER_VERSION=v0.34.0
ARG FIREFOX_VERSION=125.0.3
RUN --mount=type=bind,source=./docker,target=/docker \
if [ "$INCLUDE_FIREFOX" = "true" ]; then \
/docker/apt-install.sh wget bzip2 \
&& wget -q https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz -O - | tar xfz - -C /usr/local/bin \
&& wget -q https://download-installer.cdn.mozilla.net/pub/firefox/releases/${FIREFOX_VERSION}/linux-x86_64/en-US/firefox-${FIREFOX_VERSION}.tar.bz2 -O - | tar xfj - -C /opt \
&& ln -s /opt/firefox/firefox /usr/local/bin/firefox \
&& apt-get autoremove -yqq --purge wget bzip2 && rm -rf /var/[log,tmp]/* /tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*; \
else \
echo "Skipping Firefox installation in dev mode"; \
fi

# Install MySQL client dependencies
RUN --mount=type=bind,source=./docker,target=/docker \
/docker/apt-install.sh default-libmysqlclient-dev

# Copy development requirements and install them
COPY --chown=superset:superset requirements/development.txt requirements/
RUN --mount=type=bind,source=./docker,target=/docker \
--mount=type=cache,target=/root/.cache/pip \
/docker/pip-install.sh --requires-build-essential -r requirements/development.txt
COPY requirements/development.txt requirements/
RUN --mount=type=cache,target=/root/.cache/pip \
/app/docker/pip-install.sh --requires-build-essential -r requirements/development.txt

RUN chown -R superset:superset /app && chmod -R 775 /app
USER superset

######################################################################
# CI image...
######################################################################
FROM lean AS ci

COPY --chown=superset:superset --chmod=755 ./docker/*.sh /app/docker/

CMD ["/app/docker/docker-ci.sh"]
1 change: 1 addition & 0 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


COMPOSE_PROJECT_NAME=superset
DEV_MODE=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything that needs to be done for official docker images built during releases to remove this flag?


# database configurations (do not modify)
DATABASE_DB=superset
Expand Down
5 changes: 5 additions & 0 deletions docker/docker-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

set -eo pipefail

# Make python interactive
if [ "$DEV_MODE" == "true" ]; then
echo "Reinstalling the app in editable mode"
uv pip install -e .
fi
REQUIREMENTS_LOCAL="/app/docker/requirements-local.txt"
# If Cypress run – overwrite the password for admin and export env variables
if [ "$CYPRESS_CONFIG" == "true" ]; then
Expand Down
4 changes: 2 additions & 2 deletions docker/pip-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ fi
# Choose whether to use pip cache
if $USE_CACHE; then
echo "Using pip cache..."
uv pip install --system "${ARGS[@]}"
uv pip install "${ARGS[@]}"
else
echo "Disabling pip cache..."
uv pip install --system --no-cache-dir "${ARGS[@]}"
uv pip install --no-cache-dir "${ARGS[@]}"
fi

# Remove build-essential if it was installed
Expand Down
3 changes: 1 addition & 2 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from typing import Any, Callable, Iterator, Literal, TYPE_CHECKING, TypedDict

import click
import pkg_resources
from celery.schedules import crontab
from flask import Blueprint
from flask_appbuilder.security.manager import AUTH_DB
Expand Down Expand Up @@ -86,7 +85,7 @@

SUPERSET_LOG_VIEW = True

BASE_DIR = pkg_resources.resource_filename("superset", "")
BASE_DIR = str(files("superset"))
if "SUPERSET_HOME" in os.environ:
DATA_DIR = os.environ["SUPERSET_HOME"]
else:
Expand Down
Loading