Dockerfile 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. FROM node:18-alpine AS base
  2. FROM base AS deps
  3. RUN echo 'https://mirrors.aliyun.com/alpine/v3.19/main' > /etc/apk/repositories
  4. RUN echo 'https://mirrors.aliyun.com/alpine/v3.19/community' >> /etc/apk/repositories
  5. RUN apk add --no-cache libc6-compat
  6. WORKDIR /app
  7. COPY package.json yarn.lock ./
  8. RUN yarn config set registry 'https://registry.npmmirror.com/'
  9. RUN yarn install
  10. FROM base AS builder
  11. RUN echo 'https://mirrors.aliyun.com/alpine/v3.19/main' > /etc/apk/repositories
  12. RUN echo 'https://mirrors.aliyun.com/alpine/v3.19/community' >> /etc/apk/repositories
  13. RUN apk update && apk add --no-cache git
  14. ENV OPENAI_API_KEY=""
  15. ENV CODE=""
  16. WORKDIR /app
  17. COPY --from=deps /app/node_modules ./node_modules
  18. COPY . .
  19. RUN yarn build
  20. FROM base AS runner
  21. WORKDIR /app
  22. RUN echo 'https://mirrors.aliyun.com/alpine/v3.19/main' > /etc/apk/repositories
  23. RUN echo 'https://mirrors.aliyun.com/alpine/v3.19/community' >> /etc/apk/repositories
  24. RUN apk add proxychains-ng
  25. ENV PROXY_URL=""
  26. ENV OPENAI_API_KEY=""
  27. ENV CODE=""
  28. COPY --from=builder /app/public ./public
  29. COPY --from=builder /app/.next/standalone ./
  30. COPY --from=builder /app/.next/static ./.next/static
  31. COPY --from=builder /app/.next/server ./.next/server
  32. EXPOSE 3000
  33. CMD if [ -n "$PROXY_URL" ]; then \
  34. export HOSTNAME="127.0.0.1"; \
  35. protocol=$(echo $PROXY_URL | cut -d: -f1); \
  36. host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \
  37. port=$(echo $PROXY_URL | cut -d: -f3); \
  38. conf=/etc/proxychains.conf; \
  39. echo "strict_chain" > $conf; \
  40. echo "proxy_dns" >> $conf; \
  41. echo "remote_dns_subnet 224" >> $conf; \
  42. echo "tcp_read_time_out 15000" >> $conf; \
  43. echo "tcp_connect_time_out 8000" >> $conf; \
  44. echo "localnet 127.0.0.0/255.0.0.0" >> $conf; \
  45. echo "localnet ::1/128" >> $conf; \
  46. echo "[ProxyList]" >> $conf; \
  47. echo "$protocol $host $port" >> $conf; \
  48. cat /etc/proxychains.conf; \
  49. proxychains -f $conf node server.js; \
  50. else \
  51. node server.js; \
  52. fi