GIT PUSH
AND RUN PYTHON SERVICE
DEPLOY REACTJS APP TO VPS SSH WIDTH Step 1: setup.sh
#!/bin/bash read -p "Enter work folder (ex: /srv): " SRV[ $SRV ] && [ -s $SRV ] && echo "Work folder: "$SRV || exitread -p "Enter PROJECT: " PROJECT[ -s $PROJECT ] && exit || echo "PROJECT "$PROJECTecho "--------------------BEGIN-----------------------" echo "BEGIN SETUP PROJECT "$PROJECTTMP=$SRV/tmp/ && echo "+ TMP "$TMPWWW=$SRV/www/ && echo "+ WWW "$WWWGIT=$SRV/git/ && echo "+ GIT "$GITENV=$SRV/env/ && echo "+ ENV "$ENVecho "------------------------------------------------" [ ! -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 $TMPgit --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 / || exitrm -rf $WWWmv $TMP $WWW # Do stuff like starting docker cd $WWW || exit# docker-compose up -d --build chmod 777 runsystemctl 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=simpleExecStart='$WWW$PROJECT/run'Restart=on-failureRestartSec=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 $PROJECTsudo systemctl enable $PROJECT
Local
# LOCAL DEPLOY read -p "Enter PROJECT: " PROJECT && echo "PROJECT "$PROJECTread -p "Enter ipv4 IPSERVER: " IPSERVER && echo "IPSERVER ipv4 "$IPSERVER cd /path/to/$PROJECT rm run && echo "rm run"echo '#!/bin/bashkill $(lsof -t -i:4444)cd /srv/www/<project-folder>/buildpython -m SimpleHTTPServer 4444' >> run && echo run" created" yarn build git initgit 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//