deploy-reactjs-vps-run-service

0.0.3 • Public • Published

DEPLOY REACTJS APP TO VPS SSH WIDTH GIT PUSH AND RUN PYTHON SERVICE

Step 1: setup.sh

#!/bin/bash 
read -p "Enter work folder (ex: /srv): " SRV
$SRV ] && [ -s $SRV ] && echo "Work folder: "$SRV || exit
read -p "Enter PROJECT: " PROJECT
[ -s $PROJECT ] && exit || echo "PROJECT "$PROJECT
echo "--------------------BEGIN-----------------------"
 
echo "BEGIN SETUP PROJECT "$PROJECT
TMP=$SRV/tmp/ && echo "+ TMP "$TMP
WWW=$SRV/www/ && echo "+ WWW "$WWW
GIT=$SRV/git/ && echo "+ GIT "$GIT
ENV=$SRV/env/ && echo "+ ENV "$ENV
echo "------------------------------------------------"
 
! -d $TMP ] && sudo mkdir -p $TMP && echo $TMP" created" && sudo chgrp -R users $TMP && echo $TMP" chgrp users" && sudo chmod g+w $TMP && echo $TMP" chmod g+w" || echo $TMP" find"
! -d $WWW ] && sudo mkdir -p $WWW && echo $WWW" created" && sudo chgrp -R users $WWW && echo $WWW" chgrp users" && sudo chmod g+w $WWW && echo $WWW" chmod g+w" || echo $WWW" find"
echo "------------------------------------------------"
 
! -d $GIT$PROJECT.git ] && sudo mkdir -p $GIT$PROJECT.git && echo $GIT$PROJECT.git" created" || echo $GIT$PROJECT.git" find"
cd $GIT$PROJECT.git/ && echo "cd $GIT$PROJECT.git/"
echo "------------------------------------------------"
 
sudo git init --bare && echo "git init --bare"
echo "------------------------------------------------"
 
sudo chgrp -R users . && echo "chgrp -R users ."
sudo chmod -R g+rwX . && echo "chmod -R g+rwX ."
sudo find . -type d -exec chmod g+s '{}' + && echo "find . -type d -exec chmod g+s '{}' +"
echo "------------------------------------------------"
 
sudo git config core.sharedRepository group && echo "git config core.sharedRepository group"
echo "------------------------------------------------"
 
cd $GIT$PROJECT.git/hooks/ && echo "cd $GIT$PROJECT.git/hooks/"
echo "------------------------------------------------"
 
sudo rm $GIT$PROJECT.git/hooks/post-receive && echo "rm $GIT$PROJECT.git/hooks/post-receive"
sudo echo '#!/bin/bash
 
# The production directory 
WWW='$WWW$PROJECT'
 
# A temporary directory for deployment 
TMP='$TMP$PROJECT'
 
# The Git repo 
GIT='$GIT$PROJECT.git'
 
# The Env  repo 
ENV='$ENV$PROJECT'
 
# Deploy the content to the temporary directory 
mkdir -p $TMP
git --work-tree=$TMP --git-dir=$GIT checkout -f
 
# Copy the env variable to the temporary directory 
cp -a $ENV/. $TMP
 
# Do stuffs, like npm install 
cd $TMP || exit
 
# Replace the content of the production directory 
# with the temporary directory 
cd / || exit
rm -rf $WWW
mv $TMP $WWW
 
# Do stuff like starting docker 
cd $WWW || exit
# docker-compose up -d --build 
chmod 777 run
systemctl restart '$PROJECT >> $GIT$PROJECT.git/hooks/post-receive && echo $GIT$PROJECT.git/hooks/post-receive" created"
 
sudo touch $GIT$PROJECT.git/hooks/post-receive && echo "touch $GIT$PROJECT.git/hooks/post-receive"
sudo chmod +x $GIT$PROJECT.git/hooks/post-receive && echo "chmod +x $GIT$PROJECT.git/hooks/post-receive"
 
sudo rm /lib/systemd/system/$PROJECT.service && echo "rm /lib/systemd/system/$PROJECT.service"
sudo echo '[Unit]
Description='$PROJECT'
 
[Service]
Type=simple
ExecStart='$WWW$PROJECT/run'
Restart=on-failure
RestartSec=10
 
[Install]
WantedBy=multi-user.target' >> /lib/systemd/system/$PROJECT.service && echo /lib/systemd/system/$PROJECT.service" created"
 
sudo chmod +x /lib/systemd/system/$PROJECT.service && echo "chmod +x /lib/systemd/system/$PROJECT.service"

Server

sudo -i
 
apt install python
 
sh /path/to/setup.sh
 
read -p "Enter PROJECT: " PROJECT && [ -s $PROJECT ] && exit || echo "PROJECT "$PROJECT
 
sudo systemctl start $PROJECT
sudo systemctl enable $PROJECT

Local

# LOCAL DEPLOY 
read -p "Enter PROJECT: " PROJECT && echo "PROJECT "$PROJECT
read -p "Enter ipv4 IPSERVER: " IPSERVER && echo "IPSERVER ipv4 "$IPSERVER
 
cd /path/to/$PROJECT
 
rm run && echo "rm run"
echo '#!/bin/bash
kill $(lsof -t -i:4444)
cd /srv/www/<project-folder>/build
python -m SimpleHTTPServer 4444' >> run && echo run" created"
 
yarn build
 
git init
git remote add deploy ssh://root@$IPSERVER/srv/git/$PROJECT.git/
 
git add . 
git commit -m "<commit message>"
git push deploy master

NGINX CONFIG

sudo apt install nginx

nano /etc/nginx/conf.d/.conf

server {
	listen 80;
	root /root/path;
	server_name <ipv4 or hostname>;
	access_log /var/log/nginx/<project>_client_access.log;
	error_log /var/log/nginx/<project>_client_error.log;

	location /<your-app>/ {
	    proxy_pass http://127.0.0.1:4444/;
	}	
}

sudo service nginx restart

http://ipv4//

Package Sidebar

Install

npm i deploy-reactjs-vps-run-service

Weekly Downloads

1

Version

0.0.3

License

ISC

Unpacked Size

4.83 kB

Total Files

2

Last publish

Collaborators

  • manhavn