Dockerfile 2.5 KB

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