-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
143 lines (115 loc) · 3.29 KB
/
setup.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Function to install necessary dependencies to run the web app
setup_environment() {
echo "Installing necessary dependencies..."
# Printing out the python version
python3 -V
# Set up Virtual Environment
python3 -m venv .venv
# Activate the environment
. .venv/bin/activate
# Upgrade pip
pip install --upgrade pip
# Install the requirements
pip install -r requirements.txt
# Add Current working directory to the .env file
echo "APP_SECRET_KEY=$(python3 -c 'import os; print(os.urandom(32).hex())')" >> .env
echo "SQL_DIR=$(pwd)/database" >> .env
echo "SQL_BACKUP_DIR=$(pwd)/db_backups" >> .env
}
# start the local server
start_local_server() {
# Activate the environment
. .venv/bin/activate
# Starts the server
python3 fetch_news.py && python3 app.py
}
# deploy to ubuntu
deploy_to_ubuntu_server() {
# gitlab host
ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
# clone the new repo contents
if [ -d /home/sury/pythonserver ]; then
# Navigating to the repo
cd pythonserver
# pulling the changes
git pull origin main
# Reload the application using Supervisor
sudo supervisorctl reload
else
# pulling the repo
git clone git@github.com:thatmissedsemicolon/Hacker-News-App.git
# Navigating to the latest repo
cd pythonserver
# Run your setup script
bash setup.sh install
# Reload the application using Supervisor
sudo supervisorctl reload
fi
}
# Function to run tests using pylint
run_pylint_tests() {
echo "Running Pylint tests..."
# Activate the virtual environment
. .venv/bin/activate
# Run pylint on all Python files
find . -type d \( -name .venv -o -name __pycache__ -o -name .pytest_cache \) -prune -false -o -type f -name "*.py" -exec pylint {} +
}
# Function to run tests with pytest using coverage
run_coverage_pytest_tests() {
echo "Running test with pytest using coverage..."
# Activate the virtual environment
. .venv/bin/activate
# Run tests with coverage
coverage run -m pytest tests/test_routes.py tests/test_server.py
coverage report -m
}
# Function to install Python on ubuntu
install_python_ubuntu() {
apt update && apt upgrade -y
apt-get install python3 -y
apt install python3.10-venv -y
python3 -V
}
# Function to install Homebrew and Python on macOS
install_brew_and_python_mac() {
which brew || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update && brew upgrade
brew install python3
}
# Function to display usage
usage() {
echo "Usage: $0 [ubuntu|mac|install|deploy|start|pylint|coverage]"
exit 1
}
# Checks if an argument is provided
if [ $# -eq 0 ]; then
usage
fi
# Checks the argument and calls the appropriate function
case $1 in
ubuntu)
install_python_ubuntu
;;
mac)
install_brew_and_python_mac
;;
install)
setup_environment
;;
deploy)
deploy_to_ubuntu_server
;;
start)
start_local_server
;;
pylint)
run_pylint_tests
;;
coverage)
run_coverage_pytest_tests
;;
*)
usage
;;
esac