81 lines
2.0 KiB
Bash
81 lines
2.0 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
export NODE_OPTIONS="--max_old_space_size=4096"
|
|
export CI="true"
|
|
export npm_config_progress="false"
|
|
export npm_config_loglevel="warn"
|
|
export FORCE_COLOR="0"
|
|
|
|
LOG_FILE="/var/log/bssapp_deploy.log"
|
|
APP_DIR="/opt/bssapp"
|
|
LOCK_FILE="/tmp/bssapp_deploy.lock"
|
|
|
|
build_api_binary() {
|
|
if ! command -v go >/dev/null 2>&1; then
|
|
echo "go command not found; cannot build backend binary."
|
|
return 1
|
|
fi
|
|
|
|
cd "$APP_DIR/svc"
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o "$APP_DIR/bssapp" ./main.go
|
|
chmod +x "$APP_DIR/bssapp"
|
|
ln -sf "$APP_DIR/bssapp" "$APP_DIR/nerp"
|
|
ln -sf "$APP_DIR/bssapp" "$APP_DIR/start"
|
|
}
|
|
|
|
run_deploy() {
|
|
exec 9>"$LOCK_FILE"
|
|
if ! flock -n 9; then
|
|
echo "[$(date '+%F %T')] Deploy already running. Skipping new request."
|
|
return 0
|
|
fi
|
|
|
|
echo "=============================="
|
|
echo "[DEPLOY START] $(date '+%F %T')"
|
|
echo "=============================="
|
|
|
|
cd "$APP_DIR"
|
|
|
|
echo "== GIT SYNC =="
|
|
git fetch origin
|
|
git reset --hard origin/master
|
|
git clean -fdx -e bssapp -e nerp
|
|
|
|
echo "== BUILD UI =="
|
|
cd "$APP_DIR/ui"
|
|
npm ci --no-audit --no-fund --include=optional
|
|
|
|
# npm scriptlerinde PATH onceligi nedeniyle node_modules/.bin/sass kullanilir.
|
|
# Bu dosya pure JS olursa --embedded hata verir; global Dart Sass binary'sine bagliyoruz.
|
|
SASS_BIN="$(command -v sass || true)"
|
|
if [[ -z "$SASS_BIN" ]]; then
|
|
echo "sass command not found in PATH."
|
|
return 1
|
|
fi
|
|
"$SASS_BIN" --embedded --version >/dev/null 2>&1 || {
|
|
echo "Global sass supports --embedded is not available."
|
|
return 1
|
|
}
|
|
ln -sf "$SASS_BIN" "$APP_DIR/ui/node_modules/.bin/sass"
|
|
|
|
npm run build
|
|
|
|
echo "== BUILD API =="
|
|
build_api_binary
|
|
|
|
echo "== RESTART SERVICE =="
|
|
systemctl restart bssapp
|
|
|
|
echo "[DEPLOY FINISHED] $(date '+%F %T')"
|
|
}
|
|
|
|
if [[ "${1:-}" == "--run" ]]; then
|
|
run_deploy >>"$LOG_FILE" 2>&1
|
|
exit 0
|
|
fi
|
|
|
|
# Fully detach webhook-triggered process to avoid EPIPE from closed request sockets.
|
|
nohup /bin/bash "$0" --run </dev/null >/dev/null 2>&1 &
|
|
exit 0
|