Dockerfile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. # PY stage that simply does a pip install on our requirements
  19. ######################################################################
  20. ARG PY_VER=3.6.9
  21. FROM python:${PY_VER} AS superset-py
  22. RUN mkdir /app \
  23. && apt-get update -y \
  24. && apt-get install -y --no-install-recommends \
  25. build-essential \
  26. default-libmysqlclient-dev \
  27. libpq-dev \
  28. && rm -rf /var/lib/apt/lists/*
  29. # First, we just wanna install requirements, which will allow us to utilize the cache
  30. # in order to only build if and only if requirements change
  31. COPY ./requirements.txt /app/
  32. RUN cd /app \
  33. && pip install --no-cache -r requirements.txt
  34. ######################################################################
  35. # Node stage to deal with static asset construction
  36. ######################################################################
  37. FROM node:10-jessie AS superset-node
  38. # NPM ci first, as to NOT invalidate previous steps except for when package.json changes
  39. RUN mkdir -p /app/superset-frontend
  40. RUN mkdir -p /app/superset/assets
  41. COPY ./superset-frontend/package* /app/superset-frontend/
  42. RUN cd /app/superset-frontend \
  43. && npm ci
  44. # Next, copy in the rest and let webpack do its thing
  45. COPY ./superset-frontend /app/superset-frontend
  46. # This is BY FAR the most expensive step (thanks Terser!)
  47. RUN cd /app/superset-frontend \
  48. && npm run build \
  49. && rm -rf node_modules
  50. ######################################################################
  51. # Final lean image...
  52. ######################################################################
  53. ARG PY_VER=3.6.9
  54. FROM python:${PY_VER} AS lean
  55. ENV LANG=C.UTF-8 \
  56. LC_ALL=C.UTF-8 \
  57. FLASK_ENV=production \
  58. FLASK_APP="superset.app:create_app()" \
  59. PYTHONPATH="/app/pythonpath" \
  60. SUPERSET_HOME="/app/superset_home" \
  61. SUPERSET_PORT=8080
  62. RUN useradd --user-group --no-create-home --no-log-init --shell /bin/bash superset \
  63. && mkdir -p ${SUPERSET_HOME} ${PYTHONPATH} \
  64. && apt-get update -y \
  65. && apt-get install -y --no-install-recommends \
  66. build-essential \
  67. default-libmysqlclient-dev \
  68. libpq-dev \
  69. && rm -rf /var/lib/apt/lists/*
  70. COPY --from=superset-py /usr/local/lib/python3.6/site-packages/ /usr/local/lib/python3.6/site-packages/
  71. # Copying site-packages doesn't move the CLIs, so let's copy them one by one
  72. COPY --from=superset-py /usr/local/bin/gunicorn /usr/local/bin/celery /usr/local/bin/flask /usr/bin/
  73. COPY --from=superset-node /app/superset/static/assets /app/superset/static/assets
  74. COPY --from=superset-node /app/superset-frontend /app/superset-frontend
  75. ## Lastly, let's install superset itself
  76. COPY superset /app/superset
  77. COPY setup.py MANIFEST.in README.md /app/
  78. RUN cd /app \
  79. && chown -R superset:superset * \
  80. && pip install -e .
  81. COPY ./docker/docker-entrypoint.sh /usr/bin/
  82. WORKDIR /app
  83. USER superset
  84. HEALTHCHECK CMD ["curl", "-f", "http://localhost:8088/health"]
  85. EXPOSE ${SUPERSET_PORT}
  86. ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]
  87. ######################################################################
  88. # Dev image...
  89. ######################################################################
  90. FROM lean AS dev
  91. COPY ./requirements-dev.txt ./docker/requirements-extra.txt /app/
  92. USER root
  93. RUN cd /app \
  94. && pip install --no-cache -r requirements-dev.txt -r requirements-extra.txt
  95. USER superset