From 536b1c4816093cb31cf07924e2a63048e7e1561e Mon Sep 17 00:00:00 2001 From: Sebastian Liebscher <112352529+sebastianliebscher@users.noreply.github.com> Date: Thu, 13 Apr 2023 18:31:36 +0200 Subject: [PATCH] fix(docker): optimize docker build by better utilizing build cache (#23624) --- Dockerfile | 84 ++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9089fc8f28..aa83ff5fdb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,52 +58,48 @@ ENV LANG=C.UTF-8 \ SUPERSET_PORT=8088 RUN mkdir -p ${PYTHONPATH} \ - && useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset \ - && apt-get update -y \ - && apt-get install -y --no-install-recommends \ - build-essential \ - curl \ - default-libmysqlclient-dev \ - libsasl2-dev \ - libsasl2-modules-gssapi-mit \ - libpq-dev \ - libecpg-dev \ - && rm -rf /var/lib/apt/lists/* - -COPY ./requirements/*.txt /app/requirements/ -COPY setup.py MANIFEST.in README.md /app/ - -# setup.py uses the version information in package.json -COPY superset-frontend/package.json /app/superset-frontend/ - -RUN cd /app \ - && mkdir -p superset/static \ - && touch superset/static/version_info.json \ - && pip install --no-cache -r requirements/local.txt - -COPY --from=superset-node /app/superset/static/assets /app/superset/static/assets - -## Lastly, let's install superset itself -COPY superset /app/superset -COPY setup.py MANIFEST.in README.md /app/ -RUN cd /app \ - && chown -R superset:superset * \ - && pip install -e . \ - && flask fab babel-compile --target superset/translations - -COPY ./docker/run-server.sh /usr/bin/ - -RUN chmod a+x /usr/bin/run-server.sh + && useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset \ + && apt-get update -y \ + && apt-get install -y --no-install-recommends \ + build-essential \ + curl \ + default-libmysqlclient-dev \ + libsasl2-dev \ + libsasl2-modules-gssapi-mit \ + libpq-dev \ + libecpg-dev \ + && rm -rf /var/lib/apt/lists/* WORKDIR /app +COPY --chown=superset:superset ./requirements/*.txt requirements/ +COPY --chown=superset:superset setup.py MANIFEST.in README.md ./ + +# setup.py uses the version information in package.json +COPY --chown=superset:superset superset-frontend/package.json superset-frontend/ + +RUN mkdir -p superset/static \ + && touch superset/static/version_info.json \ + && pip install --no-cache-dir -r requirements/local.txt + +COPY --chown=superset:superset --from=superset-node /app/superset/static/assets superset/static/assets + +## Lastly, let's install superset itself +COPY --chown=superset:superset superset superset +RUN chown -R superset:superset ./* \ + && pip install --no-cache-dir -e . \ + && flask fab babel-compile --target superset/translations + +COPY ./docker/run-server.sh /usr/bin/ +RUN chmod a+x /usr/bin/run-server.sh + USER superset HEALTHCHECK CMD curl -f "http://localhost:$SUPERSET_PORT/health" EXPOSE ${SUPERSET_PORT} -CMD /usr/bin/run-server.sh +CMD ["/usr/bin/run-server.sh"] ###################################################################### # Dev image... @@ -118,13 +114,13 @@ USER root RUN apt-get update -y \ && apt-get install -y --no-install-recommends \ - libnss3 \ - libdbus-glib-1-2 \ - libgtk-3-0 \ - libx11-xcb1 \ - libasound2 \ - libxtst6 \ - wget + libnss3 \ + libdbus-glib-1-2 \ + libgtk-3-0 \ + libx11-xcb1 \ + libasound2 \ + libxtst6 \ + wget # Install GeckoDriver WebDriver RUN wget https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz -O /tmp/geckodriver.tar.gz && \