feat: add proxy for docker

This commit is contained in:
yidadaa
2023-04-09 20:35:42 +08:00
parent c8be5e4267
commit 1bb7b4a653
2 changed files with 21 additions and 12 deletions

View File

@@ -3,12 +3,12 @@ FROM node:18-alpine AS base
FROM base AS deps
RUN apk add --no-cache libc6-compat
RUN apk --no-cache add proxychains-ng
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn config set registry 'https://registry.npm.taobao.org'
RUN yarn install
FROM base AS builder
@@ -28,6 +28,8 @@ RUN yarn build
FROM base AS runner
WORKDIR /app
RUN apk add proxychains-ng
ENV PROXY_URL=""
ENV OPENAI_API_KEY=""
ENV CODE=""
@@ -43,8 +45,16 @@ CMD if [ -n "$PROXY_URL" ]; then \
protocol=$(echo $PROXY_URL | cut -d: -f1); \
host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \
port=$(echo $PROXY_URL | cut -d: -f3); \
echo "$protocol $host $port" >> /etc/proxychains.conf; \
proxychains node server.js; \
conf=/etc/proxychains.conf; \
echo "strict_chain" >> $conf; \
echo "proxy_dns" >> $conf; \
echo "remote_dns_subnet 224" >> $conf; \
echo "tcp_read_time_out 15000" >> $conf; \
echo "tcp_connect_time_out 8000" >> $conf; \
echo "[ProxyList]" >> $conf; \
echo "$protocol $host $port" >> $conf; \
cat /etc/proxychains.conf; \
proxychains -f $conf node server.js; \
else \
node server.js; \
fi
fi