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"
|
SSH_HOST="$1"
|
||||||
REMOTE_COMPOSE="~/opencode-devbox/docker-compose.yml"
|
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 ──────────────────────────────────
|
# ── Bind mount patterns to detect ──────────────────────────────────
|
||||||
# Maps: grep pattern → local source → remote destination
|
# Maps: grep pattern → local source → remote destination
|
||||||
declare -a MOUNT_PATTERNS=(
|
declare -a MOUNT_PATTERNS=(
|
||||||
@@ -39,9 +53,9 @@ declare -a MOUNT_PATTERNS=(
|
|||||||
"~/.agents/skills:/home/developer/.agents/skills|$HOME/.agents/skills|~/.agents/skills"
|
"~/.agents/skills:/home/developer/.agents/skills|$HOME/.agents/skills|~/.agents/skills"
|
||||||
)
|
)
|
||||||
|
|
||||||
# ── Verify SSH connectivity ─────────────────────────────────────────
|
# ── Establish persistent SSH connection ─────────────────────────────
|
||||||
info "Checking SSH connectivity to ${SSH_HOST}..."
|
info "Connecting to ${SSH_HOST}..."
|
||||||
if ! ssh -o ConnectTimeout=5 "$SSH_HOST" true 2>/dev/null; then
|
if ! ssh_cmd true 2>/dev/null; then
|
||||||
err "Cannot connect to ${SSH_HOST}"
|
err "Cannot connect to ${SSH_HOST}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -49,7 +63,7 @@ ok "Connected to ${SSH_HOST}"
|
|||||||
|
|
||||||
# ── Fetch remote docker-compose.yml ─────────────────────────────────
|
# ── Fetch remote docker-compose.yml ─────────────────────────────────
|
||||||
info "Reading docker-compose.yml from ${SSH_HOST}..."
|
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 "Could not read ${REMOTE_COMPOSE} on ${SSH_HOST}"
|
||||||
err "Has the VM been set up? Run the post-setup steps first."
|
err "Has the VM been set up? Run the post-setup steps first."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -79,13 +93,18 @@ for entry in "${MOUNT_PATTERNS[@]}"; do
|
|||||||
info "Syncing ${local_path} → ${SSH_HOST}:${remote_path}"
|
info "Syncing ${local_path} → ${SSH_HOST}:${remote_path}"
|
||||||
|
|
||||||
# Ensure remote directory exists
|
# 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)
|
# Sync with rsync (fall back to scp if rsync unavailable)
|
||||||
if command -v rsync &>/dev/null; then
|
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
|
else
|
||||||
scp -r "${local_path}/." "${SSH_HOST}:${remote_path}/"
|
scp -o "ControlPath=${CTRL_SOCKET}" -r "${local_path}/." "${SSH_HOST}:${remote_path}/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ok "Synced ${local_path}"
|
ok "Synced ${local_path}"
|
||||||
|
|||||||
Reference in New Issue
Block a user