File size: 2,169 Bytes
6ba63c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile

FROM continuumio/miniconda3:latest

# Add build argument to force rebuild
ARG CACHEBUST=1

# Avoid tzdata interactive configuration
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC

# Install system dependencies
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
    git \
    build-essential \
    python3-dev \
    wget \
    openmpi-bin \
    libopenmpi-dev \
    libopenmpi3 \
    libhwloc15 \
    libevent-dev \
    libpmix2 \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Set up OpenMPI environment
ENV OMPI_MCA_btl_vader_single_copy_mechanism=none \
    OMPI_ALLOW_RUN_AS_ROOT=1 \
    OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 \
    PATH=/usr/lib/x86_64-linux-gnu/openmpi/bin:$PATH \
    LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/openmpi/lib:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

# Copy environment file
COPY colabs/environment.yml /tmp/environment.yml

# Create conda environment
RUN conda env create -f /tmp/environment.yml && \
    conda run -n biomedparse pip install gradio==3.50.2

# Initialize conda in bash
RUN conda init bash

# Make RUN commands use the new environment
SHELL ["conda", "run", "-n", "biomedparse", "/bin/bash", "-c"]

# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Switch to the "user" user
USER user

# Set up HF token for the user
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
    echo "export HF_TOKEN=$(cat /run/secrets/HF_TOKEN)" >> $HOME/.bashrc

# Set home to the user's home directory
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Set the working directory to the user's home directory
WORKDIR $HOME/app

# Copy all files to the app directory
COPY --chown=user . $HOME/app

# Set permissions for entrypoint script
RUN chmod 755 $HOME/app/entrypoint.sh

# Add conda environment to user's path
RUN echo "conda activate biomedparse" >> $HOME/.bashrc

# Use entrypoint script to set up environment and run application
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["exec /home/user/app/entrypoint.sh"]