Skip to content

Instantly share code, notes, and snippets.

@kyawkyawsoezhu
Created July 17, 2021 06:29
Show Gist options
  • Save kyawkyawsoezhu/eaa25fdbfb3672c90b8c0ab7e93617cc to your computer and use it in GitHub Desktop.
Save kyawkyawsoezhu/eaa25fdbfb3672c90b8c0ab7e93617cc to your computer and use it in GitHub Desktop.
Bash file for deploying ReactJS app (CRA) to production server
DEPLOY_USER=$USER
DEPLOY_SERVER=awesome.example.com
DEPLOY_PATH=/var/www/awesome-react-app
#! /bin/bash
if [ ! -f .env.deploy ]
then
echo "can't file .env.deploy file"
exit 1;
fi
source .env.deploy
if [ ! -f .env.production ]
then
echo "need .env.production file"
exit 1;
fi
DEST="${DEPLOY_USER}@${DEPLOY_SERVER}:${DEPLOY_PATH}"
echo -e "\n\e[33m Building... \e[m"
NODE_PATH=src/ sh -ac '. ./.env.production; react-scripts build'
echo -e "Build files are ready to deploy to \e[33m ${DEPLOY_SERVER}:${DEPLOY_PATH} \e[m"
read -r -p "continue? [Y/n]" response
if [[ ! $response =~ ^(Y|y| ) ]]; then
exit 1;
fi
echo -e "\n\e[33m Deploying files to server... \e[m"
rsync -avzH build/ $DEST --delete-after --info=progress2
echo -e "\n\e[33m Removing build folder from local... \e[m"
rm -rfv build
echo -e "\n\t\e[32m Deployed complete. \e[m\n"
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment