Dockerfile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Use the official Golang image as the base image
  2. FROM --platform=$BUILDPLATFORM golang:1.20 as builder
  3. ARG TARGETOS TARGETARCH
  4. RUN echo "TARGETOS=$TARGETOS TARGETARCH=$TARGETARCH"
  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. RUN echo "GOOS=$TARGETOS GOARCH=$TARGETARCH" > /app/.env
  11. # Copy the source code
  12. COPY . .
  13. # Build the X-ui binary
  14. RUN CGO_ENABLED=۰ GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o xui-release-$TARGETARCH -v main.go
  15. # Start a new stage using the base image
  16. FROM ubuntu:20.04
  17. ARG TARGETOS TARGETARCH
  18. RUN echo "TARGETOS=$TARGETOS TARGETARCH=$TARGETARCH"
  19. # Set up the working directory
  20. WORKDIR /app
  21. # Copy the X-ui binary and required files from the builder stage
  22. COPY --from=builder /app/xui-release-$TARGETARCH /app/x-ui/xui-release
  23. COPY --from=builder /app/.env /app/x-ui/.env
  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 wget https://github.com/mhsanaei/Xray-core/releases/latest/download/Xray-linux-64.zip \
  36. && unzip Xray-linux-64.zip \
  37. && rm -f Xray-linux-64.zip geoip.dat geosite.dat iran.dat \
  38. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
  39. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
  40. && wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat \
  41. && mv xray xray-linux-$TARGETARCH
  42. WORKDIR /app
  43. RUN chmod +x /app/x-ui/x-ui.sh
  44. # Set the entrypoint
  45. ENTRYPOINT ["/app/x-ui/xui-release"]