refactor: Switch to multi-stage build
This commit is contained in:
parent
58759e3314
commit
ebcbb53cb1
2 changed files with 285 additions and 106 deletions
|
@ -1,116 +1,248 @@
|
||||||
FROM ubuntu:bionic
|
###
|
||||||
|
### R base image
|
||||||
|
### Based on r-ver
|
||||||
|
###
|
||||||
|
FROM debian:buster AS rver
|
||||||
|
|
||||||
ENV R_VERSION=3.6.3
|
LABEL org.label-schema.license="GPL-2.0" \
|
||||||
ENV ROCKER_VERSION=4.1.1
|
org.label-schema.vcs-url="https://github.com/rocker-org/rocker-versioned" \
|
||||||
ENV R_HOME=/usr/local/lib/R
|
org.label-schema.vendor="Rocker Project" \
|
||||||
ENV TZ=Etc/UTC
|
maintainer="Carl Boettiger <cboettig@ropensci.org>"
|
||||||
ENV SAMTOOLS_VERSION=1.2
|
|
||||||
|
ARG R_VERSION
|
||||||
|
ARG BUILD_DATE
|
||||||
|
ARG CRAN
|
||||||
|
ENV BUILD_DATE ${BUILD_DATE:-2020-04-24}
|
||||||
|
ENV R_VERSION=${R_VERSION:-3.6.3} \
|
||||||
|
CRAN=${CRAN:-https://cran.r-project.org} \
|
||||||
|
LC_ALL=en_US.UTF-8 \
|
||||||
|
LANG=en_US.UTF-8 \
|
||||||
|
TERM=xterm
|
||||||
|
|
||||||
RUN <<END_RUN_CMD
|
RUN <<END_RUN_CMD
|
||||||
# Install R
|
DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get update
|
apt-get update && apt-get install -y --no-install-recommends \
|
||||||
apt-get install --no-install-recommends -y \
|
bash-completion \
|
||||||
curl \
|
ca-certificates \
|
||||||
ca-certificates
|
file \
|
||||||
curl -L "https://github.com/rocker-org/rocker-versioned2/archive/refs/tags/R${ROCKER_VERSION}.tar.gz" | tar xvz
|
fonts-texgyre \
|
||||||
./rocker-versioned2-R${ROCKER_VERSION}/scripts/install_R.sh
|
g++ \
|
||||||
rm -rf rocker-versioned2-R${ROCKER_VERSION}
|
gfortran \
|
||||||
|
gsfonts \
|
||||||
# Install BioPerl
|
libblas-dev \
|
||||||
apt-get update
|
libbz2-1.0 \
|
||||||
apt-get install --no-install-recommends -y \
|
libcurl4 \
|
||||||
curl \
|
libicu63 \
|
||||||
perl \
|
libjpeg62-turbo \
|
||||||
cpanminus \
|
libopenblas-dev \
|
||||||
build-essential \
|
libpangocairo-1.0-0 \
|
||||||
|
libpcre3 \
|
||||||
|
libpng16-16 \
|
||||||
|
libreadline7 \
|
||||||
|
libtiff5 \
|
||||||
|
liblzma5 \
|
||||||
|
locales \
|
||||||
make \
|
make \
|
||||||
libexpat1-dev \
|
unzip \
|
||||||
libssl-dev \
|
zip \
|
||||||
zlib1g-dev \
|
zlib1g
|
||||||
libncurses5-dev
|
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
|
||||||
|
locale-gen en_US.utf8
|
||||||
|
/usr/sbin/update-locale LANG=en_US.UTF-8
|
||||||
|
BUILDDEPS="curl \
|
||||||
|
default-jdk \
|
||||||
|
libbz2-dev \
|
||||||
|
libcairo2-dev \
|
||||||
|
libcurl4-openssl-dev \
|
||||||
|
libpango1.0-dev \
|
||||||
|
libjpeg-dev \
|
||||||
|
libicu-dev \
|
||||||
|
libpcre3-dev \
|
||||||
|
libpng-dev \
|
||||||
|
libreadline-dev \
|
||||||
|
libtiff5-dev \
|
||||||
|
liblzma-dev \
|
||||||
|
libx11-dev \
|
||||||
|
libxt-dev \
|
||||||
|
perl \
|
||||||
|
tcl8.6-dev \
|
||||||
|
tk8.6-dev \
|
||||||
|
texinfo \
|
||||||
|
texlive-extra-utils \
|
||||||
|
texlive-fonts-recommended \
|
||||||
|
texlive-fonts-extra \
|
||||||
|
texlive-latex-recommended \
|
||||||
|
x11proto-core-dev \
|
||||||
|
xauth \
|
||||||
|
xfonts-base \
|
||||||
|
xvfb \
|
||||||
|
zlib1g-dev"
|
||||||
|
apt-get install -y --no-install-recommends $BUILDDEPS
|
||||||
|
## Download source code
|
||||||
|
curl -O https://cran.r-project.org/src/base/R-3/R-${R_VERSION}.tar.gz
|
||||||
|
## Extract source code
|
||||||
|
tar -xf R-${R_VERSION}.tar.gz
|
||||||
|
cd R-${R_VERSION}
|
||||||
|
## Set compiler flags
|
||||||
|
R_PAPERSIZE=letter \
|
||||||
|
R_BATCHSAVE="--no-save --no-restore"
|
||||||
|
R_BROWSER=xdg-open
|
||||||
|
PAGER=/usr/bin/pager
|
||||||
|
PERL=/usr/bin/perl
|
||||||
|
R_UNZIPCMD=/usr/bin/unzip
|
||||||
|
R_ZIPCMD=/usr/bin/zip
|
||||||
|
R_PRINTCMD=/usr/bin/lpr
|
||||||
|
LIBnn=lib
|
||||||
|
AWK=/usr/bin/awk
|
||||||
|
CFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g"
|
||||||
|
CXXFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g"
|
||||||
|
## Configure options
|
||||||
|
./configure --enable-R-shlib \
|
||||||
|
--enable-memory-profiling \
|
||||||
|
--with-readline \
|
||||||
|
--with-blas \
|
||||||
|
--with-tcltk \
|
||||||
|
--disable-nls \
|
||||||
|
--with-recommended-packages \
|
||||||
|
--prefix /usr/local
|
||||||
|
## Build and install
|
||||||
|
make -j $(nproc) -O
|
||||||
|
make install
|
||||||
|
## Add a library directory (for user-installed packages)
|
||||||
|
mkdir -p /usr/local/lib/R/site-library
|
||||||
|
chown root:staff /usr/local/lib/R/site-library
|
||||||
|
chmod g+ws /usr/local/lib/R/site-library
|
||||||
|
## Fix library path
|
||||||
|
sed -i '/^R_LIBS_USER=.*$/d' /usr/local/lib/R/etc/Renviron
|
||||||
|
echo "R_LIBS_USER=\${R_LIBS_USER-'/usr/local/lib/R/site-library'}" >> /usr/local/lib/R/etc/Renviron
|
||||||
|
echo "R_LIBS=\${R_LIBS-'/usr/local/lib/R/site-library:/usr/local/lib/R/library:/usr/lib/R/library'}" >> /usr/local/lib/R/etc/Renviron
|
||||||
|
echo "options(repos = c(CRAN='$CRAN'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site
|
||||||
|
## Clean up from R source install
|
||||||
|
apt-get remove --purge -y $BUILDDEPS
|
||||||
|
apt-get autoremove -y
|
||||||
|
apt-get autoclean -y
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
END_RUN_CMD
|
||||||
|
|
||||||
|
###
|
||||||
|
### Added Bioconductor packages to r-ver
|
||||||
|
###
|
||||||
|
FROM rver as bioconductor
|
||||||
|
RUN <<END_RUN_CMD
|
||||||
|
apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
zlib1g-dev
|
||||||
|
|
||||||
|
R -e "install.packages('BiocManager', repos='https://cran.r-project.org')"
|
||||||
|
R -e "BiocManager::install('Biostrings')"
|
||||||
|
R -e "BiocManager::install('seqinr')"
|
||||||
|
|
||||||
|
apt-get autoremove -y
|
||||||
|
apt-get autoclean -y
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
END_RUN_CMD
|
||||||
|
|
||||||
|
###
|
||||||
|
### Perl base image
|
||||||
|
###
|
||||||
|
FROM buildpack-deps:buster AS perl
|
||||||
|
LABEL maintainer="Peter Martini <PeterCMartini@GMail.com>, Zak B. Elep <zakame@cpan.org>"
|
||||||
|
|
||||||
|
RUN <<END_RUN_CMD
|
||||||
|
curl -fL https://www.cpan.org/src/5.0/perl-5.34.1.tar.xz -o perl-5.34.1.tar.xz
|
||||||
|
tar --strip-components=1 -xaf perl-5.34.1.tar.xz -C /usr/src/perl
|
||||||
|
rm perl-5.34.1.tar.xz
|
||||||
|
cat *.patch | patch -p1
|
||||||
|
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"
|
||||||
|
archBits="$(dpkg-architecture --query DEB_BUILD_ARCH_BITS)"
|
||||||
|
archFlag="$([ "$archBits" = '64' ] && echo '-Duse64bitall' || echo '-Duse64bitint')"
|
||||||
|
./Configure -Darchname="$gnuArch" "$archFlag" -Dusethreads -Duseshrplib -Dvendorprefix=/usr/local -des
|
||||||
|
make -j$(nproc)
|
||||||
|
TEST_JOBS=$(nproc) make test_harness
|
||||||
|
make install
|
||||||
|
cd /usr/src
|
||||||
|
curl -fLO https://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7047.tar.gz
|
||||||
|
tar -xzf App-cpanminus-1.7047.tar.gz && cd App-cpanminus-1.7047 && perl bin/cpanm . && cd /root
|
||||||
|
cpanm IO::Socket::SSL
|
||||||
|
curl -fL https://raw.githubusercontent.com/skaji/cpm/0.997011/cpm -o /usr/local/bin/cpm
|
||||||
|
chmod +x /usr/local/bin/cpm
|
||||||
|
rm -fr /root/.cpanm /usr/src/perl /usr/src/App-cpanminus-1.7047*
|
||||||
|
END_RUN_CMD
|
||||||
|
|
||||||
|
###
|
||||||
|
### Added bioperl packaged
|
||||||
|
###
|
||||||
|
FROM perl AS bioperl
|
||||||
|
RUN <<END_RUN_CMD
|
||||||
cpanm -n -v Bio::Seq Bio::SeqIO Perl4::CoreLibs
|
cpanm -n -v Bio::Seq Bio::SeqIO Perl4::CoreLibs
|
||||||
|
END_RUN_CMD
|
||||||
|
|
||||||
# Install R packages
|
###
|
||||||
install2.r --error --skipinstalled BiocManager
|
### Samtools build
|
||||||
R -e "BiocManager::install(c('Biostrings', 'seqinr'))"
|
###
|
||||||
|
FROM buildpack-deps:buster AS samtools
|
||||||
# Install samtools
|
ARG SAMTOOLS_VERSION=1.2
|
||||||
|
RUN <<END_RUN_CMD
|
||||||
curl -L "https://github.com/samtools/samtools/releases/download/${SAMTOOLS_VERSION}/samtools-${SAMTOOLS_VERSION}.tar.bz2" | tar xvj
|
curl -L "https://github.com/samtools/samtools/releases/download/${SAMTOOLS_VERSION}/samtools-${SAMTOOLS_VERSION}.tar.bz2" | tar xvj
|
||||||
cd samtools-${SAMTOOLS_VERSION} && make && make install && cd ..
|
cd samtools-${SAMTOOLS_VERSION} && make && make install && cd ..
|
||||||
rm -rf samtools-${SAMTOOLS_VERSION}
|
|
||||||
|
|
||||||
# Install viquas
|
|
||||||
mkdir /viquas && \
|
|
||||||
curl -L "https://master.dl.sourceforge.net/project/viquas/ViQuaS1.3.tar.gz" | tar xvz -C /viquas --strip-components=1
|
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
apt-get remove -y \
|
|
||||||
build-essential \
|
|
||||||
make \
|
|
||||||
curl
|
|
||||||
rm -rf /var/lib/apt/lists
|
|
||||||
END_RUN_CMD
|
END_RUN_CMD
|
||||||
|
|
||||||
|
###
|
||||||
|
### Viquas extraction
|
||||||
|
###
|
||||||
|
FROM buildpack-deps:buster AS viquas
|
||||||
RUN <<END_RUN_CMD
|
RUN <<END_RUN_CMD
|
||||||
cat << 'EOF' > /usr/bin/viquas
|
mkdir /viquas
|
||||||
#!/bin/sh
|
curl -L "https://master.dl.sourceforge.net/project/viquas/ViQuaS1.3.tar.gz" | tar xvz -C /viquas --strip-components=1
|
||||||
USAGE="
|
|
||||||
USAGE:
|
|
||||||
viquas reference.fsa reads.bam [o r perform_richness diversity_region_length]
|
|
||||||
"
|
|
||||||
|
|
||||||
NUM_ARGS=$#
|
|
||||||
case $NUM_ARGS in
|
|
||||||
2)
|
|
||||||
;;
|
|
||||||
6)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "${USAGE}"
|
|
||||||
echo "Incorrect number of arguments: expecting 2 or 6"
|
|
||||||
exit 1
|
|
||||||
esac
|
|
||||||
|
|
||||||
PWD_BACKUP=$PWD
|
|
||||||
|
|
||||||
if [ ! -f "${1}" ]; then
|
|
||||||
echo "Error: ${1} is not a file"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "${2}" ]; then
|
|
||||||
echo "Error: ${2} is not a file"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
REFERENCE_FILE=$(basename "${1}")
|
|
||||||
BAM_FILE=$(basename "${2}")
|
|
||||||
|
|
||||||
cp "${1}" /viquas
|
|
||||||
cp "${2}" /viquas
|
|
||||||
|
|
||||||
cd /viquas || exit 1
|
|
||||||
|
|
||||||
case $NUM_ARGS in
|
|
||||||
2)
|
|
||||||
Rscript /viquas/ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}"
|
|
||||||
;;
|
|
||||||
6)
|
|
||||||
Rscript /viquas/ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}" "${@[3:]}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "${USAGE}"
|
|
||||||
echo "Incorrect number of arguments: expecting 2 or 6"
|
|
||||||
exit 1
|
|
||||||
esac
|
|
||||||
|
|
||||||
mv /viquas/ViQuaS-Spectrum.fa "${PWD_BACKUP}"
|
|
||||||
mv /viquas/ViQuaS-Richness.txt "${PWD_BACKUP}" 2> /dev/null
|
|
||||||
|
|
||||||
cd "${PWD_BACKUP}" || exit 1
|
|
||||||
EOF
|
|
||||||
chmod +x /usr/bin/viquas
|
|
||||||
chmod -R 777 /viquas
|
|
||||||
END_RUN_CMD
|
END_RUN_CMD
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
### Final build
|
||||||
|
###
|
||||||
|
FROM debian:buster as final
|
||||||
|
RUN <<END_RUN_CMD
|
||||||
|
apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
bash-completion \
|
||||||
|
file \
|
||||||
|
fonts-texgyre \
|
||||||
|
gfortran \
|
||||||
|
gsfonts \
|
||||||
|
libblas-dev \
|
||||||
|
libbz2-1.0 \
|
||||||
|
libcurl4 \
|
||||||
|
libicu63 \
|
||||||
|
libjpeg62-turbo \
|
||||||
|
libncurses5-dev \
|
||||||
|
libopenblas-dev \
|
||||||
|
libpangocairo-1.0-0 \
|
||||||
|
libpcre3 \
|
||||||
|
libpng16-16 \
|
||||||
|
libreadline7 \
|
||||||
|
libtiff5 \
|
||||||
|
liblzma5 \
|
||||||
|
locales \
|
||||||
|
unzip \
|
||||||
|
zip \
|
||||||
|
zlib1g
|
||||||
|
|
||||||
|
apt-get autoremove -y
|
||||||
|
apt-get autoclean -y
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
|
END_RUN_CMD
|
||||||
|
|
||||||
|
COPY --from=bioconductor /usr/local/bin /usr/local/bin
|
||||||
|
COPY --from=bioconductor /usr/local/lib /usr/local/lib
|
||||||
|
COPY --from=bioconductor /usr/local/share /usr/local/share
|
||||||
|
COPY --from=bioperl /usr/local/bin /usr/local/bin
|
||||||
|
COPY --from=bioperl /usr/local/lib /usr/local/lib
|
||||||
|
COPY --from=bioperl /usr/local/share /usr/local/share
|
||||||
|
COPY --from=bioperl /usr/share/perl /usr/share/perl
|
||||||
|
COPY --from=samtools /usr/local/bin /usr/local/bin
|
||||||
|
COPY --from=samtools /usr/local/lib /usr/local/lib
|
||||||
|
COPY --from=samtools /usr/local/share /usr/local/share
|
||||||
|
COPY --from=viquas /viquas /viquas
|
||||||
|
COPY --chmod=755 viquas /usr/local/bin/viquas
|
||||||
ENTRYPOINT [ "viquas" ]
|
ENTRYPOINT [ "viquas" ]
|
||||||
|
|
47
modules/viquas/viquas
Normal file
47
modules/viquas/viquas
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/bin/sh
|
||||||
|
USAGE="
|
||||||
|
USAGE:
|
||||||
|
viquas reference.fsa reads.bam [o r perform_richness diversity_region_length]
|
||||||
|
"
|
||||||
|
|
||||||
|
NUM_ARGS=$#
|
||||||
|
case $NUM_ARGS in
|
||||||
|
2)
|
||||||
|
;;
|
||||||
|
6)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "${USAGE}"
|
||||||
|
echo "Incorrect number of arguments: expecting 2 or 6"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! -f "${1}" ]; then
|
||||||
|
echo "Error: ${1} is not a file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "${2}" ]; then
|
||||||
|
echo "Error: ${2} is not a file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
REFERENCE_FILE=$(basename "${1}")
|
||||||
|
BAM_FILE=$(basename "${2}")
|
||||||
|
|
||||||
|
cp -r /viquas/{viquas_files,ViQuaS.R} .
|
||||||
|
|
||||||
|
case $NUM_ARGS in
|
||||||
|
2)
|
||||||
|
Rscript ./ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}"
|
||||||
|
;;
|
||||||
|
6)
|
||||||
|
Rscript ./ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}" "${@[3:]}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "${USAGE}"
|
||||||
|
echo "Incorrect number of arguments: expecting 2 or 6"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
rm -rf ./{viquas_files,ViQuaS.R}
|
Loading…
Reference in a new issue