ci: switch prod deploy to server-side git pull and go build

This commit is contained in:
root
2026-03-10 00:43:23 +08:00
parent be5a1bcdd1
commit 4ff97b2665
4 changed files with 116 additions and 43 deletions
+5 -34
View File
@@ -19,21 +19,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
- name: Download modules
run: go mod download
- name: Build linux binary
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:
SSH_KEY: ${{ secrets.PROD_SSH_KEY }}
@@ -51,36 +36,22 @@ jobs:
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "${PORT:-22}" "$HOST" >> ~/.ssh/known_hosts
- name: Upload binary to server
- name: Deploy on server (git pull + go build)
env:
HOST: ${{ secrets.PROD_HOST }}
PORT: ${{ secrets.PROD_PORT }}
USER: ${{ secrets.PROD_USER }}
run: |
set -e
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.gz "${USER:-root}@${HOST}:${REMOTE_BIN_GZ}"
- name: Deploy on server
env:
HOST: ${{ secrets.PROD_HOST }}
PORT: ${{ secrets.PROD_PORT }}
USER: ${{ secrets.PROD_USER }}
run: |
set -e
REMOTE_BIN_GZ="/tmp/wx_service-${GITHUB_SHA}.gz"
SSH_OPTS="-o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=10 -o ServerAliveCountMax=3"
SSH_OPTS="-o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=10 -o ServerAliveCountMax=6"
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_GZ}' \
DEPLOY_REF='${GITHUB_SHA}' \
RELEASE_ID='${GITHUB_SHA}' \
GO_VERSION='1.23.6' \
SERVICE_NAME='wx_service' \
RUN_USER='www' \
RUN_GROUP='www' \
PORT='8080' \
SYNC_CODE='true' \
DEPLOY_REF='${GITHUB_SHA}' \
INSTALL_SERVICE='true' \
bash -s" < scripts/ops/deploy_binary.sh
bash -s" < scripts/ops/deploy_from_source.sh