Dockerfile 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Use the official Golang image as the base image
  2. FROM golang:1.20 as builder
  3. ARG TARGETARCH
  4. ARG TARGETOS
  5. # Set up the working directory
  6. WORKDIR /app
  7. # Copy the Go modules and download the dependencies
  8. COPY go.mod go.sum ./
  9. RUN go mod download
  10. # Copy the source code
  11. COPY . .
  12. # Build the X-ui binary
  13. RUN CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o xui-release-${TARGETARCH} -v main.go
  14. # Start a new stage using the base image
  15. FROM ubuntu:20.04
  16. ARG TARGETARCH
  17. # Set up the working directory
  18. WORKDIR /app
  19. # Copy the X-ui binary and required files from the builder stage
  20. COPY --from=builder /app/xui-release-${TARGETARCH} /app/x-ui/xui-release
  21. COPY x-ui.service /app/x-ui/x-ui.service
  22. COPY x-ui.sh /app/x-ui/x-ui.sh
  23. # Set up the runtime environment
  24. RUN apt-get update && apt-get install -y \
  25. wget \
  26. unzip \
  27. && rm -rf /var/lib/apt/lists/*
  28. WORKDIR /app/x-ui/bin
  29. # Download and set up the required files
  30. RUN wget https://github.com/mhsanaei/Xray-core/releases/latest/download/Xray-linux-64.zip \
  31. && unzip Xray-linux-64.zip \
  32. && rm -f Xray-linux-64.zip geoip.dat geosite.dat iran.dat \
  33. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
  34. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
  35. && wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat \
  36. && mv xray xray-linux-${TARGETARCH}
  37. WORKDIR /app
  38. RUN chmod +x /app/x-ui/x-ui.sh
  39. # Set the entrypoint
  40. ENTRYPOINT ["/app/x-ui/x-ui.sh"]