Skip to content

Commit

Permalink
Merge pull request #275 from se7entyse7en/dockerfile-optmized
Browse files Browse the repository at this point in the history
Dockerfile optimized
  • Loading branch information
se7entyse7en authored Sep 9, 2019
2 parents 2d0723f + aeffcdb commit aa02fc2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Improve speed of development mode on macOs ([#266](https://github.com/src-d/sourced-ui/pull/266))
- Make gunicorn to catch SIGTERM correctly which speed-ups stop command and makes container exit with correct exit code ([#239](https://github.com/src-d/sourced-ui/issues/239))
- Optimize size of Docker image ([#275](https://github.com/src-d/sourced-ui/pull/275))

</details>

Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ endif
# IS_RELEASE is "true" if tag is semantic version and not a pre-release
IS_RELEASE := $(shell echo $(VERSION) | grep -q -E '^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$$' && echo "true" || true)

all: build
all: build build-dev

# Clean, and copy src-d files in the superset repository
.PHONY: patch
Expand Down Expand Up @@ -93,6 +93,8 @@ dev-prepare: set-override watch
.PHONY: patch
build: patch
docker build -t $(DOCKER_IMAGE_NAME):$(VERSION) -f superset/contrib/docker/Dockerfile $(SUPERSET_DIR)
build-dev: patch
docker build -t $(DOCKER_IMAGE_NAME):$(VERSION)-dev -f superset/contrib/docker/Dockerfile $(SUPERSET_DIR) --build-arg DEV_BUILD=true

.PHONY: docker-validate
docker-validate:
Expand Down
71 changes: 47 additions & 24 deletions superset/contrib/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
FROM python:3.6-jessie
FROM node:10 AS static

WORKDIR /home/superset

# Install deps and cache them
COPY superset/assets/package*.json superset/assets/
RUN cd superset/assets && npm ci

# Build
COPY superset/assets superset/assets
RUN cd superset/assets && npm run build

FROM python:3.6 AS wheels

WORKDIR /home/superset

RUN apt-get update -y
RUN apt-get install -y libsasl2-dev

COPY requirements.txt .
COPY requirements-dev.txt .
COPY contrib/docker/requirements-extra.txt .

RUN pip install --upgrade setuptools pip \
&& pip wheel --wheel-dir=/wheels \
-r requirements.txt -r requirements-dev.txt -r requirements-extra.txt

FROM python:3.6-slim

ARG DEV_BUILD

RUN useradd --user-group --create-home --no-log-init --shell /bin/bash superset

Expand All @@ -24,48 +53,42 @@ ENV LANG=C.UTF-8 \

RUN apt-get update -y

# Install dependencies to fix `curl https support error` and `elaying package configuration warning`
RUN apt-get install -y apt-transport-https apt-utils

# Install git as it is used for requirements from Github
RUN apt-get install -y git
# Install superset dependencies
# https://superset.incubator.apache.org/installation.html#os-dependencies
RUN apt-get install -y build-essential libssl-dev \
libffi-dev python3-dev libsasl2-dev libldap2-dev libsasl2-2 libsasl2-modules-gssapi-mit libxi-dev

# Install extra useful tool for development
RUN apt-get install -y vim less postgresql-client redis-tools
RUN apt-get install -y libsasl2-dev libsasl2-2 libsasl2-modules-gssapi-mit

# Install nodejs for custom build
# https://superset.incubator.apache.org/installation.html#making-your-own-build
# https://nodejs.org/en/download/package-manager/
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt-get install -y nodejs
RUN if [ "$DEV_BUILD" = "true" ]; \
then apt-get install -y curl && \
curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt-get install -y nodejs vim less postgresql-client redis-tools; fi

WORKDIR /home/superset

COPY --from=wheels /wheels /wheels

COPY requirements.txt .
COPY requirements-dev.txt .
COPY contrib/docker/requirements-extra.txt .

RUN pip install --upgrade setuptools pip \
&& pip install -r requirements.txt -r requirements-dev.txt -r requirements-extra.txt \
&& rm -rf /root/.cache/pip
&& pip install --no-index --find-links=/wheels \
-r requirements.txt -r requirements-dev.txt -r requirements-extra.txt \
&& rm -rf /wheels

RUN pip install gevent
RUN if [ "$DEV_BUILD" != "true" ]; \
then apt-get -y --purge autoremove git; fi

COPY --chown=superset:superset superset superset
COPY --chown=superset:superset dashboards dashboards

ENV PATH=/home/superset/superset/bin:$PATH \
PYTHONPATH=/home/superset/:$PYTHONPATH \
SUPERSET_CONFIG_PATH=/home/superset/superset/superset_config.py
SUPERSET_CONFIG_PATH=/home/superset/superset/superset_config.py

USER superset
COPY --chown=superset:superset --from=static /home/superset/superset/assets/dist superset/assets/dist

RUN cd superset/assets \
&& npm ci \
&& npm run build \
&& rm -rf node_modules
USER superset

COPY contrib/docker/superset_config.py ./superset/
COPY contrib/docker/bootstrap.py .
Expand Down

0 comments on commit aa02fc2

Please sign in to comment.