Skip to content

Commit

Permalink
better deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
corbt committed Oct 14, 2024
1 parent 0b4c95c commit fe92fbe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
5 changes: 1 addition & 4 deletions prepare_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
71 changes: 54 additions & 17 deletions setup_remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 [email protected]: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!"
echo "Remote setup completed successfully!"

0 comments on commit fe92fbe

Please sign in to comment.