From 521d8ef6a18a1567aa48df475d0db77ee64d1fb3 Mon Sep 17 00:00:00 2001 From: mayampi01 <176286256+mayampi01@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:36:30 +0800 Subject: [PATCH] Docker: Add multi-arch builds and Loyalsoldier flavor (#3589) Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- .github/docker/Dockerfile | 28 +++++++++++++++---------- .github/workflows/docker.yml | 40 ++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/.github/docker/Dockerfile b/.github/docker/Dockerfile index ad1e8c3dc214..211ef6d24d95 100644 --- a/.github/docker/Dockerfile +++ b/.github/docker/Dockerfile @@ -2,21 +2,27 @@ FROM --platform=$BUILDPLATFORM golang:alpine AS build WORKDIR /src COPY . . -ARG TARGETOS TARGETARCH +ARG TARGETOS +ARG TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main +ADD https://github.com/v2fly/geoip/releases/latest/download/geoip.dat /v2fly/geoip.dat +ADD https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat /v2fly/geosite.dat +ADD https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat /loyalsoldier/geoip.dat +ADD https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat /loyalsoldier/geosite.dat -FROM --platform=${TARGETPLATFORM} alpine:latest -WORKDIR /root +# chainguard/static contains only tzdata and ca-certificates, can be built with multiarch static binaries. +FROM --platform=linux/amd64 chainguard/static:latest +WORKDIR /var/log/xray 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 +COPY --from=build --chmod=755 /src/xray /usr/bin/xray +USER root +WORKDIR /root VOLUME /etc/xray -ENV TZ=Asia/Shanghai +ARG TZ=Asia/Shanghai +ENV TZ=$TZ ENTRYPOINT [ "/usr/bin/xray" ] CMD [ "-config", "/etc/xray/config.json" ] + +ARG flavor=v2fly +COPY --from=build /$flavor /usr/share/xray diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 89a0b6938213..c0945db36b02 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -25,24 +25,52 @@ jobs: type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} + - name: Docker metadata Loyalsoldier flavor + id: loyalsoldier + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/xray-core + flavor: | + latest=auto + suffix=-ls,onlatest=true + tags: | + type=sha + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} 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@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and push uses: docker/build-push-action@v6 with: context: . - platforms: linux/amd64,linux/arm64 + platforms: | + linux/amd64 + linux/arm64 + linux/loong64 + linux/riscv64 + provenance: false file: .github/docker/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + - name: Build and push Loyalsoldier flavor + uses: docker/build-push-action@v6 + with: + context: . + platforms: | + linux/amd64 + linux/arm64 + linux/loong64 + linux/riscv64 + provenance: false + file: .github/docker/Dockerfile + build-args: flavor=loyalsoldier + push: true + tags: | + ${{ steps.loyalsoldier.outputs.tags }}