File size: 1,754 Bytes
9e909f5
 
 
 
 
 
 
72d25de
9e909f5
 
 
 
 
 
72d25de
9e909f5
 
 
 
72d25de
74ebbc8
9e909f5
a882b66
9e909f5
 
 
 
 
 
72d25de
 
74ebbc8
 
9e909f5
 
72d25de
 
74ebbc8
9e909f5
 
74ebbc8
9e909f5
 
72d25de
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
# Declare the base image
FROM rocker/r-ver:latest

# Considerations for local development: reduce Docker cache size and rebuild time
#   Single RUN directive and two COPY directives
#     Pre-RUN COPY for relatively stable files, post-RUN COPY for app files
#   Avoid other directives like USER and ENV
#     startup.sh activates the virtual environment for running the app
# Considerations for remote development (HF Spaces Dev Mode)
#   Dev Mode requires useradd, chown and USER
#   Use CMD instead of ENTRYPOINT

# Set working directory and copy non-app files
WORKDIR /app
COPY requirements.txt entrypoint.sh .

# Install Python and system tools
# Create and activate virtual environment for installing packages
# Install required Python and R packages
# Rename startup script and make it executable
# Add user with uid=1000 and chown /app directory for HF Spaces Dev Mode
RUN apt-get update && \
    apt-get install -y python3 python3-pip python3-venv screen vim git && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    python3 -m venv /opt/venv && \
    export PATH="/opt/venv/bin:$PATH" && \
    pip --no-cache-dir install -r requirements.txt && \
    R -q -e 'install.packages(c("ellmer", "mcptools", "readr", "ggplot2", "tidyverse"))' && \
    cp entrypoint.sh startup.sh && \
    chmod +x startup.sh && \
    useradd -m -u 1000 user && \
    chown -R user /app
    
# Copy app files with user permissions
# NOTE: This overwrites all copied files, rendering them non-executable. That is why we
# created an executable file with a different name (startup.sh) that is not overwritten here.
COPY --chown=user . /app

# Set the user for Dev Mode
USER user

# Set default command (executable file in WORKDIR)
CMD [ "/app/startup.sh" ]