Exclude node_modules and other generated files from sync-to-vm.sh
This commit is contained in:
+26
-7
@@ -30,6 +30,20 @@ fi
|
||||
SSH_HOST="$1"
|
||||
REMOTE_COMPOSE="~/opencode-devbox/docker-compose.yml"
|
||||
|
||||
# ── SSH multiplexing (reuse one connection for all operations) ──────
|
||||
CTRL_SOCKET=$(mktemp -u /tmp/sync-to-vm-XXXXXX)
|
||||
SSH_OPTS="-o ControlMaster=auto -o ControlPath=${CTRL_SOCKET} -o ControlPersist=120 -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3"
|
||||
|
||||
cleanup() {
|
||||
ssh ${SSH_OPTS} -O exit "$SSH_HOST" 2>/dev/null || true
|
||||
rm -f "$CTRL_SOCKET"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
ssh_cmd() {
|
||||
ssh ${SSH_OPTS} "$SSH_HOST" "$@"
|
||||
}
|
||||
|
||||
# ── Bind mount patterns to detect ──────────────────────────────────
|
||||
# Maps: grep pattern → local source → remote destination
|
||||
declare -a MOUNT_PATTERNS=(
|
||||
@@ -39,9 +53,9 @@ declare -a MOUNT_PATTERNS=(
|
||||
"~/.agents/skills:/home/developer/.agents/skills|$HOME/.agents/skills|~/.agents/skills"
|
||||
)
|
||||
|
||||
# ── Verify SSH connectivity ─────────────────────────────────────────
|
||||
info "Checking SSH connectivity to ${SSH_HOST}..."
|
||||
if ! ssh -o ConnectTimeout=5 "$SSH_HOST" true 2>/dev/null; then
|
||||
# ── Establish persistent SSH connection ─────────────────────────────
|
||||
info "Connecting to ${SSH_HOST}..."
|
||||
if ! ssh_cmd true 2>/dev/null; then
|
||||
err "Cannot connect to ${SSH_HOST}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -49,7 +63,7 @@ ok "Connected to ${SSH_HOST}"
|
||||
|
||||
# ── Fetch remote docker-compose.yml ─────────────────────────────────
|
||||
info "Reading docker-compose.yml from ${SSH_HOST}..."
|
||||
REMOTE_COMPOSE_CONTENT=$(ssh "$SSH_HOST" "cat $REMOTE_COMPOSE 2>/dev/null") || {
|
||||
REMOTE_COMPOSE_CONTENT=$(ssh_cmd "cat $REMOTE_COMPOSE 2>/dev/null") || {
|
||||
err "Could not read ${REMOTE_COMPOSE} on ${SSH_HOST}"
|
||||
err "Has the VM been set up? Run the post-setup steps first."
|
||||
exit 1
|
||||
@@ -79,13 +93,18 @@ for entry in "${MOUNT_PATTERNS[@]}"; do
|
||||
info "Syncing ${local_path} → ${SSH_HOST}:${remote_path}"
|
||||
|
||||
# Ensure remote directory exists
|
||||
ssh "$SSH_HOST" "mkdir -p ${remote_path}"
|
||||
ssh_cmd "mkdir -p ${remote_path}"
|
||||
|
||||
# Sync with rsync (fall back to scp if rsync unavailable)
|
||||
if command -v rsync &>/dev/null; then
|
||||
rsync -az --progress "${local_path}/" "${SSH_HOST}:${remote_path}/"
|
||||
rsync -az --progress \
|
||||
--exclude='node_modules' \
|
||||
--exclude='__pycache__' \
|
||||
--exclude='.venv' \
|
||||
--exclude='*.pyc' \
|
||||
-e "ssh ${SSH_OPTS}" "${local_path}/" "${SSH_HOST}:${remote_path}/"
|
||||
else
|
||||
scp -r "${local_path}/." "${SSH_HOST}:${remote_path}/"
|
||||
scp -o "ControlPath=${CTRL_SOCKET}" -r "${local_path}/." "${SSH_HOST}:${remote_path}/"
|
||||
fi
|
||||
|
||||
ok "Synced ${local_path}"
|
||||
|
||||
Reference in New Issue
Block a user