File size: 5,811 Bytes
829e92a
17a0b0c
637465e
f482b1b
 
 
829e92a
637465e
 
 
 
17a0b0c
829e92a
f482b1b
637465e
 
829e92a
637465e
 
 
 
829e92a
637465e
 
829e92a
65c45d5
637465e
829e92a
65c45d5
637465e
829e92a
637465e
 
f482b1b
637465e
 
829e92a
 
637465e
 
65c45d5
 
f482b1b
829e92a
f482b1b
65c45d5
 
637465e
 
 
 
 
 
f482b1b
637465e
f482b1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
028be1b
829e92a
f482b1b
 
 
637465e
f482b1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829e92a
f482b1b
 
637465e
 
17a0b0c
637465e
17a0b0c
f482b1b
 
 
829e92a
f482b1b
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
113
114
115
116
117
118
119
120
121
122
# Используем базовый образ Node.js
FROM node:20-bookworm

# Работаем под root для установки и настройки WARP
USER root

# Установка необходимых зависимостей
RUN apt-get update && apt-get install -y \
    curl \
    gnupg \
    ca-certificates \
    lsb-release \
    iptables \
    sudo \
    && rm -rf /var/lib/apt/lists/*

# Установка Cloudflare WARP
RUN curl https://pkg.cloudflareclient.com/pubkey.gpg | gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/cloudflare-client.list
RUN apt-get update && apt-get install -y cloudflare-warp

# Создаем рабочую директорию
WORKDIR /app

# Генерируем package.json
RUN echo '{"name":"warp-express","version":"1.0.0","dependencies":{"express":"^4.18.2","axios":"^1.7.2","socks-proxy-agent":"^8.0.4"}}' > package.json

# Устанавливаем зависимости
RUN npm install

# Создаем файл приложения
RUN echo "const express = require('express');" > app.js \
    && echo "const axios = require('axios');" >> app.js \
    && echo "const { SocksProxyAgent } = require('socks-proxy-agent');" >> app.js \
    && echo "const app = express();" >> app.js \
    && echo "const port = 7860;" >> app.js \
    && echo "const proxyUrl = 'socks5://127.0.0.1:1080';" >> app.js \
    && echo "const agent = new SocksProxyAgent(proxyUrl);" >> app.js \
    && echo "app.get('/', async (req, res) => {" >> app.js \
    && echo "  try {" >> app.js \
    && echo "    const response = await axios.get('https://ip.oxylabs.io/location', { " >> app.js \
    && echo "      httpsAgent: agent," >> app.js \
    && echo "      httpAgent: agent," >> app.js \
    && echo "      proxy: false," >> app.js \
    && echo "      timeout: 10000" >> app.js \
    && echo "    });" >> app.js \
    && echo "    res.type('json').send(JSON.stringify(response.data, null, 2));" >> app.js \
    && echo "  } catch (error) {" >> app.js \
    && echo "    res.status(500).send('Error: ' + error.message);" >> app.js \
    && echo "  }" >> app.js \
    && echo "});" >> app.js \
    && echo "app.listen(port, () => console.log('Server running on port ' + port));" >> app.js

# Скрипт запуска
RUN echo '#!/bin/bash' > /entrypoint.sh \
    && echo 'set -e' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Запуск WARP сервиса с правами root' >> /entrypoint.sh \
    && echo 'echo "Starting WARP service..."' >> /entrypoint.sh \
    && echo '/usr/bin/warp-svc &' >> /entrypoint.sh \
    && echo 'WARP_PID=$!' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Ждём запуска сервиса' >> /entrypoint.sh \
    && echo 'echo "Waiting for WARP service to start..."' >> /entrypoint.sh \
    && echo 'sleep 10' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Проверяем статус сервиса' >> /entrypoint.sh \
    && echo 'for i in {1..5}; do' >> /entrypoint.sh \
    && echo '  if warp-cli status 2>/dev/null; then' >> /entrypoint.sh \
    && echo '    echo "WARP service is running"' >> /entrypoint.sh \
    && echo '    break' >> /entrypoint.sh \
    && echo '  fi' >> /entrypoint.sh \
    && echo '  echo "Waiting for service... attempt $i"' >> /entrypoint.sh \
    && echo '  sleep 5' >> /entrypoint.sh \
    && echo 'done' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Регистрация' >> /entrypoint.sh \
    && echo 'echo "Registering WARP..."' >> /entrypoint.sh \
    && echo 'yes | warp-cli registration new || true' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Настройка режима прокси' >> /entrypoint.sh \
    && echo 'echo "Setting proxy mode..."' >> /entrypoint.sh \
    && echo 'warp-cli mode proxy' >> /entrypoint.sh \
    && echo 'warp-cli proxy port 1080' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Подключение' >> /entrypoint.sh \
    && echo 'echo "Connecting to WARP..."' >> /entrypoint.sh \
    && echo 'warp-cli connect' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Проверка подключения' >> /entrypoint.sh \
    && echo 'sleep 5' >> /entrypoint.sh \
    && echo 'warp-cli status' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Функция ротации IP' >> /entrypoint.sh \
    && echo 'rotate_ip() {' >> /entrypoint.sh \
    && echo '  while true; do' >> /entrypoint.sh \
    && echo '    sleep 300' >> /entrypoint.sh \
    && echo '    echo "Rotating IP..."' >> /entrypoint.sh \
    && echo '    warp-cli disconnect || true' >> /entrypoint.sh \
    && echo '    sleep 5' >> /entrypoint.sh \
    && echo '    warp-cli connect || true' >> /entrypoint.sh \
    && echo '    echo "IP rotated at $(date)"' >> /entrypoint.sh \
    && echo '  done' >> /entrypoint.sh \
    && echo '}' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Запуск ротации в фоне' >> /entrypoint.sh \
    && echo 'rotate_ip &' >> /entrypoint.sh \
    && echo '' >> /entrypoint.sh \
    && echo '# Запуск Express сервера' >> /entrypoint.sh \
    && echo 'echo "Starting Express server..."' >> /entrypoint.sh \
    && echo 'exec node app.js' >> /entrypoint.sh \
    && chmod +x /entrypoint.sh

# Открываем порт
EXPOSE 7860

# Запускаем как root для работы с WARP
USER root

# Запускаем скрипт
CMD ["/bin/bash", "/entrypoint.sh"]