From be5a1bcdd126e8e8de029ba092da0c34a2b24fd6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 10 Mar 2026 00:34:20 +0800 Subject: [PATCH] ci: compress deploy artifact to speed up ssh publish --- .github/workflows/deploy-prod.yml | 12 +++++++----- scripts/ops/deploy_binary.sh | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index f01a25b..07697bc 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -13,7 +13,7 @@ concurrency: jobs: deploy: runs-on: ubuntu-latest - timeout-minutes: 20 + timeout-minutes: 30 steps: - name: Checkout @@ -31,6 +31,8 @@ jobs: run: | mkdir -p tmp CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o tmp/wx_service ./cmd/api + gzip -9 -c tmp/wx_service > tmp/wx_service.gz + ls -lh tmp/wx_service tmp/wx_service.gz - name: Prepare SSH env: @@ -56,9 +58,9 @@ jobs: USER: ${{ secrets.PROD_USER }} run: | set -e - REMOTE_BIN="/tmp/wx_service-${GITHUB_SHA}" + REMOTE_BIN_GZ="/tmp/wx_service-${GITHUB_SHA}.gz" SSH_OPTS="-o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=10 -o ServerAliveCountMax=3" - scp -O ${SSH_OPTS} -P "${PORT:-22}" tmp/wx_service "${USER:-root}@${HOST}:${REMOTE_BIN}" + scp -O ${SSH_OPTS} -P "${PORT:-22}" tmp/wx_service.gz "${USER:-root}@${HOST}:${REMOTE_BIN_GZ}" - name: Deploy on server env: @@ -67,12 +69,12 @@ jobs: USER: ${{ secrets.PROD_USER }} run: | set -e - REMOTE_BIN="/tmp/wx_service-${GITHUB_SHA}" + REMOTE_BIN_GZ="/tmp/wx_service-${GITHUB_SHA}.gz" SSH_OPTS="-o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=10 -o ServerAliveCountMax=3" ssh ${SSH_OPTS} -p "${PORT:-22}" "${USER:-root}@${HOST}" \ "APP_DIR='/www/wwwroot/wx_service' \ DIST_DIR='/www/wwwroot/wx_service/dist' \ - SOURCE_BIN='${REMOTE_BIN}' \ + SOURCE_BIN='${REMOTE_BIN_GZ}' \ RELEASE_ID='${GITHUB_SHA}' \ SERVICE_NAME='wx_service' \ RUN_USER='www' \ diff --git a/scripts/ops/deploy_binary.sh b/scripts/ops/deploy_binary.sh index f5ef830..a5cb195 100755 --- a/scripts/ops/deploy_binary.sh +++ b/scripts/ops/deploy_binary.sh @@ -97,6 +97,19 @@ if [ ! -f "$SOURCE_BIN" ]; then exit 1 fi +if [[ "$SOURCE_BIN" == *.gz ]]; then + if ! command -v gzip >/dev/null 2>&1; then + echo "gzip not found on server" >&2 + exit 1 + fi + decompressed_bin="${SOURCE_BIN%.gz}" + log "decompressing binary: ${SOURCE_BIN} -> ${decompressed_bin}" + gzip -dc "$SOURCE_BIN" > "$decompressed_bin" + chmod 755 "$decompressed_bin" + rm -f "$SOURCE_BIN" + SOURCE_BIN="$decompressed_bin" +fi + log "deploy start, release: ${RELEASE_ID}" mkdir -p "$DIST_DIR" "$APP_DIR/backups"