Dockerfile.usa 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # syntax=docker/dockerfile:latest
  2. FROM --platform=$BUILDPLATFORM golang:latest AS build
  3. # Build xray-core
  4. WORKDIR /src
  5. COPY . .
  6. ARG TARGETOS
  7. ARG TARGETARCH
  8. RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main
  9. # Download geodat into a staging directory
  10. ADD https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/geoip.dat /tmp/geodat/geoip.dat
  11. ADD https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/geosite.dat /tmp/geodat/geosite.dat
  12. RUN mkdir -p /tmp/empty
  13. # Create config files with empty JSON content
  14. RUN mkdir -p /tmp/usr/local/etc/xray
  15. RUN cat <<EOF >/tmp/usr/local/etc/xray/00_log.json
  16. {
  17. "log": {
  18. "error": "/var/log/xray/error.log",
  19. "loglevel": "warning",
  20. "access": "none",
  21. "dnsLog": false
  22. }
  23. }
  24. EOF
  25. RUN echo '{}' >/tmp/usr/local/etc/xray/01_api.json
  26. RUN echo '{}' >/tmp/usr/local/etc/xray/02_dns.json
  27. RUN echo '{}' >/tmp/usr/local/etc/xray/03_routing.json
  28. RUN echo '{}' >/tmp/usr/local/etc/xray/04_policy.json
  29. RUN echo '{}' >/tmp/usr/local/etc/xray/05_inbounds.json
  30. RUN echo '{}' >/tmp/usr/local/etc/xray/06_outbounds.json
  31. RUN echo '{}' >/tmp/usr/local/etc/xray/07_transport.json
  32. RUN echo '{}' >/tmp/usr/local/etc/xray/08_stats.json
  33. RUN echo '{}' >/tmp/usr/local/etc/xray/09_reverse.json
  34. # Create log files
  35. RUN mkdir -p /tmp/var/log/xray && touch \
  36. /tmp/var/log/xray/access.log \
  37. /tmp/var/log/xray/error.log
  38. # Build finally image
  39. # Note on Distroless Base Image and Architecture Support:
  40. # - The official 'gcr.io/distroless/static' image provided by Google only supports a limited set of architectures for Linux:
  41. # - linux/amd64
  42. # - linux/arm/v7
  43. # - linux/arm64/v8
  44. # - linux/ppc64le
  45. # - linux/s390x
  46. # - Upon inspection, the blob contents of the Distroless images across these architectures are nearly identical, with only minor differences in metadata (e.g., 'Architecture' field in the manifest).
  47. # - Due to this similarity in content, it is feasible to forcibly specify a single platform (e.g., '--platform=linux/amd64') for unsupported architectures, as the core image content remains compatible with statically compiled binaries like Go applications.
  48. FROM --platform=linux/amd64 gcr.io/distroless/static:nonroot
  49. COPY --from=build --chown=0:0 --chmod=755 /src/xray /usr/local/bin/xray
  50. COPY --from=build --chown=0:0 --chmod=644 /tmp/geodat/*.dat /usr/local/share/xray/
  51. COPY --from=build --chown=0:0 --chmod=755 /tmp/empty /usr/local/etc/xray
  52. COPY --from=build --chown=0:0 --chmod=644 /tmp/usr/local/etc/xray/*.json /usr/local/etc/xray/
  53. COPY --from=build --chown=0:0 --chmod=755 /tmp/empty /var/log/xray
  54. COPY --from=build --chown=65532:65532 --chmod=600 /tmp/var/log/xray/*.log /var/log/xray/
  55. VOLUME /usr/local/etc/xray
  56. VOLUME /var/log/xray
  57. ARG TZ=Etc/UTC
  58. ENV TZ=$TZ
  59. ENTRYPOINT [ "/usr/local/bin/xray" ]
  60. CMD [ "-confdir", "/usr/local/etc/xray/" ]