Add multistage build
To reduce the size of the Docker image. We use a multistage build based on an alpine distro, the size is reduced by a factor of 7.
This commit is contained in:
parent
d1e52eae86
commit
f94426476d
106
Dockerfile
106
Dockerfile
|
@ -1,24 +1,102 @@
|
||||||
# Get the base Python image
|
# Get the base Python image
|
||||||
FROM python:latest
|
FROM alpine:edge AS builder
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
ARG branch="devel"
|
||||||
|
ARG login="" password=""
|
||||||
|
ARG folder=/opt/msspec user=msspec
|
||||||
|
|
||||||
# Install system dependencies
|
# Install system dependencies
|
||||||
RUN apt-get update && apt-get install -y virtualenv gfortran libgtk-3-dev nano
|
# tools
|
||||||
|
RUN apk add bash git make gfortran python3
|
||||||
# Add a non-privileged user
|
# headers
|
||||||
RUN useradd -ms /bin/bash -d /opt/msspec msspec
|
RUN apk add python3-dev lapack-dev musl-dev
|
||||||
|
# python packages
|
||||||
# Set the working directory in the container
|
RUN apk add py3-virtualenv py3-pip py3-numpy-dev py3-h5py py3-lxml py3-matplotlib py3-numpy py3-pandas py3-cairo py3-scipy py3-setuptools_scm
|
||||||
USER msspec
|
RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing py3-wxpython
|
||||||
RUN mkdir -p /opt/msspec/code
|
RUN pip install ase pint terminaltables ipython
|
||||||
WORKDIR /opt/msspec/code
|
# for GUI
|
||||||
|
RUN apk add ttf-droid adwaita-icon-theme
|
||||||
|
RUN apk add build-base
|
||||||
|
|
||||||
# Fetch the code
|
# Fetch the code
|
||||||
RUN git clone https://git.ipr.univ-rennes1.fr/epsi/msspec_python3.git .
|
RUN mkdir -p ${folder}/code
|
||||||
#COPY --chown=msspec:msspec . .
|
WORKDIR ${folder}/code
|
||||||
|
RUN git clone --branch ${branch} https://${login}:${password}@git.ipr.univ-rennes1.fr/epsi/msspec_python3.git .
|
||||||
|
|
||||||
|
# Build
|
||||||
|
RUN make pybinding NO_VENV=1 PYTHON=python3 VERBOSE=1
|
||||||
|
RUN make -C src sdist PYTHON=python3 NO_VENV=1 VENV_PATH=${folder}/.local/src/msspec_venv && \
|
||||||
|
pip install src/dist/msspec*tar.gz
|
||||||
|
|
||||||
|
# Add a non-privileged user
|
||||||
|
RUN adduser -D -s /bin/bash -h ${folder} ${user}
|
||||||
|
|
||||||
|
# Set the working directory in the container
|
||||||
|
USER ${user}
|
||||||
|
|
||||||
|
RUN virtualenv --system-site-packages ${folder}/.local/src/msspec_venv
|
||||||
|
RUN make -C src frontend PYTHON=python3 NO_VENV=1 VENV_PATH=${folder}/.local/src/msspec_venv
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine:edge
|
||||||
|
# Variables
|
||||||
|
ARG folder=/opt/msspec user=msspec
|
||||||
|
# Install system dependencies
|
||||||
|
RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
|
||||||
|
# hdf5-hl cairo openblas lapack libxml2 libxslt libzlf wxwidgets-gtk3 openjpeg libimagequant \
|
||||||
|
nano \
|
||||||
|
py3-virtualenv \
|
||||||
|
lapack \
|
||||||
|
bash \
|
||||||
|
# git \
|
||||||
|
# make \
|
||||||
|
# gfortran \
|
||||||
|
python3 \
|
||||||
|
# ttf-droid \
|
||||||
|
ttf-liberation \
|
||||||
|
adwaita-xfce-icon-theme \
|
||||||
|
# python3-dev \
|
||||||
|
# lapack-dev \
|
||||||
|
# musl-dev \
|
||||||
|
# py3-virtualenv \
|
||||||
|
py3-pip \
|
||||||
|
# py3-numpy-dev \
|
||||||
|
py3-h5py \
|
||||||
|
py3-lxml \
|
||||||
|
py3-matplotlib \
|
||||||
|
py3-numpy \
|
||||||
|
py3-pandas \
|
||||||
|
py3-cairo \
|
||||||
|
py3-scipy \
|
||||||
|
py3-setuptools_scm \
|
||||||
|
py3-wxpython \
|
||||||
|
&& pip install \
|
||||||
|
ase \
|
||||||
|
pint \
|
||||||
|
terminaltables \
|
||||||
|
ipython \
|
||||||
|
&& pip cache purge \
|
||||||
|
# Add a non-privileged user
|
||||||
|
&& adduser -D -s /bin/bash -h ${folder} ${user}
|
||||||
|
|
||||||
|
# Set the working directory in the container
|
||||||
|
USER ${user}
|
||||||
|
WORKDIR ${folder}
|
||||||
# Install msspec
|
# Install msspec
|
||||||
ENV PATH=/opt/msspec/.local/bin:$PATH
|
#COPY --from=builder ${folder}/.local ${folder}/.local
|
||||||
RUN make install VERBOSE=1
|
#COPY --from=builder /usr/lib/python3.10/site-packages /usr/lib/python3.10/site-packages
|
||||||
|
|
||||||
|
COPY --from=builder ${folder}/code/src/dist/msspec*tar.gz msspec.tar.gz
|
||||||
|
RUN virtualenv --system-site-packages .local/src/msspec_venv && \
|
||||||
|
. .local/src/msspec_venv/bin/activate && \
|
||||||
|
pip install msspec.tar.gz && \
|
||||||
|
rm -f msspec.tar.gz && \
|
||||||
|
mkdir -p .local/bin
|
||||||
|
|
||||||
|
COPY --from=builder ${folder}/.local/bin/msspec .local/bin/msspec
|
||||||
|
ENV PATH=${folder}/.local/bin:$PATH
|
||||||
|
|
||||||
# Run the msspec frontend command on startup
|
# Run the msspec frontend command on startup
|
||||||
ENTRYPOINT ["msspec"]
|
ENTRYPOINT ["msspec"]
|
||||||
|
|
Loading…
Reference in New Issue