opex792 commited on
Commit
f482b1b
·
verified ·
1 Parent(s): 829e92a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +64 -19
Dockerfile CHANGED
@@ -1,6 +1,9 @@
1
  # Используем базовый образ Node.js
2
  FROM node:20-bookworm
3
 
 
 
 
4
  # Установка необходимых зависимостей
5
  RUN apt-get update && apt-get install -y \
6
  curl \
@@ -8,6 +11,7 @@ RUN apt-get update && apt-get install -y \
8
  ca-certificates \
9
  lsb-release \
10
  iptables \
 
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
  # Установка Cloudflare WARP
@@ -27,7 +31,7 @@ RUN npm install
27
  # Создаем файл приложения
28
  RUN echo "const express = require('express');" > app.js \
29
  && echo "const axios = require('axios');" >> app.js \
30
- && echo "const SocksProxyAgent = require('socks-proxy-agent');" >> app.js \
31
  && echo "const app = express();" >> app.js \
32
  && echo "const port = 7860;" >> app.js \
33
  && echo "const proxyUrl = 'socks5://127.0.0.1:1080';" >> app.js \
@@ -36,8 +40,9 @@ RUN echo "const express = require('express');" > app.js \
36
  && echo " try {" >> app.js \
37
  && echo " const response = await axios.get('https://ip.oxylabs.io/location', { " >> app.js \
38
  && echo " httpsAgent: agent," >> app.js \
 
39
  && echo " proxy: false," >> app.js \
40
- && echo " timeout: 5000" >> app.js \
41
  && echo " });" >> app.js \
42
  && echo " res.type('json').send(JSON.stringify(response.data, null, 2));" >> app.js \
43
  && echo " } catch (error) {" >> app.js \
@@ -46,31 +51,71 @@ RUN echo "const express = require('express');" > app.js \
46
  && echo "});" >> app.js \
47
  && echo "app.listen(port, () => console.log('Server running on port ' + port));" >> app.js
48
 
49
- # Скрипт запуска (в одном файле)
50
  RUN echo '#!/bin/bash' > /entrypoint.sh \
51
- && echo '# Запуск WARP сервиса' >> /entrypoint.sh \
52
- && echo 'warp-svc &' >> /entrypoint.sh \
53
- && echo 'sleep 5' >> /entrypoint.sh \
54
- && echo '# Регистрация и настройка' >> /entrypoint.sh \
55
- && echo 'warp-cli registration new --accept-tos' >> /entrypoint.sh \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  && echo 'warp-cli mode proxy' >> /entrypoint.sh \
57
  && echo 'warp-cli proxy port 1080' >> /entrypoint.sh \
58
- && echo '# Первоначальное подключение' >> /entrypoint.sh \
 
 
59
  && echo 'warp-cli connect' >> /entrypoint.sh \
60
- && echo '# Цикл ротации IP каждые 5 минут' >> /entrypoint.sh \
61
- && echo 'while true; do' >> /entrypoint.sh \
62
- && echo ' sleep 300' >> /entrypoint.sh \
63
- && echo ' warp-cli disconnect' >> /entrypoint.sh \
64
- && echo ' sleep 5' >> /entrypoint.sh \
65
- && echo ' warp-cli connect' >> /entrypoint.sh \
66
- && echo ' echo "IP rotated at $(date)"' >> /entrypoint.sh \
67
- && echo 'done &' >> /entrypoint.sh \
 
 
 
 
 
 
 
 
 
 
 
 
68
  && echo '# Запуск Express сервера' >> /entrypoint.sh \
69
- && echo 'node app.js' >> /entrypoint.sh \
 
70
  && chmod +x /entrypoint.sh
71
 
72
  # Открываем порт
73
  EXPOSE 7860
74
 
 
 
 
75
  # Запускаем скрипт
76
- CMD ["/bin/bash", "/entrypoint.sh"]
 
1
  # Используем базовый образ Node.js
2
  FROM node:20-bookworm
3
 
4
+ # Работаем под root для установки и настройки WARP
5
+ USER root
6
+
7
  # Установка необходимых зависимостей
8
  RUN apt-get update && apt-get install -y \
9
  curl \
 
11
  ca-certificates \
12
  lsb-release \
13
  iptables \
14
+ sudo \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
  # Установка Cloudflare WARP
 
31
  # Создаем файл приложения
32
  RUN echo "const express = require('express');" > app.js \
33
  && echo "const axios = require('axios');" >> app.js \
34
+ && echo "const { SocksProxyAgent } = require('socks-proxy-agent');" >> app.js \
35
  && echo "const app = express();" >> app.js \
36
  && echo "const port = 7860;" >> app.js \
37
  && echo "const proxyUrl = 'socks5://127.0.0.1:1080';" >> app.js \
 
40
  && echo " try {" >> app.js \
41
  && echo " const response = await axios.get('https://ip.oxylabs.io/location', { " >> app.js \
42
  && echo " httpsAgent: agent," >> app.js \
43
+ && echo " httpAgent: agent," >> app.js \
44
  && echo " proxy: false," >> app.js \
