ci: compress deploy artifact to speed up ssh publish
This commit is contained in:
@@ -13,7 +13,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 20
|
timeout-minutes: 30
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -31,6 +31,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p tmp
|
mkdir -p tmp
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o tmp/wx_service ./cmd/api
|
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
|
- name: Prepare SSH
|
||||||
env:
|
env:
|
||||||
@@ -56,9 +58,9 @@ jobs:
|
|||||||
USER: ${{ secrets.PROD_USER }}
|
USER: ${{ secrets.PROD_USER }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
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_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
|
- name: Deploy on server
|
||||||
env:
|
env:
|
||||||
@@ -67,12 +69,12 @@ jobs:
|
|||||||
USER: ${{ secrets.PROD_USER }}
|
USER: ${{ secrets.PROD_USER }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
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_OPTS="-o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=10 -o ServerAliveCountMax=3"
|
||||||
ssh ${SSH_OPTS} -p "${PORT:-22}" "${USER:-root}@${HOST}" \
|
ssh ${SSH_OPTS} -p "${PORT:-22}" "${USER:-root}@${HOST}" \
|
||||||
"APP_DIR='/www/wwwroot/wx_service' \
|
"APP_DIR='/www/wwwroot/wx_service' \
|
||||||
DIST_DIR='/www/wwwroot/wx_service/dist' \
|
DIST_DIR='/www/wwwroot/wx_service/dist' \
|
||||||
SOURCE_BIN='${REMOTE_BIN}' \
|
SOURCE_BIN='${REMOTE_BIN_GZ}' \
|
||||||
RELEASE_ID='${GITHUB_SHA}' \
|
RELEASE_ID='${GITHUB_SHA}' \
|
||||||
SERVICE_NAME='wx_service' \
|
SERVICE_NAME='wx_service' \
|
||||||
RUN_USER='www' \
|
RUN_USER='www' \
|
||||||
|
|||||||
@@ -97,6 +97,19 @@ if [ ! -f "$SOURCE_BIN" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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}"
|
log "deploy start, release: ${RELEASE_ID}"
|
||||||
mkdir -p "$DIST_DIR" "$APP_DIR/backups"
|
mkdir -p "$DIST_DIR" "$APP_DIR/backups"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user