|
1 | | -# syntax=docker/dockerfile:1 |
2 | | -FROM --platform=$BUILDPLATFORM golang:alpine AS build |
| 1 | +# syntax=docker/dockerfile:latest |
| 2 | +FROM --platform=$BUILDPLATFORM golang:latest AS build |
| 3 | + |
| 4 | +# Build xray-core |
3 | 5 | WORKDIR /src |
4 | 6 | COPY . . |
5 | 7 | ARG TARGETOS |
6 | 8 | ARG TARGETARCH |
7 | 9 | RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main |
8 | | -ADD https://github.com/v2fly/geoip/releases/latest/download/geoip.dat /v2fly/geoip.dat |
9 | | -ADD https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat /v2fly/geosite.dat |
10 | | -ADD https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat /loyalsoldier/geoip.dat |
11 | | -ADD https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat /loyalsoldier/geosite.dat |
12 | | - |
13 | | -# chainguard/static contains only tzdata and ca-certificates, can be built with multiarch static binaries. |
14 | | -FROM --platform=linux/amd64 chainguard/static:latest |
15 | | -WORKDIR /var/log/xray |
16 | | -COPY .github/docker/files/config.json /etc/xray/config.json |
17 | | -COPY --from=build --chmod=755 /src/xray /usr/bin/xray |
18 | | - |
19 | | -USER root |
20 | | -WORKDIR /root |
21 | | -VOLUME /etc/xray |
22 | | -ARG TZ=Asia/Shanghai |
| 10 | + |
| 11 | +# Download geodat into a staging directory |
| 12 | +ADD https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/geoip.dat /tmp/geodat/geoip.dat |
| 13 | +ADD https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/geosite.dat /tmp/geodat/geosite.dat |
| 14 | + |
| 15 | +RUN mkdir -p /tmp/empty |
| 16 | + |
| 17 | +# Create config files with empty JSON content |
| 18 | +RUN mkdir -p /tmp/usr/local/etc/xray |
| 19 | +RUN cat <<EOF >/tmp/usr/local/etc/xray/00_log.json |
| 20 | +{ |
| 21 | + "log": { |
| 22 | + "error": "/var/log/xray/error.log", |
| 23 | + "loglevel": "warning", |
| 24 | + "access": "none", |
| 25 | + "dnsLog": false |
| 26 | + } |
| 27 | +} |
| 28 | +EOF |
| 29 | +RUN echo '{}' >/tmp/usr/local/etc/xray/01_api.json |
| 30 | +RUN echo '{}' >/tmp/usr/local/etc/xray/02_dns.json |
| 31 | +RUN echo '{}' >/tmp/usr/local/etc/xray/03_routing.json |
| 32 | +RUN echo '{}' >/tmp/usr/local/etc/xray/04_policy.json |
| 33 | +RUN echo '{}' >/tmp/usr/local/etc/xray/05_inbounds.json |
| 34 | +RUN echo '{}' >/tmp/usr/local/etc/xray/06_outbounds.json |
| 35 | +RUN echo '{}' >/tmp/usr/local/etc/xray/07_transport.json |
| 36 | +RUN echo '{}' >/tmp/usr/local/etc/xray/08_stats.json |
| 37 | +RUN echo '{}' >/tmp/usr/local/etc/xray/09_reverse.json |
| 38 | + |
| 39 | +# Create log files |
| 40 | +RUN mkdir -p /tmp/var/log/xray && touch \ |
| 41 | + /tmp/var/log/xray/access.log \ |
| 42 | + /tmp/var/log/xray/error.log |
| 43 | + |
| 44 | +# Build finally image |
| 45 | +FROM gcr.io/distroless/static:nonroot |
| 46 | + |
| 47 | +COPY --from=build --chown=0:0 --chmod=755 /src/xray /usr/local/bin/xray |
| 48 | +COPY --from=build --chown=0:0 --chmod=644 /tmp/geodat/*.dat /usr/local/share/xray/ |
| 49 | +COPY --from=build --chown=0:0 --chmod=755 /tmp/empty /usr/local/etc/xray |
| 50 | +COPY --from=build --chown=0:0 --chmod=644 /tmp/usr/local/etc/xray/*.json /usr/local/etc/xray/ |
| 51 | +COPY --from=build --chown=0:0 --chmod=755 /tmp/empty /var/log/xray |
| 52 | +COPY --from=build --chown=65532:65532 --chmod=600 /tmp/var/log/xray/*.log /var/log/xray/ |
| 53 | + |
| 54 | +VOLUME /usr/local/etc/xray |
| 55 | +VOLUME /var/log/xray |
| 56 | + |
| 57 | +ARG TZ=Etc/UTC |
23 | 58 | ENV TZ=$TZ |
24 | | -ENTRYPOINT [ "/usr/bin/xray" ] |
25 | | -CMD [ "-confdir", "/etc/xray/" ] |
26 | 59 |
|
27 | | -ARG flavor=v2fly |
28 | | -COPY --from=build --chmod=644 /$flavor /usr/share/xray |
| 60 | +ENTRYPOINT [ "/usr/local/bin/xray" ] |
| 61 | +CMD [ "-confdir", "/usr/local/etc/xray/" ] |
0 commit comments