Created
July 17, 2021 06:29
-
-
Save kyawkyawsoezhu/eaa25fdbfb3672c90b8c0ab7e93617cc to your computer and use it in GitHub Desktop.
Bash file for deploying ReactJS app (CRA) to production server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEPLOY_USER=$USER | |
DEPLOY_SERVER=awesome.example.com | |
DEPLOY_PATH=/var/www/awesome-react-app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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