File size: 4,086 Bytes
d8913ed
1afc99f
d8913ed
 
 
 
 
 
 
 
 
 
ece0691
d8913ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca59b57
70e0304
d8913ed
 
009b841
a7890d8
d8913ed
 
 
 
 
 
 
 
5efefc7
d8913ed
 
 
 
a7890d8
d8913ed
 
 
 
 
 
 
3b2cb0c
d8913ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
877c479
e60d88a
d8913ed
 
 
 
 
 
59209d6
 
01bafed
59209d6
 
 
 
e080a07
 
59209d6
 
 
 
fb04ff4
 
 
d8913ed
 
fb04ff4
e6710a1
d8913ed
be48c67
d8913ed
808c7fb
d8913ed
 
91a7855
808c7fb
 
d8913ed
91a7855
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Pull the base image
FROM vaibhavarduino/librechat:latest
# FROM librechat/librechat-dev:latest

# Set environment variables (Consider moving sensitive ones like ngrok token to build args or runtime envs)
ENV HOST=0.0.0.0 \
    PORT=7860 \
    SESSION_EXPIRY=900000 \
    REFRESH_TOKEN_EXPIRY=604800000 \
    # MEILI_NO_ANALYTICS=true \
    # MEILI_HOST=https://librechat-meilisearch.hf.space \
    PYTHONUNBUFFERED=1 \
    NGROK_AUTHTOKEN=2vPTfcN3MOK2T12aE2fxtBzjxue_6ejqTQUkkWqZfRm2QAN49 

# Combine directory creation and permission setting
RUN mkdir -p /app/uploads/temp \
    /app/client/public/images/temp \
    /app/api/logs/ \
    /app/data \
    /app/code_interpreter && \
    chmod -R 777 /app/uploads/temp \
    /app/client/public/images \
    /app/api/logs/ \
    /app/data \
    /app/code_interpreter

# Copy configuration and tests
COPY librechat.yaml /app/librechat.yaml
COPY tests.py /app/tests.py

# --- Build Stage ---
# Temporarily switch to root for package installation
USER root
RUN sed -i 's/#\(.*\/community\)/\1/' /etc/apk/repositories
# Install Node.js dependencies first (leverages layer cache if package.json doesn't change often)
# Assuming package.json is in /app/api in the base image or copied before
# If not, uncomment and adjust COPY commands if needed:
# COPY api/package.json api/package-lock.json* ./api/
RUN cd /app/api && npm install --omit=dev --no-audit --no-fund --prefer-offline && npm cache clean --force
# Note: Using --omit=dev might break if runtime needs dev deps. Remove if necessary.
# --prefer-offline might help if network is slow/flaky, uses cache more aggressively.
# npm cache clean --force might free up a little space within the layer.
RUN wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz -O ngrok.tgz && tar xvzf ngrok.tgz &&  cp ngrok /usr/local/bin && rm ngrok.tgz
# Install system dependencies (including build tools), Python packages, and cleanup in one RUN command
# Reduces layers and removes build tools afterwards
RUN apk add --no-cache --virtual .build-deps \
        build-base \
        sudo \
        gcc \
        libc-dev \
        mpc1-dev \
        python3-dev && \
    apk add --no-cache \
        bash \
        git \
        shadow \
        libc6-compat \
        py3-pip \
        python3 && \
    ln -sf python3 /usr/bin/python && \
    # Consider specific versions if needed: python3~=3.10
    echo "Starting pip install..." && \
    pip3 install --no-cache-dir --upgrade --break-system-packages \
        pip \
        setuptools \
        mcp \
        mcp-simple-pubmed \
        mcp-simple-arxiv \
        litellm \
        gradio \
        XlsxWriter \
        openpyxl \
        google-genai \
        matplotlib \
        requests-futures \
        pexpect && \
    # (Add back commented packages here if needed, e.g., actors-mcp-server)
    echo "Pip install finished. Cleaning up..." && \
    apk del .build-deps && \
    rm -rf /var/cache/apk/* /root/.cache /tmp/* && \
    echo "Cleanup finished."
USER root
# RUN adduser -S -D -u 0 admin

# # (Optional) Add the admin user to the root group for completeness
# RUN addgroup admin root
RUN useradd -m -s /bin/bash admin
RUN passwd -d admin
# RUN admin ALL=ALL NOPASSWD: ALL
RUN usermod -aG sudo admin
USER admin
# # Switch to the admin user (now root-equivalent)
# USER admin
RUN su - admin
WORKDIR /app
RUN git clone https://github.com/AIGENHACKER/mcp-hfspace && cd mcp-hfspace && npm install && npm run build && npm link
RUN git clone https://github.com/exa-labs/exa-mcp-server  && cd exa-mcp-server  && npm install --save axios dotenv && npm run build && npm link
# Switch back to the non-root user defined in the base image (assuming 'node')
# Check the base image documentation if unsure about the default user

USER node
# Set the working directory (good practice)
RUN ngrok config add-authtoken $NGROK_AUTHTOKEN


# Expose the port the app runs on
EXPOSE 7860
USER root
RUN npm install -g express ejs chart.js && npm cache clean --force

# Define the command to run the application
CMD ["npm", "run", "backend"]