Dockerfile 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Use the official Golang image as the base image
  2. FROM --platform=$BUILDPLATFORM golang:1.20 as builder
  3. # Set up the working directory
  4. WORKDIR /app
  5. # Copy the Go modules and download the dependencies
  6. COPY go.mod go.sum ./
  7. RUN go mod download
  8. # Copy the source code
  9. COPY . .
  10. ARG TARGETPARCH
  11. RUN if $TARGETPARCH == "arm64"; then apt update && apt install gcc-aarch64-linux-gnu -y; fi
  12. # Build the X-ui binary
  13. RUN if $TARGETPARCH == "arm64"; then GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -o xui-release-arm64 -v main.go; fi
  14. RUN if $TARGETPARCH == "amd64"; then GOOS=linux GOARCH=amd64 go build -o xui-release-amd64 -v main.go; fi
  15. # Start a new stage using the base image
  16. FROM ubuntu:20.04
  17. # Set up the working directory
  18. WORKDIR /app
  19. # Copy the X-ui binary and required files from the builder stage
  20. RUN arch=$(uname -m); \
  21. if [ "$arch" = "aarch64" ]; then \
  22. COPY --from=builder /app/xui-release-arm64 /app/x-ui/xui-release; \
  23. else \
  24. COPY --from=builder /app/xui-release-amd64 /app/x-ui/xui-release; \
  25. fi
  26. COPY x-ui.service /app/x-ui/x-ui.service
  27. COPY x-ui.sh /app/x-ui/x-ui.sh
  28. # Set up the runtime environment
  29. RUN apt-get update && apt-get install -y \
  30. wget \
  31. unzip \
  32. tzdata \
  33. ca-certificates \
  34. && rm -rf /var/lib/apt/lists/*
  35. WORKDIR /app/x-ui/bin
  36. # Download and set up the required files
  37. RUN if [ "$arch" = "aarch64" ]; then \
  38. wget https://github.com/mhsanaei/xray-core/releases/latest/download/Xray-linux-arm64-v8a.zip \
  39. && unzip Xray-linux-arm64-v8a.zip \
  40. && rm -f Xray-linux-arm64-v8a.zip geoip.dat geosite.dat iran.dat \
  41. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
  42. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
  43. && wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat \
  44. && mv xray xray-linux-arm64 \
  45. fi
  46. RUN if [ "$arch" = "amd64" ]; then \
  47. wget https://github.com/mhsanaei/Xray-core/releases/latest/download/Xray-linux-64.zip \
  48. && unzip Xray-linux-64.zip \
  49. && rm -f Xray-linux-64.zip geoip.dat geosite.dat iran.dat \
  50. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
  51. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
  52. && wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat \
  53. && mv xray xray-linux-amd64 \
  54. fi
  55. WORKDIR /app
  56. RUN chmod +x /app/x-ui/x-ui.sh
  57. # Set the entrypoint
  58. ENTRYPOINT ["/app/x-ui/xui-release"]