sdadfadas
/
Dockerfile
179 строк · 6.9 Кб
1#
2# Licensed to the Apache Software Foundation (ASF) under one or more
3# contributor license agreements. See the NOTICE file distributed with
4# this work for additional information regarding copyright ownership.
5# The ASF licenses this file to You under the Apache License, Version 2.0
6# (the "License"); you may not use this file except in compliance with
7# the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18######################################################################
19# Node stage to deal with static asset construction
20######################################################################
21ARG PY_VER=3.10-slim-bookworm
22
23# if BUILDPLATFORM is null, set it to 'amd64' (or leave as is otherwise).
24ARG BUILDPLATFORM=${BUILDPLATFORM:-amd64}
25FROM --platform=${BUILDPLATFORM} node:18-bullseye-slim AS superset-node
26
27ARG NPM_BUILD_CMD="build"
28
29# Somehow we need python3 + build-essential on this side of the house to install node-gyp
30RUN apt-get update -qq \
31&& apt-get install \
32-yqq --no-install-recommends \
33build-essential \
34python3
35
36ENV BUILD_CMD=${NPM_BUILD_CMD} \
37PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
38# NPM ci first, as to NOT invalidate previous steps except for when package.json changes
39
40RUN --mount=type=bind,target=/frontend-mem-nag.sh,src=./docker/frontend-mem-nag.sh \
41/frontend-mem-nag.sh
42
43WORKDIR /app/superset-frontend
44RUN --mount=type=bind,target=./package.json,src=./superset-frontend/package.json \
45--mount=type=bind,target=./package-lock.json,src=./superset-frontend/package-lock.json \
46npm ci
47
48# Runs the webpack build process
49COPY superset-frontend /app/superset-frontend
50RUN npm run ${BUILD_CMD}
51
52# This copies the .po files needed for translation
53RUN mkdir -p /app/superset/translations
54COPY superset/translations /app/superset/translations
55# Compiles .json files from the .po files, then deletes the .po files
56RUN npm run build-translation
57RUN rm /app/superset/translations/*/LC_MESSAGES/*.po
58RUN rm /app/superset/translations/messages.pot
59
60######################################################################
61# Final lean image...
62######################################################################
63FROM python:${PY_VER} AS lean
64
65WORKDIR /app
66ENV LANG=C.UTF-8 \
67LC_ALL=C.UTF-8 \
68SUPERSET_ENV=production \
69FLASK_APP="superset.app:create_app()" \
70PYTHONPATH="/app/pythonpath" \
71SUPERSET_HOME="/app/superset_home" \
72SUPERSET_PORT=8088
73
74RUN mkdir -p ${PYTHONPATH} superset/static requirements superset-frontend apache_superset.egg-info requirements \
75&& useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset \
76&& apt-get update -qq && apt-get install -yqq --no-install-recommends \
77curl \
78default-libmysqlclient-dev \
79libsasl2-dev \
80libsasl2-modules-gssapi-mit \
81libpq-dev \
82libecpg-dev \
83libldap2-dev \
84&& touch superset/static/version_info.json \
85&& chown -R superset:superset ./* \
86&& rm -rf /var/lib/apt/lists/*
87
88COPY --chown=superset:superset pyproject.toml setup.py MANIFEST.in README.md ./
89# setup.py uses the version information in package.json
90COPY --chown=superset:superset superset-frontend/package.json superset-frontend/
91COPY --chown=superset:superset requirements/base.txt requirements/
92RUN --mount=type=cache,target=/root/.cache/pip \
93apt-get update -qq && apt-get install -yqq --no-install-recommends \
94build-essential \
95&& pip install --upgrade setuptools pip \
96&& pip install -r requirements/base.txt \
97&& apt-get autoremove -yqq --purge build-essential \
98&& rm -rf /var/lib/apt/lists/*
99
100# Copy the compiled frontend assets
101COPY --chown=superset:superset --from=superset-node /app/superset/static/assets superset/static/assets
102
103## Lastly, let's install superset itself
104COPY --chown=superset:superset superset superset
105RUN --mount=type=cache,target=/root/.cache/pip \
106pip install -e .
107
108# Copy the .json translations from the frontend layer
109COPY --chown=superset:superset --from=superset-node /app/superset/translations superset/translations
110
111# Compile translations for the backend - this generates .mo files, then deletes the .po files
112COPY ./scripts/translations/generate_mo_files.sh ./scripts/translations/
113RUN ./scripts/translations/generate_mo_files.sh \
114&& chown -R superset:superset superset/translations \
115&& rm superset/translations/messages.pot \
116&& rm superset/translations/*/LC_MESSAGES/*.po
117
118COPY --chmod=755 ./docker/run-server.sh /usr/bin/
119USER superset
120
121HEALTHCHECK CMD curl -f "http://localhost:${SUPERSET_PORT}/health"
122
123EXPOSE ${SUPERSET_PORT}
124
125CMD ["/usr/bin/run-server.sh"]
126
127######################################################################
128# Dev image...
129######################################################################
130FROM lean AS dev
131
132USER root
133RUN apt-get update -qq \
134&& apt-get install -yqq --no-install-recommends \
135libnss3 \
136libdbus-glib-1-2 \
137libgtk-3-0 \
138libx11-xcb1 \
139libasound2 \
140libxtst6 \
141git \
142pkg-config \
143&& rm -rf /var/lib/apt/lists/*
144
145RUN --mount=type=cache,target=/root/.cache/pip \
146pip install playwright
147RUN playwright install-deps
148RUN playwright install chromium
149
150# Install GeckoDriver WebDriver
151ARG GECKODRIVER_VERSION=v0.34.0 \
152FIREFOX_VERSION=125.0.3
153
154RUN apt-get update -qq \
155&& apt-get install -yqq --no-install-recommends wget bzip2 \
156&& wget -q https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz -O - | tar xfz - -C /usr/local/bin \
157# Install Firefox
158&& 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 \
159&& ln -s /opt/firefox/firefox /usr/local/bin/firefox \
160&& apt-get autoremove -yqq --purge wget bzip2 && rm -rf /var/[log,tmp]/* /tmp/* /var/lib/apt/lists/*
161# Cache everything for dev purposes...
162
163COPY --chown=superset:superset requirements/development.txt requirements/
164RUN --mount=type=cache,target=/root/.cache/pip \
165apt-get update -qq && apt-get install -yqq --no-install-recommends \
166build-essential \
167&& pip install -r requirements/development.txt \
168&& apt-get autoremove -yqq --purge build-essential \
169&& rm -rf /var/lib/apt/lists/*
170
171USER superset
172######################################################################
173# CI image...
174######################################################################
175FROM lean AS ci
176
177COPY --chown=superset:superset --chmod=755 ./docker/*.sh /app/docker/
178
179CMD ["/app/docker/docker-ci.sh"]
180