diff --git a/deploy/tencent_tat/hyapp_admin_server_deploy.py b/deploy/tencent_tat/hyapp_admin_server_deploy.py index 392491f..d6e32bb 100644 --- a/deploy/tencent_tat/hyapp_admin_server_deploy.py +++ b/deploy/tencent_tat/hyapp_admin_server_deploy.py @@ -31,8 +31,7 @@ def admin_endpoint(host: str, user: str) -> str: def build_remote_script(args: argparse.Namespace) -> str: endpoint = admin_endpoint(args.admin_host, args.admin_user) dry_run = "1" if args.dry_run else "0" - ssh_opts = [ - "ssh", + ssh_option_args = [ "-o", "BatchMode=yes", "-o", @@ -40,7 +39,8 @@ def build_remote_script(args: argparse.Namespace) -> str: "-o", f"ConnectTimeout={args.ssh_connect_timeout}", ] - rsync_ssh = shell_join(ssh_opts) + ssh_opts = ["ssh", *ssh_option_args] + scp_cmd = shell_join(["timeout", str(args.transfer_timeout_seconds), "scp", *ssh_option_args]) admin_ssh = shell_join([*ssh_opts, endpoint]) return f"""#!/usr/bin/env bash @@ -53,7 +53,6 @@ DRY_RUN={dry_run} ADMIN_ENDPOINT={shlex.quote(endpoint)} ADMIN_BIND_ADDR={shlex.quote(args.admin_bind_addr)} ADMIN_PORT={shlex.quote(str(args.admin_port))} -SSH_CMD={shlex.quote(rsync_ssh)} ADMIN_SSH={shlex.quote(admin_ssh)} export GIT_SSH_COMMAND="ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=15" @@ -116,7 +115,7 @@ binary_size="$(stat -c %s "$local_binary")" echo "binary_sha=$binary_sha" echo "binary_size=$binary_size" -rsync -az --partial -e "$SSH_CMD" "$local_binary" "$ADMIN_ENDPOINT:$remote_binary" +{scp_cmd} "$local_binary" "$ADMIN_ENDPOINT:$remote_binary" $ADMIN_SSH "REMOTE_BINARY='$remote_binary' EXPECTED_SHA='$binary_sha' ADMIN_BIND_ADDR='$ADMIN_BIND_ADDR' ADMIN_PORT='$ADMIN_PORT' COMMIT='$commit' bash -s" <<'REMOTE' set -euo pipefail @@ -202,6 +201,7 @@ def build_parser() -> argparse.ArgumentParser: parser.add_argument("--admin-bind-addr", default=DEFAULT_ADMIN_BIND_ADDR) parser.add_argument("--admin-port", type=int, default=DEFAULT_ADMIN_PORT) parser.add_argument("--ssh-connect-timeout", type=int, default=15) + parser.add_argument("--transfer-timeout-seconds", type=int, default=300) parser.add_argument("--timeout-seconds", type=int, default=1800) parser.add_argument("--dry-run", action="store_true") parser.add_argument("--yes", action="store_true") diff --git a/deploy/tencent_tat/tests/test_hyapp_admin_server_deploy.py b/deploy/tencent_tat/tests/test_hyapp_admin_server_deploy.py index de25a81..2ff8737 100644 --- a/deploy/tencent_tat/tests/test_hyapp_admin_server_deploy.py +++ b/deploy/tencent_tat/tests/test_hyapp_admin_server_deploy.py @@ -22,13 +22,15 @@ class AdminServerDeployScriptTests(unittest.TestCase): repo_url="git@gitea.haiyihy.com:hy/hyapp-server.git", source_dir="/opt/deploy/sources/hyapp-server", ssh_connect_timeout=15, + transfer_timeout_seconds=300, ) script = admin_deploy.build_remote_script(args) self.assertIn("git fetch --prune origin \"$BRANCH\"", script) self.assertIn("git checkout -B \"$BRANCH\" \"origin/$BRANCH\"", script) self.assertIn("docker build -t \"$build_image\" -f server/admin/Dockerfile .", script) - self.assertIn("rsync -az --partial", script) + self.assertIn("timeout 300 scp", script) + self.assertNotIn("rsync -az --partial", script) self.assertIn("systemctl restart hyapp-admin-server", script) self.assertIn("http://$ADMIN_BIND_ADDR:$ADMIN_PORT/healthz", script) self.assertIn("http://$ADMIN_BIND_ADDR:$ADMIN_PORT/readyz", script)