Skip to content

Instantly share code, notes, and snippets.

@HarshitRuwali
Last active June 4, 2022 17:20
Show Gist options
  • Save HarshitRuwali/69d730fad522a52ff96cf1f8530f9307 to your computer and use it in GitHub Desktop.
Save HarshitRuwali/69d730fad522a52ff96cf1f8530f9307 to your computer and use it in GitHub Desktop.
A script to build a react app locally and deploy it a server.
cd ~/Developer/comp-web-customer-frontend;
echo -e '\e[1;32m [+] I am here : \e[1;m' `pwd`
echo -e '\e[1;32m [+] pulling prod \e[1;m'
git pull;
echo -e '\e[1;32m [+] cleaning up before fresh build \e[1;m'
rm -rf node_modules/;
rm -rf build/;
rm build.zip;
echo -e '\e[1;32m [+] running npm i \e[1;m'
npm i --force;
echo -e '\e[1;32m [+] running npm run build \e[1;m'
npm run build;
echo -e '\e[1;32m [+] zip the build \e[1;m'
zip -r build.zip build/*;
echo -e '\e[1;32m [+] transferring the build.zip \e[1;m'
scp -i ~/Developer/ssh-keys/comp-aws-ssh.pem ~/Developer/comp-web-customer-frontend/build.zip admin@3.109.**.**:/home/admin;
echo -e '\e[1;32m [+] sshing to the server \e[1;m'
ssh -i ~/Developer/ssh-keys/comp-aws-ssh.pem \
admin@3.109.**.** "echo -e '\e[1;32m [+] moving the build.zip and unzipping \e[1;m' ; \
mv build.zip comp-web-customer-frontend/; \
cd /home/admin/comp-web-customer-frontend; \
rm -rf build/; \
unzip build.zip; \
echo -e '\e[1;32m [+] restarting the services and cleaning up \e[1;m';\
rm build.zip; \
sudo systemctl restart serve-react.service; \
sudo systecmtl restart nginx.service;" 2>/dev/null
echo -e '\e[1;32m [+] Donezo \e[1;m'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment