From fe92fbe96e20baab75b36eeaa750b38ec2378f44 Mon Sep 17 00:00:00 2001 From: Kyle Corbitt Date: Mon, 14 Oct 2024 00:08:03 -0700 Subject: [PATCH] better deployment --- prepare_env.sh | 5 +--- setup_remote.sh | 71 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/prepare_env.sh b/prepare_env.sh index 9ee3f48..673c715 100755 --- a/prepare_env.sh +++ b/prepare_env.sh @@ -23,7 +23,4 @@ apt-get install -y tmux nvtop entr # Install python dependencies curl -LsSf https://astral.sh/uv/0.4.6/install.sh | sh -source ~/.bashrc -uv sync - -echo "Python from virtual environment: $(uv run which python)" +cd /workspace/best-hn && /root/.cargo/bin/uv sync \ No newline at end of file diff --git a/setup_remote.sh b/setup_remote.sh index bdf61bc..0780f69 100755 --- a/setup_remote.sh +++ b/setup_remote.sh @@ -3,12 +3,46 @@ set -e set -o pipefail -if [ $# -ne 1 ]; then - echo "Usage: $0 \"ssh_command\"" +# Default remote name +REMOTE_NAME="best-hn" + +# Function to display usage +usage() { + echo "Usage: $0 [--remote-name REMOTE_NAME] \"ssh_command\"" exit 1 +} + +# Parse arguments +if [ "$#" -lt 1 ]; then + usage fi -ssh_command="$1" +while [[ "$#" -gt 0 ]]; do + case "$1" in + --remote-name|-n) + if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then + REMOTE_NAME="$2" + shift 2 + else + echo "Error: --remote-name requires a non-empty value." + usage + fi + ;; + -*) + echo "Unknown option: $1" + usage + ;; + *) + ssh_command="$1" + shift + ;; + esac +done + +if [ -z "$ssh_command" ]; then + echo "Error: Missing ssh_command." + usage +fi # Extract relevant information from the SSH command host=$(echo "$ssh_command" | awk '{print $2}' | cut -d@ -f2) @@ -18,29 +52,35 @@ port=$(echo "$ssh_command" | awk '{print $4}') config_file="$HOME/.ssh/config" temp_file=$(mktemp) -awk ' -/^# START best-hn config$/,/^# END best-hn config$/ {next} -{print} +awk -v remote_name="$REMOTE_NAME" -v host="$host" -v port="$port" ' +BEGIN { in_block = 0 } +/^# START/ && $0 ~ remote_name { in_block = 1; next } +/^# END/ && $0 ~ remote_name { in_block = 0; next } +!in_block { print } END { - print "# START best-hn config" - print "Host best-hn" - print " HostName '"$host"'" - print " Port '"$port"'" + print "# START " remote_name " config" + print "Host " remote_name + print " HostName " host + print " Port " port print " User root" - print "# END best-hn config" + print "# END " remote_name " config" } ' "$config_file" > "$temp_file" mv "$temp_file" "$config_file" +chmod 600 "$config_file" # Copy remote_lowtrust keypair to the remote system and rename to id_rsa scp -P "$port" ~/.ssh/remote_lowtrust "root@$host:~/.ssh/id_rsa" scp -P "$port" ~/.ssh/remote_lowtrust.pub "root@$host:~/.ssh/id_rsa.pub" +# Copy the local .env file to the remote repository +scp .env "${REMOTE_NAME}:/workspace/.env" + local_name="$(git config --get user.name)" local_email="$(git config --get user.email)" -# Clone the repository and run install_deps.sh on the remote system +# Clone the repository and run prepare_env.sh on the remote system ssh -p "$port" "root@$host" << EOF set -e set -o pipefail @@ -54,15 +94,12 @@ ssh -p "$port" "root@$host" << EOF mkdir -p ~/.ssh ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts + # Clone the repository mkdir -p /workspace cd /workspace GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git clone git@github.com:OpenPipe/best-hn.git cd best-hn/ ./prepare_env.sh - EOF -# Copy the local .env file to the remote repository -scp .env "best-hn:/workspace/.env" - -echo "Remote setup completed successfully!" \ No newline at end of file +echo "Remote setup completed successfully!"