-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_ec2.sh
More file actions
executable file
·57 lines (45 loc) · 2.23 KB
/
setup_ec2.sh
File metadata and controls
executable file
·57 lines (45 loc) · 2.23 KB
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
#!/bin/bash
# Script to set up an EC2 instance for WeatherSync deployment
# Update system packages
sudo yum update -y
# Install Git
sudo yum install git -y
# Install Python and development tools
sudo yum install python3 python3-devel python3-pip -y
sudo alternatives --set python /usr/bin/python3
sudo pip3 install --upgrade pip
# Install Node.js and npm
curl -sL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install nodejs -y
# Install Nginx
sudo amazon-linux-extras install nginx1 -y
sudo systemctl start nginx
sudo systemctl enable nginx
# Create necessary directories for Nginx
sudo mkdir -p /etc/nginx/sites-available
sudo mkdir -p /etc/nginx/sites-enabled
# Configure Nginx to use sites-enabled
if ! grep -q "include /etc/nginx/sites-enabled/\*;" /etc/nginx/nginx.conf; then
sudo sed -i 's/include \/etc\/nginx\/conf.d\/\*.conf;/include \/etc\/nginx\/conf.d\/\*.conf;\n include \/etc\/nginx\/sites-enabled\/\*;/' /etc/nginx/nginx.conf
fi
# Allow ec2-user to run sudo commands without password for specific services
echo "ec2-user ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx, /usr/bin/systemctl restart weathersync, /usr/bin/systemctl daemon-reload, /usr/bin/systemctl enable weathersync, /bin/tee /etc/nginx/sites-available/weathersync, /bin/ln -sf /etc/nginx/sites-available/weathersync /etc/nginx/sites-enabled/, /usr/sbin/nginx -t, /bin/tee /etc/systemd/system/weathersync.service" | sudo tee /etc/sudoers.d/weathersync
# Clone the repository if it doesn't exist
if [ ! -d "$HOME/WeatherSync" ]; then
git clone https://github.com/TheClimateChangers/WeatherSync.git $HOME/WeatherSync
fi
# Set up the Python virtual environment for the backend
cd $HOME/WeatherSync/backend
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
pip install gunicorn
# Install frontend dependencies
cd $HOME/WeatherSync/frontend
npm ci
echo "====================================================="
echo "EC2 setup completed! You can now run the GitHub Actions workflow."
echo "Make sure to configure your GitHub repository with these secrets:"
echo "- EC2_HOST: Your EC2 instance's public IP or domain"
echo "- EC2_SSH_KEY: Your private SSH key for the EC2 instance"
echo "====================================================="