45
+ && echo " timeout: 10000" >> app.js \
46
  && echo " });" >> app.js \
47
  && echo " res.type('json').send(JSON.stringify(response.data, null, 2));" >> app.js \
48
  && echo " } catch (error) {" >> app.js \
 
51
  && echo "});" >> app.js \
52
  && echo "app.listen(port, () => console.log('Server running on port ' + port));" >> app.js
53
 
54
+ # Скрипт запуска
55
  RUN echo '#!/bin/bash' > /entrypoint.sh \
56
+ && echo 'set -e' >> /entrypoint.sh \
57
+ && echo '' >> /entrypoint.sh \
58
+ && echo '# Запуск WARP сервиса с правами root' >> /entrypoint.sh \
59
+ && echo 'echo "Starting WARP service..."' >> /entrypoint.sh \
60
+ && echo '/usr/bin/warp-svc &' >> /entrypoint.sh \
61
+ && echo 'WARP_PID=$!' >> /entrypoint.sh \
62
+ && echo '' >> /entrypoint.sh \
63
+ && echo '# Ждём запуска сервиса' >> /entrypoint.sh \
64
+ && echo 'echo "Waiting for WARP service to start..."' >> /entrypoint.sh \
65
+ && echo 'sleep 10' >> /entrypoint.sh \
66
+ && echo '' >> /entrypoint.sh \
67
+ && echo '# Проверяем статус сервиса' >> /entrypoint.sh \
68
+ && echo 'for i in {1..5}; do' >> /entrypoint.sh \
69
+ && echo ' if warp-cli status 2>/dev/null; then' >> /entrypoint.sh \
70
+ && echo ' echo "WARP service is running"' >> /entrypoint.sh \
71
+ && echo ' break' >> /entrypoint.sh \
72
+ && echo ' fi' >> /entrypoint.sh \
73
+ && echo ' echo "Waiting for service... attempt $i"' >> /entrypoint.sh \
74
+ && echo ' sleep 5' >> /entrypoint.sh \
75
+ && echo 'done' >> /entrypoint.sh \
76
+ && echo '' >> /entrypoint.sh \
77
+ && echo '# Регистрация' >> /entrypoint.sh \
78
+ && echo 'echo "Registering WARP..."' >> /entrypoint.sh \
79
+ && echo 'yes | warp-cli registration new || true' >> /entrypoint.sh \
80
+ && echo '' >> /entrypoint.sh \
81
+ && echo '# Настройка режима прокси' >> /entrypoint.sh \
82
+ && echo 'echo "Setting proxy mode..."' >> /entrypoint.sh \
83
  && echo 'warp-cli mode proxy' >> /entrypoint.sh \
84
  && echo 'warp-cli proxy port 1080' >> /entrypoint.sh \
85
+ && echo '' >> /entrypoint.sh \
86
+ && echo '# Подключение' >> /entrypoint.sh \
87
+ && echo 'echo "Connecting to WARP..."' >> /entrypoint.sh \
88
  && echo 'warp-cli connect' >> /entrypoint.sh \
89
+ && echo '' >> /entrypoint.sh \
90
+ && echo '# Проверка подключения' >> /entrypoint.sh \
91
+ && echo 'sleep 5' >> /entrypoint.sh \
92
+ && echo 'warp-cli status' >> /entrypoint.sh \
93
+ && echo '' >> /entrypoint.sh \
94
+ && echo '# Функция ротации IP' >> /entrypoint.sh \
95
+ && echo 'rotate_ip() {' >> /entrypoint.sh \
96
+ && echo ' while true; do' >> /entrypoint.sh \
97
+ && echo ' sleep 300' >> /entrypoint.sh \
98
+ && echo ' echo "Rotating IP..."' >> /entrypoint.sh \
99
+ && echo ' warp-cli disconnect || true' >> /entrypoint.sh \
100
+ && echo ' sleep 5' >> /entrypoint.sh \
101
+ && echo ' warp-cli connect || true' >> /entrypoint.sh \
102
+ && echo ' echo "IP rotated at $(date)"' >> /entrypoint.sh \
103
+ && echo ' done' >> /entrypoint.sh \
104
+ && echo '}' >> /entrypoint.sh \
105
+ && echo '' >> /entrypoint.sh \
106
+ && echo '# Запуск ротации в фоне' >> /entrypoint.sh \
107
+ && echo 'rotate_ip &' >> /entrypoint.sh \
108
+ && echo '' >> /entrypoint.sh \
109
  && echo '# Запуск Express сервера' >> /entrypoint.sh \
110
+ && echo 'echo "Starting Express server..."' >> /entrypoint.sh \
111
+ && echo 'exec node app.js' >> /entrypoint.sh \
112
  && chmod +x /entrypoint.sh
113
 
114
  # Открываем порт
115
  EXPOSE 7860
116
 
117
+ # Запускаем как root для работы с WARP
118
+ USER root
119
+
120
  # Запускаем скрипт
121
+ CMD ["/bin/bash", "/entrypoint.sh"]