From ca32496a38f2727b2b7edfc92d3ac22feb95b6ad Mon Sep 17 00:00:00 2001 From: kunson Date: Mon, 17 Apr 2023 05:45:16 +0800 Subject: [PATCH] feat : support docker build --- .github/docker/Dockerfile | 21 +++++++++++++++ .github/docker/files/config.json | 19 ++++++++++++++ .github/workflows/docker.yml | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 .github/docker/Dockerfile create mode 100644 .github/docker/files/config.json create mode 100644 .github/workflows/docker.yml diff --git a/.github/docker/Dockerfile b/.github/docker/Dockerfile new file mode 100644 index 00000000..36f356f8 --- /dev/null +++ b/.github/docker/Dockerfile @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1 +FROM --platform=$BUILDPLATFORM golang:alpine AS build +WORKDIR /src +COPY . . +ARG TARGETOS TARGETARCH +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main + +FROM --platform=${TARGETPLATFORM} alpine:latest +WORKDIR /root +COPY .github/docker/files/config.json /etc/xray/config.json +COPY --from=build /src/xray /usr/bin/xray +RUN set -ex \ + && apk add --no-cache tzdata ca-certificates \ + && mkdir -p /var/log/xray /usr/share/xray \ + && chmod +x /usr/bin/xray \ + && wget -O /usr/share/xray/geosite.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \ + && wget -O /usr/share/xray/geoip.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat + +VOLUME /etc/xray +ENV TZ=Asia/Shanghai +CMD [ "/usr/bin/xray", "-config", "/etc/xray/config.json" ] \ No newline at end of file diff --git a/.github/docker/files/config.json b/.github/docker/files/config.json new file mode 100644 index 00000000..9dded728 --- /dev/null +++ b/.github/docker/files/config.json @@ -0,0 +1,19 @@ +{ + "inbounds": [{ + "port": 9000, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "1eb6e917-774b-4a84-aff6-b058577c60a5", + "level": 1, + "alterId": 64 + } + ] + } + }], + "outbounds": [{ + "protocol": "freedom", + "settings": {} + }] +} \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..a9c4d5f8 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,45 @@ +name: Build docker image + +on: + push: + branches: + - '*' + +jobs: + build-image: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - uses: actions/checkout@v3 + - name: Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.actor }}/xray-core + flavor: latest=true + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - # Add support for more platforms with QEMU (optional) + # https://github.com/docker/setup-qemu-action + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + file: .github/docker/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file