Refactor deployment workflow to utilize GitHub Actions for improved efficiency. Updated deploy.yml to include actions for checkout and Node.js setup, streamlined build process for Next.js with prebuilt assets, and revised deployment script to eliminate unnecessary steps. Enhanced documentation for clarity on automated deployment process.
This commit is contained in:
1 parent
bd2cfa5a26
commit
e1b5286946
5 files changed
+90
-39
No files matched your search
+14
-24
@@ -13,30 +13,20 @@ jobs:
|
||||
deploy:
|
||||
runs-on: local-host
|
||||
steps:
|
||||
- name: Checkout and deploy on the VPS
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: npm
|
||||
|
||||
- name: Build Next.js standalone (host; npm cache reused between runs)
|
||||
env:
|
||||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
REPO_ACTOR: ${{ github.actor }}
|
||||
REPO_NAME: ${{ github.repository }}
|
||||
DEPLOY_SHA: ${{ github.sha }}
|
||||
NEXT_PUBLIC_SITE_URL: https://edu.mstaut.ir
|
||||
run: bash scripts/ci-build-prebuilt.sh
|
||||
|
||||
- name: Roll out (runtime image, backup, migrate, smoke, swap)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TARGET=/opt/prod/Aut.ManagementFaculty
|
||||
mkdir -p "$TARGET"
|
||||
if [ ! -d "$TARGET/.git" ]; then
|
||||
git -C "$TARGET" init
|
||||
git -C "$TARGET" remote add origin "http://127.0.0.1:8301/$REPO_NAME.git"
|
||||
fi
|
||||
# Clear stale locks from interrupted shallow fetches (common after crash/timeout).
|
||||
# This checkout is deploy-only; concurrency group already serializes jobs.
|
||||
rm -f \
|
||||
"$TARGET/.git/shallow.lock" \
|
||||
"$TARGET/.git/index.lock" \
|
||||
"$TARGET/.git/HEAD.lock" \
|
||||
"$TARGET/.git/config.lock"
|
||||
# Supply the job token only for fetch; never store it in .git/config.
|
||||
AUTH=$(printf '%s:%s' "$REPO_ACTOR" "$REPO_TOKEN" | base64 -w0)
|
||||
git -C "$TARGET" -c "http.extraHeader=Authorization: Basic $AUTH" fetch --depth=1 origin "$DEPLOY_SHA"
|
||||
unset AUTH REPO_TOKEN
|
||||
git -C "$TARGET" checkout --detach --force FETCH_HEAD
|
||||
bash "$TARGET/scripts/deploy-production.sh"
|
||||
rm -rf prebuilt/static
|
||||
PREBUILT_DIR="$GITHUB_WORKSPACE/prebuilt" bash scripts/deploy-production.sh
|
||||
Reference in new issue
Block a user