1
0

Dockerfile 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # ========================================================
  2. # Stage: Frontend (Vite)
  3. # ========================================================
  4. FROM node:22-alpine AS frontend
  5. WORKDIR /src/frontend
  6. COPY frontend/package.json frontend/package-lock.json ./
  7. RUN npm ci
  8. COPY frontend/ ./
  9. COPY web/translation /src/web/translation
  10. RUN npm run build
  11. # ========================================================
  12. # Stage: Builder
  13. # ========================================================
  14. FROM golang:1.26-alpine AS builder
  15. WORKDIR /app
  16. ARG TARGETARCH
  17. RUN apk --no-cache --update add \
  18. build-base \
  19. gcc \
  20. curl \
  21. unzip
  22. COPY . .
  23. COPY --from=frontend /src/web/dist ./web/dist
  24. ENV CGO_ENABLED=1
  25. ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
  26. RUN go build -ldflags "-w -s" -o build/x-ui main.go
  27. RUN ./DockerInit.sh "$TARGETARCH"
  28. # ========================================================
  29. # Stage: Final Image of 3x-ui
  30. # ========================================================
  31. FROM alpine
  32. ENV TZ=Asia/Tehran
  33. WORKDIR /app
  34. RUN apk add --no-cache --update \
  35. ca-certificates \
  36. tzdata \
  37. fail2ban \
  38. bash \
  39. curl \
  40. openssl
  41. COPY --from=builder /app/build/ /app/
  42. COPY --from=builder /app/DockerEntrypoint.sh /app/
  43. COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
  44. COPY --from=builder /app/web/translation /app/web/translation
  45. # Configure fail2ban
  46. RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
  47. && cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local \
  48. && sed -i "s/^\[ssh\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  49. && sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  50. && sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
  51. RUN chmod +x \
  52. /app/DockerEntrypoint.sh \
  53. /app/x-ui \
  54. /usr/bin/x-ui
  55. ENV XUI_ENABLE_FAIL2BAN="true"
  56. EXPOSE 2053
  57. VOLUME [ "/etc/x-ui" ]
  58. CMD [ "./x-ui" ]
  59. ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]