From 1b9481db696e0d915eef5e060d106b1eef6da018 Mon Sep 17 00:00:00 2001 From: WavyCat Date: Thu, 4 Dec 2025 01:24:28 +0500 Subject: [PATCH 1/6] refactor: move install_xray script from Marzban repo to scripts dir --- Makefile | 5 +- scripts/install_xray.sh | 121 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 scripts/install_xray.sh diff --git a/Makefile b/Makefile index cb07af2..a5ed706 100644 --- a/Makefile +++ b/Makefile @@ -93,13 +93,14 @@ endif install_xray: update_os ifeq ($(UNAME_S),Linux) + chmod +x ./scripts/install_xray.sh # Debian/Ubuntu, CentOS, Fedora, Arch → Use sudo if [ "$(DISTRO)" = "debian" ] || [ "$(DISTRO)" = "ubuntu" ] || \ [ "$(DISTRO)" = "centos" ] || [ "$(DISTRO)" = "rhel" ] || [ "$(DISTRO)" = "fedora" ] || \ [ "$(DISTRO)" = "arch" ]; then \ - sudo bash -c "$$(curl -L https://github.com/Gozargah/Marzban-scripts/raw/master/install_latest_xray.sh)"; \ + sudo bash ./scripts/install_xray.sh; \ else \ - bash -c "$$(curl -L https://github.com/Gozargah/Marzban-scripts/raw/master/install_latest_xray.sh)"; \ + bash ./scripts/install_xray.sh; \ fi else diff --git a/scripts/install_xray.sh b/scripts/install_xray.sh new file mode 100644 index 0000000..bb7a4be --- /dev/null +++ b/scripts/install_xray.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash + +# Download Xray latest + +RELEASE_TAG="latest" + +if [[ "$1" ]]; then + RELEASE_TAG="$1" +fi + +check_if_running_as_root() { + # If you want to run as another user, please modify $EUID to be owned by this user + if [[ "$EUID" -ne '0' ]]; then + echo "error: You must run this script as root!" + exit 1 + fi +} + +identify_the_operating_system_and_architecture() { + if [[ "$(uname)" == 'Linux' ]]; then + case "$(uname -m)" in + 'i386' | 'i686') + ARCH='32' + ;; + 'amd64' | 'x86_64') + ARCH='64' + ;; + 'armv5tel') + ARCH='arm32-v5' + ;; + 'armv6l') + ARCH='arm32-v6' + grep Features /proc/cpuinfo | grep -qw 'vfp' || ARCH='arm32-v5' + ;; + 'armv7' | 'armv7l') + ARCH='arm32-v7a' + grep Features /proc/cpuinfo | grep -qw 'vfp' || ARCH='arm32-v5' + ;; + 'armv8' | 'aarch64') + ARCH='arm64-v8a' + ;; + 'mips') + ARCH='mips32' + ;; + 'mipsle') + ARCH='mips32le' + ;; + 'mips64') + ARCH='mips64' + lscpu | grep -q "Little Endian" && ARCH='mips64le' + ;; + 'mips64le') + ARCH='mips64le' + ;; + 'ppc64') + ARCH='ppc64' + ;; + 'ppc64le') + ARCH='ppc64le' + ;; + 'riscv64') + ARCH='riscv64' + ;; + 's390x') + ARCH='s390x' + ;; + *) + echo "error: The architecture is not supported." + exit 1 + ;; + esac + else + echo "error: This operating system is not supported." + exit 1 + fi +} + +download_xray() { + if [[ "$RELEASE_TAG" == "latest" ]]; then + DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-$ARCH.zip" + else + DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/download/$RELEASE_TAG/Xray-linux-$ARCH.zip" + fi + + echo "Downloading Xray archive: $DOWNLOAD_LINK" + if ! curl -RL -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then + echo 'error: Download failed! Please check your network or try again.' + return 1 + fi +} + +extract_xray() { + if ! unzip -q "$ZIP_FILE" -d "$TMP_DIRECTORY"; then + echo 'error: Xray decompression failed.' + "rm" -rf "$TMP_DIRECTORY" + echo "removed: $TMP_DIRECTORY" + exit 1 + fi + echo "Extracted Xray archive to $TMP_DIRECTORY" +} + +place_xray() { + install -m 755 "${TMP_DIRECTORY}/xray" "/usr/local/bin/xray" + install -d "/usr/local/share/xray/" + install -m 644 "${TMP_DIRECTORY}/geoip.dat" "/usr/local/share/xray/geoip.dat" + install -m 644 "${TMP_DIRECTORY}/geosite.dat" "/usr/local/share/xray/geosite.dat" + echo "Xray files installed" +} + +check_if_running_as_root +identify_the_operating_system_and_architecture + +TMP_DIRECTORY="$(mktemp -d)" +ZIP_FILE="${TMP_DIRECTORY}/Xray-linux-$ARCH.zip" + +download_xray +extract_xray +place_xray + +"rm" -rf "$TMP_DIRECTORY" + From 45539d19d18b273cb5532ec12454fe8dbfa46336 Mon Sep 17 00:00:00 2001 From: WavyCat Date: Thu, 4 Dec 2025 01:25:42 +0500 Subject: [PATCH 2/6] feat: new Dockerfile with crosscompile, distroless and opencontainers label --- Dockerfile | 33 +++++++++++++++++---------------- Dockerfile.multi | 16 ---------------- 2 files changed, 17 insertions(+), 32 deletions(-) delete mode 100644 Dockerfile.multi diff --git a/Dockerfile b/Dockerfile index 781d323..d8f276b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,26 @@ -FROM golang:1.25.1 as base +FROM --platform=$BUILDPLATFORM golang:1.25.1-alpine AS builder -WORKDIR /app -COPY go.mod . -COPY go.sum . -RUN go mod download -COPY . . - -FROM base as builder ARG TARGETOS ARG TARGETARCH -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o main -ldflags="-w -s" . - -FROM alpine:latest RUN apk update && apk add --no-cache make -RUN mkdir /app -WORKDIR /app -COPY --from=builder /app/main . -COPY Makefile . +WORKDIR /src +COPY go* . +RUN go mod download + +COPY . . +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make NAME=main build RUN make install_xray -ENTRYPOINT ["./main"] +FROM gcr.io/distroless/static-debian12 + +LABEL org.opencontainers.image.source="https://github.com/PasarGuard/node" + +WORKDIR /app +COPY --from=builder /src /app +COPY --from=builder /usr/local/bin/xray /usr/local/bin/xray +COPY --from=builder /usr/local/share/xray /usr/local/share/xray + +ENTRYPOINT ["./main"] \ No newline at end of file diff --git a/Dockerfile.multi b/Dockerfile.multi deleted file mode 100644 index dec791b..0000000 --- a/Dockerfile.multi +++ /dev/null @@ -1,16 +0,0 @@ -FROM alpine:latest - -RUN apk update && apk add --no-cache make - -RUN mkdir /app -WORKDIR /app - -COPY Makefile . - -ARG TARGETARCH -COPY binaries/pasarguard-node-linux-${TARGETARCH} ./main -RUN chmod +x ./main - -RUN make install_xray - -ENTRYPOINT ["./main"] \ No newline at end of file From 0e51b5a01d970d2ebf16882f718e3eb23046ef95 Mon Sep 17 00:00:00 2001 From: WavyCat Date: Thu, 4 Dec 2025 01:39:17 +0500 Subject: [PATCH 3/6] refactor: update Docker CI --- .github/workflows/docker-build-dev.yml | 25 +------------------------ .github/workflows/docker-build.yml | 26 +------------------------- 2 files changed, 2 insertions(+), 49 deletions(-) diff --git a/.github/workflows/docker-build-dev.yml b/.github/workflows/docker-build-dev.yml index efaf7d8..ff783b3 100644 --- a/.github/workflows/docker-build-dev.yml +++ b/.github/workflows/docker-build-dev.yml @@ -8,7 +8,6 @@ env: REGISTRY: ghcr.io IMAGE: pasarguard/${{ github.event.repository.name }}:${{ github.ref_name }} GHCR_IMAGE: ghcr.io/pasarguard/${{ github.event.repository.name }}:${{ github.ref_name }} - BINARY_NAME: pasarguard-node-linux jobs: build-and-push: @@ -20,25 +19,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v6 - with: - go-version: '1.25.1' - check-latest: true - - - name: Build binaries for all architectures - run: | - mkdir -p binaries - # Build for amd64 - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 make build - mv ${{env.BINARY_NAME}}-amd64 binaries/ - - # Build for arm64 - GOOS=linux GOARCH=arm64 CGO_ENABLED=0 make build - mv ${{env.BINARY_NAME}}-arm64 binaries/ - - ls -la binaries/ - - name: Login to Docker Hub uses: docker/login-action@v2 with: @@ -51,9 +31,6 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -62,7 +39,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . - file: ./Dockerfile.multi + file: ./Dockerfile platforms: linux/amd64,linux/arm64 push: true tags: | diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index d61a60a..40a9d03 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -10,7 +10,6 @@ env: GHCR_IMAGE: ghcr.io/pasarguard/${{ github.event.repository.name }}:${{ github.ref_name }} IMAGE_LATEST: pasarguard/${{ github.event.repository.name }}:latest GHCR_IMAGE_LATEST: ghcr.io/pasarguard/${{ github.event.repository.name }}:latest - BINARY_NAME: pasarguard-node-linux jobs: build-and-push: @@ -22,25 +21,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v6 - with: - go-version: '1.25.1' - check-latest: true - - - name: Build binaries for all architectures - run: | - mkdir -p binaries - # Build for amd64 - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 make build - mv ${{env.BINARY_NAME}}-amd64 binaries/ - - # Build for arm64 - GOOS=linux GOARCH=arm64 CGO_ENABLED=0 make build - mv ${{env.BINARY_NAME}}-arm64 binaries/ - - ls -la binaries/ - - name: Login to Docker Hub uses: docker/login-action@v2 with: @@ -54,9 +34,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -81,10 +58,9 @@ jobs: uses: docker/build-push-action@v5 with: context: . - file: ./Dockerfile.multi + file: ./Dockerfile platforms: linux/amd64,linux/arm64 push: true tags: ${{ env.DOCKER_TAGS }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha - cache-to: type=gha,mode=max From d00caf02a68684792f1f41bc788862b7672a687c Mon Sep 17 00:00:00 2001 From: Catherine Caramel Date: Thu, 4 Dec 2025 07:53:39 +0500 Subject: [PATCH 4/6] Delete scripts directory --- scripts/install_xray.sh | 121 ---------------------------------------- 1 file changed, 121 deletions(-) delete mode 100644 scripts/install_xray.sh diff --git a/scripts/install_xray.sh b/scripts/install_xray.sh deleted file mode 100644 index bb7a4be..0000000 --- a/scripts/install_xray.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env bash - -# Download Xray latest - -RELEASE_TAG="latest" - -if [[ "$1" ]]; then - RELEASE_TAG="$1" -fi - -check_if_running_as_root() { - # If you want to run as another user, please modify $EUID to be owned by this user - if [[ "$EUID" -ne '0' ]]; then - echo "error: You must run this script as root!" - exit 1 - fi -} - -identify_the_operating_system_and_architecture() { - if [[ "$(uname)" == 'Linux' ]]; then - case "$(uname -m)" in - 'i386' | 'i686') - ARCH='32' - ;; - 'amd64' | 'x86_64') - ARCH='64' - ;; - 'armv5tel') - ARCH='arm32-v5' - ;; - 'armv6l') - ARCH='arm32-v6' - grep Features /proc/cpuinfo | grep -qw 'vfp' || ARCH='arm32-v5' - ;; - 'armv7' | 'armv7l') - ARCH='arm32-v7a' - grep Features /proc/cpuinfo | grep -qw 'vfp' || ARCH='arm32-v5' - ;; - 'armv8' | 'aarch64') - ARCH='arm64-v8a' - ;; - 'mips') - ARCH='mips32' - ;; - 'mipsle') - ARCH='mips32le' - ;; - 'mips64') - ARCH='mips64' - lscpu | grep -q "Little Endian" && ARCH='mips64le' - ;; - 'mips64le') - ARCH='mips64le' - ;; - 'ppc64') - ARCH='ppc64' - ;; - 'ppc64le') - ARCH='ppc64le' - ;; - 'riscv64') - ARCH='riscv64' - ;; - 's390x') - ARCH='s390x' - ;; - *) - echo "error: The architecture is not supported." - exit 1 - ;; - esac - else - echo "error: This operating system is not supported." - exit 1 - fi -} - -download_xray() { - if [[ "$RELEASE_TAG" == "latest" ]]; then - DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-$ARCH.zip" - else - DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/download/$RELEASE_TAG/Xray-linux-$ARCH.zip" - fi - - echo "Downloading Xray archive: $DOWNLOAD_LINK" - if ! curl -RL -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then - echo 'error: Download failed! Please check your network or try again.' - return 1 - fi -} - -extract_xray() { - if ! unzip -q "$ZIP_FILE" -d "$TMP_DIRECTORY"; then - echo 'error: Xray decompression failed.' - "rm" -rf "$TMP_DIRECTORY" - echo "removed: $TMP_DIRECTORY" - exit 1 - fi - echo "Extracted Xray archive to $TMP_DIRECTORY" -} - -place_xray() { - install -m 755 "${TMP_DIRECTORY}/xray" "/usr/local/bin/xray" - install -d "/usr/local/share/xray/" - install -m 644 "${TMP_DIRECTORY}/geoip.dat" "/usr/local/share/xray/geoip.dat" - install -m 644 "${TMP_DIRECTORY}/geosite.dat" "/usr/local/share/xray/geosite.dat" - echo "Xray files installed" -} - -check_if_running_as_root -identify_the_operating_system_and_architecture - -TMP_DIRECTORY="$(mktemp -d)" -ZIP_FILE="${TMP_DIRECTORY}/Xray-linux-$ARCH.zip" - -download_xray -extract_xray -place_xray - -"rm" -rf "$TMP_DIRECTORY" - From 71780c7bf1bd2dd92a52c5e3b67c56770967ea09 Mon Sep 17 00:00:00 2001 From: Catherine Caramel Date: Thu, 4 Dec 2025 07:56:00 +0500 Subject: [PATCH 5/6] Update Makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a5ed706..77978f9 100644 --- a/Makefile +++ b/Makefile @@ -98,9 +98,9 @@ ifeq ($(UNAME_S),Linux) if [ "$(DISTRO)" = "debian" ] || [ "$(DISTRO)" = "ubuntu" ] || \ [ "$(DISTRO)" = "centos" ] || [ "$(DISTRO)" = "rhel" ] || [ "$(DISTRO)" = "fedora" ] || \ [ "$(DISTRO)" = "arch" ]; then \ - sudo bash ./scripts/install_xray.sh; \ + sudo bash -c "$$(curl -L https://github.com/PasarGuard/scripts/raw/main/install_core.sh)"; \ else \ - bash ./scripts/install_xray.sh; \ + bash -c "$$(curl -L https://github.com/PasarGuard/scripts/raw/main/install_core.sh)"; \ fi else From 26a8f967344240acc0ce7359eea47f37f97a9190 Mon Sep 17 00:00:00 2001 From: Catherine Caramel Date: Thu, 4 Dec 2025 07:56:50 +0500 Subject: [PATCH 6/6] fix: remove chmod command for install_xray script --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 77978f9..7d12770 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,6 @@ endif install_xray: update_os ifeq ($(UNAME_S),Linux) - chmod +x ./scripts/install_xray.sh # Debian/Ubuntu, CentOS, Fedora, Arch → Use sudo if [ "$(DISTRO)" = "debian" ] || [ "$(DISTRO)" = "ubuntu" ] || \ [ "$(DISTRO)" = "centos" ] || [ "$(DISTRO)" = "rhel" ] || [ "$(DISTRO)" = "fedora" ] || \