Last active
July 19, 2023 23:14
-
-
Save foxxyz/3044afadeb6bf5c2849bf9753049763f to your computer and use it in GitHub Desktop.
Generic Deploy Script
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
#!/usr/bin/env bash | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | |
DEPLOY_DIR="/opt/org/project" | |
DEPLOY_MODE="production" | |
RSYNC_DIR=$DEPLOY_DIR | |
SCP_DIR=$DEPLOY_DIR | |
cd $SCRIPT_DIR | |
# Exit if any of the commands fail | |
set -e | |
# Process CLI options | |
while getopts t:m:f flag | |
do | |
case "${flag}" in | |
f) FORCE=true;; | |
m) DEPLOY_MODE=${OPTARG};; | |
t) TARGET=${OPTARG};; | |
esac | |
done | |
# Ensure minimum options are specified | |
if [ -z ${TARGET+x} ] | |
then | |
echo "Error: Missing deploy target and mode" | |
echo "Example usage: ./deploy.sh -t 10.110.1.5 -m [production]" | |
exit 1 | |
fi | |
# Some color to distinguish the deploy phases | |
cecho() { | |
COLOR=`tput setaf 6` # cyan | |
BOLD=`tput bold` | |
RESET=`tput sgr0` | |
echo -e "${COLOR}${BOLD}$1${RESET}" | |
} | |
cecho "> Deploying to ${TARGET} in ${DEPLOY_MODE} mode..." | |
# Check what OS we're deploying to | |
echo -n "> Checking machine type..." | |
UNAME="$(ssh $TARGET "uname")" | |
case "${UNAME}" in | |
MINGW*) OS="win";; | |
Darwin*) OS="macos";; | |
*) OS="linux";; | |
esac | |
cecho $OS | |
# Add prefixes for windows | |
if [ $OS == "win" ] | |
then | |
RSYNC_DIR="../.."$DEPLOY_DIR | |
DEPLOY_DIR="/c"$DEPLOY_DIR | |
fi | |
cecho "> Generating directories inside $DEPLOY_DIR..." | |
ssh $TARGET "mkdir -p $DEPLOY_DIR/gui" | |
cecho "> Compiling GUI..." | |
cd ../gui | |
npm run build | |
cecho "> Copying GUI artifacts..." | |
rsync -avhi --delete dist $TARGET:$RSYNC_DIR/gui | |
rsync -avhi --delete deploy $TARGET:$RSYNC_DIR/gui | |
cd .. | |
cecho "> Copying server files..." | |
cd server | |
scp -r files $TARGET:$DEPLOY_DIR/server | |
cd .. | |
cecho "> Installing dependencies..." | |
ssh $TARGET "cd $DEPLOY_DIR/server && npm install --omit=dev" | |
cecho "> Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment