Files
browser-fingerprint/scripts/deploy-vps.sh
T
Test User 5152086668
CI / Docker build (push) Has been cancelled
CI / Frontend test and build (push) Has been cancelled
CI / Rust test (push) Has been cancelled
Release / Build and publish release (push) Has been cancelled
Initial browser fingerprint app with Gitea CI
2026-07-04 03:15:26 +08:00

57 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DEPLOY_HOST="${DEPLOY_HOST:-92.119.167.24}"
DEPLOY_USER="${DEPLOY_USER:-root}"
DEPLOY_PORT="${DEPLOY_PORT:-22}"
DEPLOY_DIR="${DEPLOY_DIR:-/opt/browser-fingerprint}"
DEPLOY_KEY="${DEPLOY_KEY:-}"
APP_PORT="${APP_PORT:-80}"
SSH_TARGET="${DEPLOY_USER}@${DEPLOY_HOST}"
RELEASE_ID="$(date +%Y%m%d%H%M%S)"
REMOTE_RELEASE="${DEPLOY_DIR}/releases/${RELEASE_ID}"
SSH_OPTS=(
-p "${DEPLOY_PORT}"
-o StrictHostKeyChecking=accept-new
)
if [[ -z "${DEPLOY_KEY}" && -f "${HOME}/.ssh/termius_deploy_ed25519" ]]; then
DEPLOY_KEY="${HOME}/.ssh/termius_deploy_ed25519"
fi
if [[ -n "${DEPLOY_KEY}" ]]; then
SSH_OPTS+=(-i "${DEPLOY_KEY}" -o IdentitiesOnly=yes)
fi
echo "Deploying to ${SSH_TARGET}:${DEPLOY_DIR}"
ssh "${SSH_OPTS[@]}" "${SSH_TARGET}" "
set -e
command -v docker >/dev/null
docker compose version >/dev/null
mkdir -p '${REMOTE_RELEASE}' '${DEPLOY_DIR}/data'
"
tar \
--exclude='.git' \
--exclude='backend/target' \
--exclude='backend/fingerprints.db' \
--exclude='backend/*.db' \
--exclude='frontend/node_modules' \
--exclude='frontend/dist' \
--exclude='.DS_Store' \
-C "${ROOT_DIR}" \
-czf - . \
| ssh "${SSH_OPTS[@]}" "${SSH_TARGET}" "tar -xzf - -C '${REMOTE_RELEASE}'"
ssh "${SSH_OPTS[@]}" "${SSH_TARGET}" "
set -e
ln -sfn '${REMOTE_RELEASE}' '${DEPLOY_DIR}/current'
cd '${DEPLOY_DIR}/current'
APP_PORT='${APP_PORT}' APP_DATA='${DEPLOY_DIR}/data' docker compose -p browser-fingerprint up -d --build
docker compose -p browser-fingerprint ps
"
echo "Deployed: http://${DEPLOY_HOST}/"