Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4031 from tbille/add-multistage
Browse files Browse the repository at this point in the history
Upgrade to multistaged build
  • Loading branch information
tbille authored May 14, 2020
2 parents 02c18d2 + 91fcb18 commit 49aa1eb
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 49aa1eb

Please sign in to comment.