#                           PUBLIC DOMAIN NOTICE
#              National Center for Biotechnology Information
#
# This software is a "United States Government Work" under the
# terms of the United States Copyright Act.  It was written as part of
# the authors' official duties as United States Government employees and
# thus cannot be copyrighted.  This software is freely available
# to the public for use.  The National Library of Medicine and the U.S.
# Government have not placed any restriction on its use or reproduction.
#   
# Although all reasonable efforts have been taken to ensure the accuracy
# and reliability of the software and data, the NLM and the U.S.
# Government do not and cannot warrant the performance or results that
# may be obtained by using this software or data.  The NLM and the U.S.
# Government disclaim all warranties, express or implied, including
# warranties of performance, merchantability or fitness for any particular
# purpose.
#   
# Please cite NCBI in any work or product based on this material.

FROM ncbi/blast:latest as blast
ARG version
LABEL Description="NCBI BLAST" Vendor="NCBI/NLM/NIH" Version=${version} Maintainer=camacho@ncbi.nlm.nih.gov

FROM google/cloud-sdk:slim
# FROM resets ARGs, thus repeated ARG instruction
ARG version

USER root
WORKDIR /root/

COPY requirements.txt .
RUN cat requirements.txt | grep -v elastic\-blast >tmp && mv tmp requirements.txt
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
    python3 -m pip install --no-cache-dir -r requirements.txt && \
    rm -frv requirements.txt

COPY src/ /blast/src/
COPY bin/ /blast/bin/
COPY requirements/ /blast/requirements/
COPY setup.py /blast/setup.py
COPY setup.cfg_cloud /blast/setup.cfg

WORKDIR /blast/
RUN python3 -m pip install .

WORKDIR /root/

RUN apt-get -y -m update && \
    apt-get install -y libgomp1 libnet-perl libidn11 libxml-simple-perl libjson-perl perl-doc liblmdb-dev time parallel vmtouch cpanminus curl wget libio-socket-ssl-perl libhtml-parser-perl unzip && \
	rm -rf /var/lib/apt/lists/*  

RUN mkdir -p /blast/bin /blast/lib
COPY --from=blast /blast/bin /blast/bin
COPY update_blastdb.pl /blast/bin
COPY --from=blast /blast/lib /blast/lib
COPY --from=blast /root/edirect /root/edirect
COPY splitq_download_db_search /blast/bin/
RUN sed -i -e "s/\$VERSION/$version/" /blast/bin/splitq_download_db_search
COPY fasta-split /blast/bin/


RUN mkdir -p /blast/blastdb /blast/blastdb_custom
RUN sed -i '$ a BLASTDB=/blast/blastdb:/blast/blastdb_custom' /etc/environment
ENV BLASTDB /blast/blastdb:/blast/blastdb_custom
ENV PATH="/root/edirect:/blast/bin:${PATH}"


WORKDIR /blast

CMD ["/bin/bash"]

