From 91fcb1845b4f91a97157a22704f247bd800abb76 Mon Sep 17 00:00:00 2001 From: Thomas Bille Date: Thu, 14 May 2020 09:26:41 +0100 Subject: [PATCH] Upgrade to multistaged build --- Dockerfile | 57 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 494009be54..5d6e415b19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,52 @@ +# syntax=docker/dockerfile:experimental + +# Build stage: Install python dependencies +# === +FROM ubuntu:focal AS python-dependencies +RUN apt-get update && apt-get install --no-install-recommends --yes python3-pip python3-setuptools +ADD requirements.txt /tmp/requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip pip3 install --user --requirement /tmp/requirements.txt + + +# Build stage: Install yarn dependencies +# === +FROM node:10-slim AS yarn-dependencies +WORKDIR /srv +ADD yarn.lock . +ADD package.json . +RUN --mount=type=cache,target=/usr/local/share/.cache/yarn yarn install + + +# Build stage: Run "yarn run build-js" +# === +FROM yarn-dependencies AS build-js +ADD . . +RUN yarn run build-prod + + +# Build the production image +# === FROM ubuntu:focal +# Install python and import python dependencies +RUN apt-get update && apt-get install --no-install-recommends --yes python3-lib2to3 python3-pkg-resources ca-certificates libsodium-dev +COPY --from=python-dependencies /root/.local/lib/python3.8/site-packages /root/.local/lib/python3.8/site-packages +COPY --from=python-dependencies /root/.local/bin /root/.local/bin +ENV PATH="/root/.local/bin:${PATH}" + # Set up environment ENV LANG C.UTF-8 WORKDIR /srv -# System dependencies -# Node ppa provided by: https://github.com/nodesource/distributions -RUN apt-get update && \ - apt-get install --yes build-essential python3-dev python3-pip - -# Import code, install code dependencies -ADD templates/ templates/ -ADD static/assets/ static/assets/ -ADD static/build/ static/build/ -ADD static/gui/ static/gui/ -ADD webapp/ webapp/ -ADD requirements.txt requirements.txt -ADD entrypoint entrypoint -ADD permanent-redirects.yaml permanent-redirects.yaml -RUN pip3 install -r requirements.txt +# Import code, build assets +ADD . . +RUN rm -rf package.json requirements.txt yarn.lock .babelrc webpack.config.js +COPY --from=build-js /srv/static/assets static/assets +COPY --from=build-js /srv/static/build static/build +COPY --from=build-js /srv/static/gui static/gui +# Set revision ID ARG BUILD_ID -RUN test -n "${BUILD_ID}" ENV TALISKER_REVISION_ID "${BUILD_ID}" # Setup commands to run server