Spaces:
Sleeping
Sleeping
VenkateshRoshan commited on
Commit ·
8591509
1
Parent(s): 9cc1b28
new setup script added
Browse files- automatic_deployer.py +3 -2
- setup_systemProcess.sh +117 -0
automatic_deployer.py
CHANGED
|
@@ -2,7 +2,7 @@ import subprocess
|
|
| 2 |
import os
|
| 3 |
import time
|
| 4 |
|
| 5 |
-
PORT=
|
| 6 |
HOST='paffenroth-23.dyn.wpi.edu'
|
| 7 |
|
| 8 |
def deploy():
|
|
@@ -44,8 +44,9 @@ def monitorStatus(HOST, PORT, checkInterval=5): # for 5 seconds will wait if the
|
|
| 44 |
status=False
|
| 45 |
while True:
|
| 46 |
if checkStatus(HOST, PORT):
|
| 47 |
-
# If the connection is successful, run
|
| 48 |
if not status:
|
|
|
|
| 49 |
deploy()
|
| 50 |
status=True
|
| 51 |
else:
|
|
|
|
| 2 |
import os
|
| 3 |
import time
|
| 4 |
|
| 5 |
+
PORT=22013
|
| 6 |
HOST='paffenroth-23.dyn.wpi.edu'
|
| 7 |
|
| 8 |
def deploy():
|
|
|
|
| 44 |
status=False
|
| 45 |
while True:
|
| 46 |
if checkStatus(HOST, PORT):
|
| 47 |
+
# If the connection is successful, run deploy and exit the loop
|
| 48 |
if not status:
|
| 49 |
+
print('Deploying the app...')
|
| 50 |
deploy()
|
| 51 |
status=True
|
| 52 |
else:
|
setup_systemProcess.sh
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#! /bin/bash
|
| 2 |
+
|
| 3 |
+
# Server details
|
| 4 |
+
PORT=22013
|
| 5 |
+
HOST=paffenroth-23.dyn.wpi.edu
|
| 6 |
+
USER=student-admin
|
| 7 |
+
|
| 8 |
+
ssh_key_path=./
|
| 9 |
+
old_ssh_key_name=./student-admin_key
|
| 10 |
+
|
| 11 |
+
# remove keys if already present
|
| 12 |
+
rm -f $ssh_key_path/my_key*
|
| 13 |
+
|
| 14 |
+
# TODO : Add password to the ssh key and store it in a file and read the file and get the password
|
| 15 |
+
|
| 16 |
+
# Generate SSH key
|
| 17 |
+
ssh-keygen -f my_key -t ed25519 -N ""
|
| 18 |
+
|
| 19 |
+
# Copy the private key into a variable
|
| 20 |
+
# new_ssh_key=$(<my_key)
|
| 21 |
+
|
| 22 |
+
# # Print the private key
|
| 23 |
+
# echo "Private Key:"
|
| 24 |
+
# echo "$new_ssh_key"
|
| 25 |
+
|
| 26 |
+
# Copy the public key into a new_ssh_key variable
|
| 27 |
+
new_ssh_pub_key=$(<my_key.pub)
|
| 28 |
+
|
| 29 |
+
# Print the public key
|
| 30 |
+
echo "Public Key:"
|
| 31 |
+
echo "$new_ssh_pub_key"
|
| 32 |
+
|
| 33 |
+
# Use the old SSH key to connect to the server and append the new public key to authorized_keys
|
| 34 |
+
ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "echo '$new_ssh_pub_key' >> /home/student-admin/.ssh/authorized_keys && chmod 600 /home/student-admin/.ssh/authorized_keys"
|
| 35 |
+
|
| 36 |
+
# TODO : Comment the old ssh key in the authorized_keys file
|
| 37 |
+
#
|
| 38 |
+
|
| 39 |
+
# Verify if the key has been added successfully
|
| 40 |
+
echo "New public key added to authorized_keys on the server."
|
| 41 |
+
|
| 42 |
+
# Make a variable to store the SSH connection command with
|
| 43 |
+
SSH_CONNECTION="ssh -i my_key -p $PORT $USER@$HOST"
|
| 44 |
+
|
| 45 |
+
# run a command to create apt install python3-venv
|
| 46 |
+
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "sudo apt-get update && sudo apt-get install python3-venv"
|
| 47 |
+
$SSH_CONNECTION "sudo apt-get update && suod apt-get upgrade && sudo apt-get install python3-venv && pip install --upgrade pip"
|
| 48 |
+
|
| 49 |
+
VENV=/home/$USER/mlops
|
| 50 |
+
|
| 51 |
+
# creating a virtual environment
|
| 52 |
+
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "python3 -m venv $VENV"
|
| 53 |
+
$SSH_CONNECTION "python3 -m venv $VENV"
|
| 54 |
+
|
| 55 |
+
echo "Virtual environment created. in $VENV"
|
| 56 |
+
|
| 57 |
+
# path of git repo
|
| 58 |
+
GIT_REPO_PATH=https://github.com/VenkateshRoshan/MLOPs-CaseStudy1.git
|
| 59 |
+
|
| 60 |
+
# Clone the git repo
|
| 61 |
+
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "git clone $GIT_REPO_PATH"
|
| 62 |
+
$SSH_CONNECTION "git clone $GIT_REPO_PATH"
|
| 63 |
+
|
| 64 |
+
# Activate the virtual environment
|
| 65 |
+
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "source $VENV/bin/activate && sudo apt install ffmpeg && cd MLOPs-CaseStudy1 && pip install -r requirements.txt"
|
| 66 |
+
$SSH_CONNECTION "source $VENV/bin/activate && sudo apt install ffmpeg && cd MLOPs-CaseStudy1 && pip3 install -r requirements.txt" # python3 app.py" to run the application
|
| 67 |
+
|
| 68 |
+
echo "The environment is ready to run the application."
|
| 69 |
+
|
| 70 |
+
# check the pip list in the environment
|
| 71 |
+
$SSH_CONNECTION "source $VENV/bin/activate && pip list"
|
| 72 |
+
|
| 73 |
+
# Create a systemd service file for the application
|
| 74 |
+
SERVICE_FILE="[Unit]
|
| 75 |
+
Description= <<< MLOps Case Study 1 Deployment >>>
|
| 76 |
+
After=network.target
|
| 77 |
+
|
| 78 |
+
[Service]
|
| 79 |
+
Type=simple
|
| 80 |
+
ExecStart=/bin/bash -c 'source $VENV/bin/activate && cd /home/$USER/MLOPs-CaseStudy1 && python3 app.py'
|
| 81 |
+
Restart=always
|
| 82 |
+
User=$USER
|
| 83 |
+
WorkingDirectory=/home/$USER/MLOPs-CaseStudy1
|
| 84 |
+
|
| 85 |
+
[Install]
|
| 86 |
+
WantedBy=multi-user.target"
|
| 87 |
+
|
| 88 |
+
# Write the service file to the server
|
| 89 |
+
echo "$SERVICE_FILE" | $SSH_CONNECTION "sudo tee /etc/systemd/system/mlopscs2.service > /dev/null"
|
| 90 |
+
|
| 91 |
+
# Reload systemd to recognize the new service
|
| 92 |
+
$SSH_CONNECTION "sudo systemctl daemon-reload"
|
| 93 |
+
|
| 94 |
+
# Enable the service to start on boot
|
| 95 |
+
$SSH_CONNECTION "sudo systemctl enable mlopscs2"
|
| 96 |
+
|
| 97 |
+
# Start the service
|
| 98 |
+
$SSH_CONNECTION "sudo systemctl start mlopscs2"
|
| 99 |
+
|
| 100 |
+
# Check the status of the service
|
| 101 |
+
# $SSH_CONNECTION "sudo systemctl status mlopscs2"
|
| 102 |
+
|
| 103 |
+
# # restart the service
|
| 104 |
+
# $SSH_CONNECTION "sudo systemctl restart mlopscs2"
|
| 105 |
+
|
| 106 |
+
# Run the application
|
| 107 |
+
$SSH_CONNECTION "source $VENV/bin/activate && cd MLOPs-CaseStudy1 && python3 app.py"
|
| 108 |
+
|
| 109 |
+
echo "Systemd service for MLOps application created and started."
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# The URL Path : paffenroth-23.dyn.wpi.edu:8013 (Gradio Port (8000) + Group Number(13) )
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# TODO : Write a docker file , upload it to VM , and run a docker image in the VM and upload it to AWS S3 bucket
|