Dockerfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 TARGETOS TARGETARCH
  11. # Build the X-ui binary
  12. RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o xui-release-$TARGETARCH -v main.go
  13. # Start a new stage using the base image
  14. FROM ubuntu:20.04
  15. # Set up the working directory
  16. WORKDIR /app
  17. ARG TARGETOS TARGETARCH
  18. # Copy the X-ui binary and required files from the builder stage
  19. COPY --from=builder /app/xui-release-$TARGETARCH /app/x-ui/xui-release
  20. COPY x-ui.service /app/x-ui/x-ui.service
  21. COPY x-ui.sh /app/x-ui/x-ui.sh
  22. # Set up the runtime environment
  23. RUN apt-get update && apt-get install -y \
  24. wget \
  25. unzip \
  26. tzdata \
  27. ca-certificates \
  28. && rm -rf /var/lib/apt/lists/*
  29. WORKDIR /app/x-ui/bin
  30. # Download and set up the required files
  31. RUN wget https://github.com/mhsanaei/Xray-core/releases/latest/download/Xray-linux-64.zip \
  32. && unzip Xray-linux-64.zip \
  33. && rm -f Xray-linux-64.zip geoip.dat geosite.dat iran.dat \
  34. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
  35. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
  36. && wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat \
  37. && arch=(dpkg --print-architecture) \
  38. && mv xray xray-linux-$arch
  39. WORKDIR /app
  40. RUN chmod +x /app/x-ui/x-ui.sh
  41. # Set the entrypoint
  42. ENTRYPOINT ["/app/x-ui/xui-release"]