Alexainc commited on
Commit
a6a6c5a
·
1 Parent(s): fbd091f

Diagnostic: Add connectivity test and switch to node:18-slim non-root user

Browse files
Files changed (2) hide show
  1. Dockerfile +17 -17
  2. bot.js +18 -0
Dockerfile CHANGED
@@ -1,7 +1,6 @@
1
- FROM node:18
2
 
3
- # Install dependencies for Tesseract.js (if needed by sharp or other system libs)
4
- # and Python for easyocr
5
  RUN apt-get update && apt-get install -y \
6
  python3 \
7
  python3-pip \
@@ -9,26 +8,27 @@ RUN apt-get update && apt-get install -y \
9
  tesseract-ocr \
10
  libtesseract-dev \
11
  libgl1-mesa-glx \
 
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- WORKDIR /app
 
 
15
 
16
- # Set up Python virtual environment to avoid "break-system-packages" issues
17
- RUN python3 -m venv /opt/venv
18
- ENV PATH="/opt/venv/bin:$PATH"
 
19
 
20
- # Copy package files and install Node dependencies
21
- COPY package*.json ./
 
 
 
22
  RUN npm install
23
 
24
- # Install Python dependencies
25
- RUN pip install --no-cache-dir easyocr
26
-
27
- # Copy the rest of the application
28
- COPY . .
29
-
30
- # Ensure the public directory is available
31
- RUN mkdir -p public
32
 
33
  # Environment variables
34
  ENV PORT=7860
 
1
+ FROM node:18-slim
2
 
3
+ # Install system dependencies
 
4
  RUN apt-get update && apt-get install -y \
5
  python3 \
6
  python3-pip \
 
8
  tesseract-ocr \
9
  libtesseract-dev \
10
  libgl1-mesa-glx \
11
+ git \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Set up the app directory with correct permissions for the 'node' user
15
+ WORKDIR /home/node/app
16
+ RUN chown -R node:node /home/node/app
17
 
18
+ # Switch to non-root user
19
+ USER node
20
+ ENV HOME=/home/node \
21
+ PATH="/home/node/.local/bin:/opt/venv/bin:$PATH"
22
 
23
+ # Set up Python virtual environment (if allowed in home)
24
+ # For simplicity in this container, we'll install python libs in the node home if needed
25
+ # but let's stick to the previous venv logic if possible, adjusted for permissions
26
+ # Actually, let's keep it simple: install node deps first
27
+ COPY --chown=node:node package*.json ./
28
  RUN npm install
29
 
30
+ # Copy the rest
31
+ COPY --chown=node:node . .
 
 
 
 
 
 
32
 
33
  # Environment variables
34
  ENV PORT=7860
bot.js CHANGED
@@ -16,6 +16,24 @@ const stats = {
16
  botUsername: 'Loading...'
17
  };
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  // Load dictionary into memory for safety and speed
20
  const dictionaryPath = path.join(__dirname, 'node_modules/check-word/words/en.txt');
21
  const dictionary = new Set();
 
16
  botUsername: 'Loading...'
17
  };
18
 
19
+ // --- Connectivity Diagnostic Test ---
20
+ (async function testConnectivity() {
21
+ console.log('--- Connectivity Test ---');
22
+ try {
23
+ const response = await axios.get(`https://api.telegram.org/bot${BOT_TOKEN}/getMe`, { timeout: 10000 });
24
+ console.log('✅ Connectivity Test (Axios): SUCCESS');
25
+ console.log('Bot Username from Axios:', response.data.result.username);
26
+ } catch (err) {
27
+ console.error('❌ Connectivity Test (Axios): FAILED');
28
+ console.error('Error Code:', err.code);
29
+ console.error('Error Message:', err.message);
30
+ if (err.response) {
31
+ console.error('Response Status:', err.response.status);
32
+ }
33
+ }
34
+ console.log('-------------------------');
35
+ })();
36
+
37
  // Load dictionary into memory for safety and speed
38
  const dictionaryPath = path.join(__dirname, 'node_modules/check-word/words/en.txt');
39
  const dictionary = new Set();