test627 / Dockerfile
opex792's picture
Update Dockerfile
f482b1b verified
# Используем базовый образ 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"]