This commit is contained in:
1 parent
69ca4b035b
commit
9b1bc2fd09
1 file changed
+22
-76
@@ -5,96 +5,42 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: atom-nexst-production
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: shell
|
runs-on: shell
|
||||||
timeout-minutes: 20
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Run Deploy Scripts Locally
|
- name: Run Deploy Scripts Locally
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
set -Eeuo pipefail
|
set -e
|
||||||
|
echo "--- EPIC WEB CONTROL: Starting Auto-Cleanup & Deploy ---"
|
||||||
|
|
||||||
APP_DIR="/var/www/atom-nexst"
|
# 1. Clean up unused build images safely
|
||||||
SERVICE_NAME="atom-nexst.service"
|
docker image prune -f
|
||||||
REPOSITORY="/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git"
|
|
||||||
LOCK_FILE="/tmp/atom-nexst-deploy.lock"
|
|
||||||
HEALTH_URL="http://127.0.0.1:3000/api/health"
|
|
||||||
|
|
||||||
echo "--- EPIC WEB CONTROL: Starting Deploy ---"
|
# 2. Navigate to your website directory
|
||||||
|
cd /var/www/atom-nexst/
|
||||||
|
|
||||||
exec 9>"$LOCK_FILE"
|
# Point Git directly to the local Gitea folder path
|
||||||
|
git remote set-url origin /docker/gitea/gitea/git/repositories/remco/epicnext-cms.git/
|
||||||
|
|
||||||
if ! flock -n 9; then
|
# 3. Fetch and update code as root to bypass folder permission blocks
|
||||||
echo "ERROR: Another deployment is already running."
|
git fetch origin --prune
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d "$APP_DIR/.git" ]; then
|
|
||||||
echo "ERROR: $APP_DIR is not a Git repository."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd "$APP_DIR"
|
|
||||||
|
|
||||||
git remote set-url origin "$REPOSITORY"
|
|
||||||
git fetch origin main --prune
|
|
||||||
git reset --hard origin/main
|
git reset --hard origin/main
|
||||||
|
|
||||||
test -f package.json
|
# Fix ownership: Ensure www-data owns the files for the web server
|
||||||
test -f pnpm-lock.yaml
|
sudo chown -R www-data:www-data /var/www/atom-nexst/
|
||||||
|
|
||||||
corepack enable
|
# 4. Configure pnpm to automatically approve build scripts for dependencies
|
||||||
corepack prepare [email protected] --activate
|
pnpm config set trusted-dependencies @parcel/watcher,@swc/core,sharp
|
||||||
|
|
||||||
sudo chown -R www-data:www-data "$APP_DIR"
|
# Install dependencies, run migrations, and build the application
|
||||||
|
pnpm install --frozen-lockfile
|
||||||
|
pnpm db:migrate
|
||||||
|
pnpm prisma generate
|
||||||
|
pnpm build
|
||||||
|
|
||||||
sudo -u www-data env HOME=/var/www \
|
# 5. Restart the application service
|
||||||
pnpm install --frozen-lockfile
|
sudo systemctl restart atom-nexst.service
|
||||||
|
|
||||||
sudo -u www-data env HOME=/var/www \
|
echo "--- Deployment successfully completed ---"
|
||||||
pnpm prisma:generate
|
|
||||||
|
|
||||||
sudo -u www-data env HOME=/var/www \
|
|
||||||
pnpm typecheck
|
|
||||||
|
|
||||||
sudo -u www-data env HOME=/var/www \
|
|
||||||
pnpm test
|
|
||||||
|
|
||||||
sudo -u www-data env HOME=/var/www \
|
|
||||||
pnpm build
|
|
||||||
|
|
||||||
sudo -u www-data env HOME=/var/www \
|
|
||||||
pnpm db:migrate
|
|
||||||
|
|
||||||
sudo systemctl restart "$SERVICE_NAME"
|
|
||||||
|
|
||||||
if ! sudo systemctl is-active --quiet "$SERVICE_NAME"; then
|
|
||||||
echo "ERROR: $SERVICE_NAME failed to start."
|
|
||||||
sudo journalctl -u "$SERVICE_NAME" -n 100 --no-pager
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
for attempt in $(seq 1 15); do
|
|
||||||
if curl \
|
|
||||||
--fail \
|
|
||||||
--silent \
|
|
||||||
--show-error \
|
|
||||||
--max-time 5 \
|
|
||||||
"$HEALTH_URL" >/dev/null; then
|
|
||||||
echo "--- Deployment successfully completed ---"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Waiting for application startup ($attempt/15)..."
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "ERROR: Application health check failed."
|
|
||||||
sudo journalctl -u "$SERVICE_NAME" -n 100 --no-pager
|
|
||||||
exit 1
|
|
||||||
Reference in new issue
Block a user