This commit is contained in:
1 parent
9628c5d248
commit
69ca4b035b
1 file changed
+87
-36
@@ -1,49 +1,100 @@
|
|||||||
name: Local Build and Deploy
|
name: Local Build and Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
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 -e
|
set -Eeuo pipefail
|
||||||
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"
|
||||||
# 2. Navigate to your website directory
|
HEALTH_URL="http://127.0.0.1:3000/api/health"
|
||||||
cd /var/www/atom-nexst/
|
|
||||||
|
echo "--- EPIC WEB CONTROL: Starting Deploy ---"
|
||||||
# Point Git directly to the local Gitea folder path
|
|
||||||
git remote set-url origin /docker/gitea/gitea/git/repositories/remco/epicnext-cms.git/
|
exec 9>"$LOCK_FILE"
|
||||||
|
|
||||||
# 3. Fetch and update code
|
if ! flock -n 9; then
|
||||||
git fetch origin --prune
|
echo "ERROR: Another deployment is already running."
|
||||||
git reset --hard origin/main
|
|
||||||
|
|
||||||
# 4. Configure pnpm and build
|
|
||||||
pnpm config set trusted-dependencies @parcel/watcher,@swc/core,sharp
|
|
||||||
pnpm install --frozen-lockfile
|
|
||||||
pnpm db:migrate
|
|
||||||
pnpm prisma generate
|
|
||||||
pnpm build
|
|
||||||
|
|
||||||
# 5. Fix ownership: Ensure files are web-server accessible after building
|
|
||||||
sudo chown -R www-data:www-data /var/www/atom-nexst/
|
|
||||||
|
|
||||||
# 6. Restart and verify the application service
|
|
||||||
echo "Restarting service..."
|
|
||||||
sudo systemctl restart atom-nexst.service
|
|
||||||
|
|
||||||
# Wait 2 seconds and check if the service is actually running smoothly
|
|
||||||
sleep 2
|
|
||||||
if ! systemctl is-active --quiet atom-nexst.service; then
|
|
||||||
echo "ERROR: atom-nexst.service failed to start!" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "--- Deployment successfully completed ---"
|
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
|
||||||
|
|
||||||
|
test -f package.json
|
||||||
|
test -f pnpm-lock.yaml
|
||||||
|
|
||||||
|
corepack enable
|
||||||
|
corepack prepare [email protected] --activate
|
||||||
|
|
||||||
|
sudo chown -R www-data:www-data "$APP_DIR"
|
||||||
|
|
||||||
|
sudo -u www-data env HOME=/var/www \
|
||||||
|
pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
sudo -u www-data env HOME=/var/www \
|
||||||
|
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