From f3ee84d984d040e26345e55c49edc0ce1762b9b2 Mon Sep 17 00:00:00 2001 From: hoodad Date: Sat, 12 Jul 2025 10:25:05 +0000 Subject: [PATCH] Simple Dockerfile & .dockerignore --- .dockerignore | 26 ++++++++++++++++++++++++++ Dockerfile | 28 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..bd7d911a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +# Binaries and build artifacts +*.exe +*.out +*.test +*.tmp + +# Go build/cache directories +/bin +/pkg +/vendor +*.log +*.cache +coverage.* + +# VCS and config noise +.git +.gitignore +.dockerignore +*.swp +*.swo +*.DS_Store +.idea/ +.vscode/ + +# Docker artifacts +Dockerfile* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..bdb1ab4d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM golang:1.24-alpine AS builder + +LABEL org.opencontainers.image.source="https://github.com/XTLS/Xray-core" \ + org.opencontainers.image.licenses="MPL-2.0" \ + org.opencontainers.image.title="xray-core" + +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download + +COPY . ./ +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false \ + -ldflags="-s -w -buildid=" -v ./main + +FROM alpine:3.22.0 + +COPY --from=builder /src/xray /usr/local/bin/xray +RUN adduser -D -u 10001 xray &&\ + chmod +x /usr/local/bin/xray &&\ + mkdir -p /etc/xray /var/log/xray &&\ + echo {} > /etc/xray/config.json + +WORKDIR /etc/xray +USER xray + +ENTRYPOINT ["xray", "-c", "/etc/xray/config.json"]