File size: 4,056 Bytes
d8913ed
1afc99f
d8913ed
 
 
 
 
 
 
 
 
 
ece0691
d8913ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca59b57
70e0304
d8913ed
 
009b841
a7890d8
d8913ed
 
 
 
 
 
 
 
5efefc7
d8913ed
 
 
 
 
 
 
 
 
 
b7d063d
54c124a
d8913ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
877c479
e60d88a
d8913ed
 
 
 
 
 
01bafed
eee17f3
60a73e7
4ddf07b
a12894c
fb04ff4
 
 
d8913ed
 
4ccc076
421a955
b7d063d
 
71accfc
ff480ef
 
e4b2bf0
d8913ed
 
91a7855
808c7fb
1128b44
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
# 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 \
        gcc \
        libc-dev \
        mpc1-dev \
        python3-dev && \
    apk add --no-cache \
        bash \
        git  \ 
        busybox-suid \
        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 node 
RUN ngrok config add-authtoken $NGROK_AUTHTOKEN
RUN su root
USER root 
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
RUN echo "node ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/node && \
    chmod 0440 /etc/sudoers.d/node
#RUN  usermod -aG root node
#RUN  usermod -aG wheel node
RUN addgroup  -S node root
# RUN adduser node -G wheel
# RUN adduser node -G root
RUN echo 'permit nopass :node as root' >> /etc/doas.d/doas.conf
# Expose the port the app runs on
EXPOSE 7860
USER root
RUN npm install -g express ejs chart.js && npm cache clean --force
#RUN chmod u+s /usr/local/bin/doas  
# Define the command to run the application
CMD ["npm", "run", "backend"]