1
0

Dockerfile 1.8 KB

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