Dockerfile 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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=0 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. # 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 --from=builder /app/.env /app/x-ui/.env
  22. COPY x-ui.service /app/x-ui/x-ui.service
  23. COPY x-ui.sh /app/x-ui/x-ui.sh
  24. # Set up the runtime environment
  25. RUN apt-get update && apt-get install -y \
  26. wget \
  27. unzip \
  28. tzdata \
  29. ca-certificates \
  30. && rm -rf /var/lib/apt/lists/*
  31. WORKDIR /app/x-ui/bin
  32. # Download and set up the required files
  33. RUN wget https://github.com/mhsanaei/Xray-core/releases/latest/download/Xray-linux-64.zip \
  34. && unzip Xray-linux-64.zip \
  35. && rm -f Xray-linux-64.zip geoip.dat geosite.dat iran.dat \
  36. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
  37. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
  38. && wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat \
  39. && arch=(dpkg --print-architecture) \
  40. && mv xray xray-linux-$arch
  41. WORKDIR /app
  42. RUN chmod +x /app/x-ui/x-ui.sh
  43. # Set the entrypoint
  44. ENTRYPOINT ["/app/x-ui/xui-release"]