Spaces:
Sleeping
Sleeping
JCai
commited on
Commit
•
70356da
1
Parent(s):
5952a1b
auto_first_deploy script and modify auto_deployment
Browse files- auto_first_deploy.sh +51 -0
- automated_deployment.sh +6 -4
auto_first_deploy.sh
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#! /bin/bash
|
2 |
+
|
3 |
+
if [ -f .env ]; then
|
4 |
+
source .env # loads the variables into current shell session
|
5 |
+
else
|
6 |
+
echo ".env file not found"
|
7 |
+
exit 1
|
8 |
+
fi
|
9 |
+
|
10 |
+
|
11 |
+
# Check if connection works with student-admin_key
|
12 |
+
ssh -i ${STUDENT-ADMIN_KEY} -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE} "echo 'SSH connection with student-admin_key successfully'"
|
13 |
+
|
14 |
+
# Create a unique key
|
15 |
+
ssh-keygen -f cs2_key -t ed25519 -N ${KEY_PASSWORD}
|
16 |
+
|
17 |
+
# Insert the key into the authorized_keys file on the server
|
18 |
+
# One > creates
|
19 |
+
cat mykey.pub > authorized_keys
|
20 |
+
|
21 |
+
chmod 600 authorized_keys
|
22 |
+
|
23 |
+
echo "checking that the authorized_keys file is correct"
|
24 |
+
ls -l authorized_keys
|
25 |
+
cat authorized_keys
|
26 |
+
|
27 |
+
# Copy the authorized_keys file to the server
|
28 |
+
scp -i ${STUDENT-ADMIN_KEY} -P ${PORT} -o StrictHostKeyChecking=no authorized_keys student-admin@${MACHINE}:~/.ssh/
|
29 |
+
|
30 |
+
# Add the key to the ssh-agent
|
31 |
+
eval "$(ssh-agent -s)"
|
32 |
+
ssh-add cs2_key
|
33 |
+
|
34 |
+
# Check the key file on the server
|
35 |
+
echo "checking that the authorized_keys file is correct"
|
36 |
+
ssh -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE} "cat ~/.ssh/authorized_keys"
|
37 |
+
|
38 |
+
# make the prefix command
|
39 |
+
COMMAND="ssh -i ${CS2_KEY} -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE}"
|
40 |
+
# COMMAND="ssh -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE}" # not including key is also okay
|
41 |
+
|
42 |
+
# use the COMMAND to run git clone to clone the repo to VM
|
43 |
+
${COMMAND} "git clone https://github.com/jcai0o0/cs553-case-study-1.git"
|
44 |
+
# use the COMMAND to install python3-venv
|
45 |
+
${COMMAND} "sudo apt install -qq -y python3-venv"
|
46 |
+
# use the COMMAND to the repo folder and create virtual environment named cs2_venv
|
47 |
+
${COMMAND} "cd cs553-case-study-1 && python3 -m venv cs2_venv"
|
48 |
+
# use the COMMAND to cd to the repo folder, activate the cs2_venv virtual environemt, and install all required packages
|
49 |
+
${COMMAND} "cd cs553-case-study-1 && source cs2_venv/bin/activate && pip install -r requirements.txt"
|
50 |
+
# make the product up and run in the background, put running log in file log.txt
|
51 |
+
${COMMAND} "nohup cs553-case-study-1/venv/bin/python3 CS553_example/app.py > log.txt 2>&1 &"
|
automated_deployment.sh
CHANGED
@@ -10,13 +10,15 @@ fi
|
|
10 |
|
11 |
# ssh into the vm
|
12 |
# check that the code in installed and start up the product
|
13 |
-
COMMAND="ssh -i ${
|
14 |
|
15 |
# clone the repo
|
16 |
${COMMAND} "git clone https://github.com/jcai0o0/cs553-case-study-1.git"
|
|
|
17 |
${COMMAND} "sudo apt install -qq -y python3-venv"
|
|
|
18 |
${COMMAND} "cd cs553-case-study-1 && python3 -m venv cs2_venv"
|
|
|
19 |
${COMMAND} "cd cs553-case-study-1 && source cs2_venv/bin/activate && pip install -r requirements.txt"
|
20 |
-
|
21 |
-
${COMMAND} "nohup cs553-case-study-1/cs2_venv/bin/python3 cs553-case-study-1/app.py > log.txt 2>&1 &"
|
22 |
-
|
|
|
10 |
|
11 |
# ssh into the vm
|
12 |
# check that the code in installed and start up the product
|
13 |
+
COMMAND="ssh -i ${CS2_KEY_PATH} -p ${PORT} -o StrictHostKeyChecking=no student-admin@${MACHINE}"
|
14 |
|
15 |
# clone the repo
|
16 |
${COMMAND} "git clone https://github.com/jcai0o0/cs553-case-study-1.git"
|
17 |
+
# install python3-venv
|
18 |
${COMMAND} "sudo apt install -qq -y python3-venv"
|
19 |
+
# use the COMMAND to the repo folder and create virtual environment named cs2_venv
|
20 |
${COMMAND} "cd cs553-case-study-1 && python3 -m venv cs2_venv"
|
21 |
+
# use the COMMAND to cd to the repo folder, activate the cs2_venv virtual environment, and install all required packages
|
22 |
${COMMAND} "cd cs553-case-study-1 && source cs2_venv/bin/activate && pip install -r requirements.txt"
|
23 |
+
# make the product up and run in the background, put running log in file log.txt
|
24 |
+
${COMMAND} "nohup cs553-case-study-1/cs2_venv/bin/python3 cs553-case-study-1/app.py > log.txt 2>&1 &"
|
|