Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Script to Deploy to Homolog #613

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 92 additions & 4 deletions deploy-homolog.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,100 @@
#!/bin/bash

if [[ ! $b4a_certs_path ]]; then echo 'Set b4a_certs_path environment variable, please!' && exit; fi

# Back4App variables
host=34.192.186.60
user=ubuntu
pem=AppContainers.pem

branch=$(git symbolic-ref --short HEAD)
git='~/bin/git-parse-dashboard'

ssh -t -i $b4a_certs_path/$pem $user@$host "sudo su back4app -c '. ~/.nvm/nvm.sh && nvm use 14 && cd ~/scm/parse-dashboard && rm -rf node_modules && $git reset --hard && $git remote update && $git checkout $branch && $git merge origin/$branch && npm install && sed -i \"s/http:\/\/localhost:4000\/parseapi/https:\/\/dashboard-homolog.back4app.com\/parseapi/\" node_modules/parse/lib/browser/settings.js && npm run build-homolog'"
# Check if ENV VAR is defined
if [[ ! $b4a_certs_path ]]; then
echo 'Set b4a_certs_path environment variable, please!' && exit
fi

# Define usage function
usage() {
echo
echo
echo "Usage: $0

[--type <parse-dashboard, parse-dashboard2>] (required)
Specifies the type of dashboard to deploy. Valid options are 'parse-dashboard' and 'parse-dashboard2'.

[--remote <branch>] (optional)
Specifies the Git 'remote' repository from which to deploy.
If not provided, the 'origin' remote will be used."

echo
echo
}

# Initialize custom variables
remote=""
type=""
commands=""

# Parse command-line options
ARGS=$(getopt -o r:t: --long remote:,type: -n "$0" -- "$@")
eval set -- "$ARGS"

while true; do
case "$1" in
-r | --remote)
remote="$2"
shift 2
;;
-t | --type)
if [[ -z "$2" ]]; then
echo "Error: Value for --type is empty."
usage
exit 1
fi
type="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Invalid option: $1"
usage
exit 1
;;
esac
done

# Check if origin or type are empty
if [[ -z "$remote" ]]; then
remote="origin"
elif [[ -z "$type" ]]; then
echo "--type must be provided."
usage
exit 1
fi


case "$type" in
"parse-dashboard")
folder="~/scm/parse-dashboard"
;;
"parse-dashboard2")
folder="~/scm/parse-dashboard2"
;;
*)
echo "Error: Invalid value for --type. Expected 'parse-dashboard' or 'parse-dashboard2'."
usage
exit 1
;;
esac

echo "Deploying origin: ${remote}"

commands+="sudo su back4app -c '. ~/.nvm/nvm.sh && nvm use 14 "
commands+="&& cd $folder && rm -rf node_modules && $git reset --hard "
commands+="&& $git remote update && $git remote update && $git checkout $branch && $git merge $remote/$branch "
commands+="&& npm install && sed -i \"s/http:\/\/localhost:4000\/parseapi/https:\/\/dashboard-homolog.back4app.com\/parseapi/\" node_modules/parse/lib/browser/settings.js "
commands+="&& npm run build-homolog'"

ssh -t -i $b4a_certs_path/$pem $user@$host $commands
Loading