Dockerfile 2.5 KB

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