Skip to content

Commit

Permalink
improve deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
mattslaney committed Jul 11, 2024
1 parent 51776e8 commit 4289a7f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TURN_SECRET=COTURN_SECRET_STRING
TURN_SECRET=COTURN_AUTH_SECRET
TURN_TTL=3600
6 changes: 4 additions & 2 deletions coturn/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Install coturn
sudo apt-get update -y
sudo apt-get install coturn
if ! command -v nginx &> /dev/null; then
sudo apt-get update -y
sudo apt-get install coturn
fi

# Configure coturn
sudo mv /etc/turnserver.conf /etc/turnserver.conf.backup
Expand Down
47 changes: 27 additions & 20 deletions nginx/setup.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
# Setup reverse proxy
sudo apt-get update
sudo apt-get install nginx
if ! command -v nginx &> /dev/null; then
# Setup reverse proxy
sudo apt-get update
sudo apt-get install nginx
fi

# Generate a self signed certificate
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"
sudo cp *.pem /etc/ssl
if [ ! -e /etc/ssl/cert.pem -o ! -e /etc/ssl/key.pem ]; then
echo "Generating a certificate"
# Obtain a certificate
## Self Signed
# openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365
# sudo cp *.pem /etc/ssl
## Self Signed - One Command
# sudo openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"
# sudo cp *.pem /etc/ssl
## Real Certificate
if [ -z "$1" ]; then
read -p "Enter the domain for the certificate: " domainname
else
domainname=$1
fi
sudo certbot certonly --standalone -d $domainname
sudo ln -s "/etc/letsencrypt/live/$domainname/fullchain.pem" /etc/ssl/cert.pem
sudo ln -s "/etc/letsencrypt/live/$domainname/privkey.pem" /etc/ssl/key.pem
else
echo "Using existing certificate"
fi

# Set up the reverse proxy to the node app
sudo cp webrtc /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/webrtc /etc/nginx/sites-enabled

# Obtain a certificate
## Self Signed
# openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365
## Self Signed - One Command
# sudo openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"
## Real Certificate
if [ -z "$1" ]; then
read -p "Enter the domain for the certificate: " domainname
else
domainname=$1
fi
sudo certbot certonly --standalone -d $domainname
sudo ln -sf /etc/nginx/sites-available/webrtc /etc/nginx/sites-enabled

# Open HTTP & HTTPS on firewall
sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
Expand Down
13 changes: 10 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ cd coturn
source ./setup.sh
cd ..
cd nginx
source ./nginx/setup.sh
source ./setup.sh
cd ..

# Run app
sudo apt-get install nodejs npm
# Setup app
if [ ! `command -v node` ] && [ ! `command -v npm` ]; then
sudo apt-get install nodejs npm
fi

# Update .envs
COTURN_AUTH_SECRET=$(sudo grep "static-auth-secret" /etc/turnserver.conf | cut -d'=' -f2)
sed -i "s/TURN_SECRET=.*/TURN_SECRET=$COTURN_AUTH_SECRET/g" .env

npm install
node index.js

0 comments on commit 4289a7f

Please sign in to comment.