1
0

Dockerfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Use the official Golang image as the base image
  2. ARG TARGETARCH
  3. ARG TARGETOS
  4. FROM golang:1.20 as builder
  5. ARG TARGETARCH
  6. ARG TARGETOS
  7. # Set up the working directory
  8. WORKDIR /app
  9. # Copy the Go modules and download the dependencies
  10. COPY go.mod go.sum ./
  11. RUN go mod download
  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 TARGETARCH
  19. ARG TARGETOS
  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 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. && 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. && mv xray xray-linux-$TARGETARCH
  40. WORKDIR /app
  41. RUN chmod +x /app/x-ui/x-ui.sh
  42. RUN apt install tzdata ca-certificates
  43. # Set the entrypoint
  44. ENTRYPOINT ["/app/x-ui/xui-release"]