1
0

Dockerfile 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. RUN echo "GOOS=$TARGETOS GOARCH=$TARGETARCH" > /app/.env
  10. # Copy the source code
  11. COPY . .
  12. # Build the X-ui binary
  13. RUN CGO_ENABLED=0 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. # Set up the working directory
  17. WORKDIR /app
  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 --from=builder /app/.env /app/x-ui/.env
  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. tzdata \
  28. ca-certificates \
  29. && rm -rf /var/lib/apt/lists/*
  30. WORKDIR /app/x-ui/bin
  31. # Download and set up the required files
  32. RUN wget https://github.com/mhsanaei/Xray-core/releases/latest/download/Xray-linux-64.zip \
  33. && unzip Xray-linux-64.zip \
  34. && rm -f Xray-linux-64.zip geoip.dat geosite.dat iran.dat \
  35. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
  36. && wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
  37. && wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat \
  38. && arch=(dpkg --print-architecture) \
  39. && mv xray xray-linux-$arch
  40. WORKDIR /app
  41. RUN chmod +x /app/x-ui/x-ui.sh
  42. # Set the entrypoint
  43. ENTRYPOINT ["/app/x-ui/xui-release"]