-
Notifications
You must be signed in to change notification settings - Fork 8
/
deploy.sh
41 lines (34 loc) · 1.05 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Install APT Dependencies
sudo apt-get update
sudo apt-get install python3 python3-pip python3-venv -y
# Create service script
cat << EOF > /opt/todo-list/todo-list.service
[Unit]
Description=Todo List
[Service]
User=jenkins
WorkingDirectory=/opt/todo-list
Environment="DATABASE_URI=$DATABASE_URI"
Environment="SECRET_KEY=$SECRET_KEY"
ExecStart=/bin/bash -c 'cd /opt/todo-list && source ./venv/bin/activate && python3 create.py && python3 app.py'
[Install]
WantedBy=multi-user.target
EOF
# Install the app service script
sudo cp /opt/todo-list/todo-list.service /etc/systemd/system/
# Create todo list working directory and make working directory
install_dir=/opt/todo-list
sudo rm -rf $install_dir
sudo mkdir $install_dir
sudo cp -r . $install_dir
sudo chown -R jenkins:jenkins $install_dir
# Create and source virtual environment
python3 -m venv venv
source venv/bin/activate
# Install pip requirements
pip3 install -r requirements.txt
# Start the systemd service
sudo systemctl daemon-reload
sudo systemctl stop todo-list
sudo systemctl start todo-list