forked from back4app/parse-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Script to Deploy to Homolog (back4app#613)
- Loading branch information
1 parent
b27d98b
commit c789e1c
Showing
1 changed file
with
92 additions
and
4 deletions.
There are no files selected for viewing
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
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 |