Dockerfile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Build environment for Anthropic's OSS Scanner (https://github.com/anthropics/oss-scanner).
  2. # The scanner builds this with the repository as the context, then audits the image offline:
  3. # everything the build, the tests and a reproducer need must be fetched here.
  4. FROM node:26-trixie-slim AS node
  5. FROM golang:1.27.2-trixie
  6. ENV DEBIAN_FRONTEND=noninteractive \
  7. CGO_ENABLED=1 \
  8. CGO_CFLAGS="-D_LARGEFILE64_SOURCE" \
  9. GOTOOLCHAIN=local
  10. RUN apt-get update && apt-get install -y --no-install-recommends \
  11. build-essential ca-certificates curl git jq procps sqlite3 unzip \
  12. && rm -rf /var/lib/apt/lists/*
  13. # Node 26 is required: `make gen` imports .ts files directly and needs its type stripping.
  14. COPY --from=node /usr/local/bin/node /usr/local/bin/node
  15. COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
  16. RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
  17. && ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
  18. && node --version && npm --version
  19. # scanner contract: the checkout lives inside the image, at /src
  20. COPY . /src
  21. WORKDIR /src
  22. RUN go mod download && go mod verify
  23. # The Go binary embeds the Vite build from internal/web/dist, so the frontend goes first.
  24. # HUSKY=0 skips the git-hook install, which needs a .git directory the build context may lack.
  25. RUN cd frontend && HUSKY=0 npm ci && npm run build
  26. # Debug info and no inlining, so stack traces and debuggers map straight to the source.
  27. RUN go build -gcflags=all="-N -l" -o /usr/local/bin/x-ui . \
  28. && ln -s /usr/local/bin/x-ui /src/x-ui
  29. # Xray-core, the mtg-multi MTProto sidecar and the geo databases, exactly as the release image ships them.
  30. RUN ./DockerInit.sh "$(dpkg --print-architecture)" \
  31. && ln -s "/src/build/bin/xray-linux-$(dpkg --print-architecture)" /usr/local/bin/xray \
  32. && xray version
  33. # Turns on the xray gRPC end-to-end tests (internal/xray, internal/amneziawgnet) against the real core.
  34. ENV XRAY_E2E_BINARY=/usr/local/bin/xray
  35. # Baseline tests: also warms the build cache. A failure is logged, never fatal.
  36. RUN go test -count=1 -timeout 30m ./... > /src/.oss-scanner-go-test.log 2>&1 \
  37. || echo "WARNING: go test reported failures, see /src/.oss-scanner-go-test.log"
  38. RUN cd frontend && npx vitest run --project unit --project components > /src/.oss-scanner-vitest.log 2>&1 \
  39. || echo "WARNING: vitest reported failures, see /src/.oss-scanner-vitest.log"
  40. # Reproducers and patches must build with the network gone.
  41. ENV GOPROXY=off \
  42. GOSUMDB=off \
  43. GOFLAGS=-mod=readonly \
  44. npm_config_offline=true
  45. CMD ["bash"]