From 240b42f113cee9ad9d1935a31f7cf901e1f01204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Fri, 30 Apr 2021 13:05:57 +0200 Subject: [PATCH] Implement multi-stage-build --- .gitignore | 1 - Dockerfile | 47 ++++++++++++++++++++++++++++++------- Dockerfile.compile | 58 ---------------------------------------------- Makefile | 3 --- 4 files changed, 39 insertions(+), 70 deletions(-) delete mode 100644 .gitignore delete mode 100644 Dockerfile.compile diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 86fc345..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -quantum_package_static.tar.gz \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 329700b..0e8964a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,39 @@ # For help about how Dockerfiles work, see https://docs.docker.com/engine/reference/builder +FROM ubuntu:20.04 AS builder +# Build argument (can be changed at build time +# This argument define timezone for tzdata requierd by qp_run +ARG tz=Etc/UTC +# enable manpages installation +RUN sed -i 's,^path-exclude=/usr/share/man/,#path-exclude=/usr/share/man/,' /etc/dpkg/dpkg.cfg.d/excludes +# Install all requierd packages +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install apt-utils -y \ +# Git for download quantum package +git \ +# All necessary packages to compile and run quantum package +curl wget python gfortran gcc g++ build-essential unzip liblapack-dev pkg-config autoconf zlib1g zlib1g-dev libgmp-dev \ +-y +# Add user and switch to this user +RUN adduser --disabled-password --gecos '' builder +USER builder +# I don't know why but the USER environment variable is not set so I set it because it's requested for ninja +ENV USER=builder +# Go to home +WORKDIR /home/builder +# Download quantum package +RUN git clone --depth 1 --branch 2.1.2 https://github.com/QuantumPackage/qp2 +# Go to quantum package +WORKDIR /home/builder/qp2 +# Configure +RUN ./configure -i all -c config/gfortran_avx.cfg +# source don't work with /bin/sh (used by the run command so I use bash) +# Compile the code to a static build +RUN /bin/bash -c "source quantum_package.rc ; qp export_as_tgz" + + # This image is based from Ubuntu LTS FROM ubuntu:20.04 -LABEL version="1.0" \ +LABEL version="1.1" \ maintainer.name="Mickaël Véril" \ quantum_package.author.name="Anthony Scemama" \ quantum_package.url="https://quantumpackage.github.io/qp2" \ @@ -26,19 +57,19 @@ apt-get autoremove && apt-get clean # Reconfigure tzdata with the good timezone RUN echo $tz > /etc/timezone && rm -rf /etc/localtime && echo "set mouse=" > ~/.vimrc RUN dpkg-reconfigure -f noninteractive tzdata -# ADD user and switch to this user +# Add user and switch to this user RUN adduser --disabled-password --gecos '' $user USER $user # I don't know why but the USER environment variable is not set so I set it because it's requested for ninja ENV USER=$user # Go to home WORKDIR /home/$user -# untar directly static quantum package -ADD quantum_package_static.tar.gz . -# move quantum package -RUN mv quantum_package_static qp2 -# add examples -COPY --chown=$user examples examples +# Copy examples +COPY --chown=$user:$user examples examples +# Copy QP2 static from build +COPY --from=builder --chown=$user:$user /home/builder/qp2/quantum_package_static.tar.gz . +# Extract static build +RUN tar -xf quantum_package_static.tar.gz && mv quantum_package_static qp2 && rm quantum_package_static.tar.gz RUN echo "set -g default-command /home/$user/qp2/bin/qpsh" >> .tmux.conf RUN echo "shell \"/home/$user/qp2/bin/qpsh\"" >> .screenrc # start a qp shell when run diff --git a/Dockerfile.compile b/Dockerfile.compile deleted file mode 100644 index c59ef42..0000000 --- a/Dockerfile.compile +++ /dev/null @@ -1,58 +0,0 @@ -# For help about how Dockerfiles work, see https://docs.docker.com/engine/reference/builder - -# This image is based from Ubuntu LTS -FROM ubuntu:20.04 -LABEL version="1.0" \ -maintainer.name="Mickaël Véril" \ -quantum_package.author.name="Anthony Scemama" \ -quantum_package.url="https://quantumpackage.github.io/qp2" \ -quantum_package.repo="https://github.com/QuantumPackage/qp2" \ -laboratory.name="Laboratoire de Chimie et Physique Quantique (LCPQ)" \ -laboratory.url="http://www.lcpq.ups-tlse.fr/" -# Build argument (can be changed at build time -# This argument define the user name -ARG user=user -# This argument define timezone for tzdata requierd by qp_run -ARG tz=Etc/UTC -# enable manpages installation -RUN sed -i 's,^path-exclude=/usr/share/man/,#path-exclude=/usr/share/man/,' /etc/dpkg/dpkg.cfg.d/excludes -# Install all requierd packages -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install apt-utils -y \ -# Git for download quantum package -git \ -# All necessary packages to compile and run quantum package -curl wget python gfortran gcc g++ build-essential unzip liblapack-dev pkg-config autoconf zlib1g zlib1g-dev tzdata libgmp-dev \ -# Other packages for user usage -htop vim emacs screen tmux less man manpages-posix lsb-release -y -# Reconfigure tzdata with the good timezone -RUN echo $tz > /etc/timezone -RUN rm -rf /etc/localtime -RUN dpkg-reconfigure -f noninteractive tzdata -# ADD user and switch to this user -RUN adduser --disabled-password --gecos '' $user -USER $user -# I don't know why but the USER environment variable is not set so I set it because it's requested for ninja -ENV USER=$user -# Go to home -WORKDIR /home/$user -# Download quantum package -RUN git clone https://github.com/QuantumPackage/qp2 -# Go to quantum package -WORKDIR /home/$user/qp2 -# Configure -RUN TRAVIS=1 ./configure -i all -c config/gfortran.cfg -# source don't work with /bin/sh (used by the run command so I use bash) -# Compile the code -RUN /bin/bash -c "source quantum_package.rc ; ninja" -# Run tests -RUN /bin/bash -c "source quantum_package.rc ; qp_test -a" -# Return to the user directory -WORKDIR /home/$user/ -# add examples -COPY --chown=$user examples examples -RUN echo "set -g default-command /home/$user/qp2/bin/qpsh" >> .tmux.conf -RUN echo "shell \"/home/$user/qp2/bin/qpsh\"" >> .screenrc -# start a qp shell when run -CMD ["./qp2/bin/qpsh"] - - diff --git a/Makefile b/Makefile index 4125c19..8311818 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,6 @@ default: no-cache: docker build -t $(IMAGE) --no-cache . -compile: - docker build -t $(IMAGE) -f Dockerfile.compile . - compile-no-cache: docker build -t $(IMAGE) -f Dockerfile.compile --no-cache . .