-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from AliMD/feat/wp
Improve classic deploy script
- Loading branch information
Showing
6 changed files
with
91 additions
and
335 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,69 +1,3 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
trap "echo '❌ Error'" ERR | ||
|
||
thisPath="$(pwd)" | ||
thisBasename="$(basename "$thisPath")" | ||
cd $thisPath; | ||
rsync="rsync -Prlptzhv --delete --exclude=_data --exclude=.env.* --exclude=deploy* --exclude=*.md --exclude=.DS*" | ||
|
||
if command -v code >/dev/null 2>&1 | ||
then | ||
editor="code --wait" | ||
else | ||
editor="nano" | ||
fi | ||
|
||
if [ -z ${DEPLOY_HOST:-} ] | ||
then | ||
echo "❌ Please set deploy host env by 'export DEPLOY_HOST=root@srv1.alwatr.io'" | ||
exit 1 | ||
fi | ||
|
||
if [ -z ${DEPLOY_NAME:-} ] | ||
then | ||
echo "❌ Please set deploy name env by 'DEPLOY_NAME=$thisBasename ./deploy.sh'" | ||
exit 1 | ||
fi | ||
|
||
DEPLOY_NAME=${DEPLOY_NAME:-$thisBasename} | ||
deployPath="/srv/$DEPLOY_NAME/" | ||
envPath=".env.$DEPLOY_NAME" | ||
|
||
echo "DEPLOY_HOST: $DEPLOY_HOST" | ||
echo "DEPLOY_NAME: $DEPLOY_NAME" | ||
echo "DEPLOY_PATH: $deployPath" | ||
|
||
echoStep () { | ||
echo "🔸 $1" | ||
} | ||
|
||
remoteShell () { | ||
server=$1; shift; | ||
echo "🔸 remoteShell => $server" | ||
ssh -o "ConnectTimeout=5" -tt -q $server $@ | ||
} | ||
|
||
if [ ! -f $envPath ] | ||
then | ||
echo "❌ $envPath not found!" | ||
cp .env.example $envPath | ||
$editor $envPath | ||
fi | ||
|
||
echoStep "Sync..." | ||
|
||
remoteShell $DEPLOY_HOST "mkdir -p $deployPath" | ||
|
||
cp -afv $envPath .env | ||
$rsync ./ $DEPLOY_HOST:$deployPath | ||
rm -fv .env | ||
|
||
if [[ "${1:-}" == "--down" ]] | ||
then | ||
echoStep "Down..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && docker compose down --remove-orphans" | ||
else | ||
echoStep "Up..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && chmod +x _up.sh && ./_up.sh" | ||
fi | ||
source ../lib/deploy.sh |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
trap "echo '❌ Error'" ERR | ||
|
||
thisPath="$(pwd)" | ||
thisBasename="$(basename "$thisPath")" | ||
cd $thisPath; | ||
rsync="rsync -Prlptzhv --delete --exclude=_data --exclude=.env.* --exclude=deploy* --exclude=*.md --exclude=.DS*" | ||
|
||
if command -v code >/dev/null 2>&1 | ||
then | ||
editor="code --wait" | ||
else | ||
editor="nano" | ||
fi | ||
|
||
if [ -z ${DEPLOY_HOST:-} ] | ||
then | ||
echo "❌ Please set deploy host env by 'export DEPLOY_HOST=root@srv1.alwatr.io'" | ||
exit 1 | ||
fi | ||
|
||
if [ -z ${DEPLOY_NAME:-} ] | ||
then | ||
echo "❌ Please set deploy name env by 'DEPLOY_NAME=$thisBasename ./deploy.sh'" | ||
exit 1 | ||
fi | ||
|
||
DEPLOY_NAME=${DEPLOY_NAME:-$thisBasename} | ||
deployPath="/srv/$DEPLOY_NAME/" | ||
envPath=".env.$DEPLOY_NAME" | ||
|
||
echo "DEPLOY_HOST: $DEPLOY_HOST" | ||
echo "DEPLOY_NAME: $DEPLOY_NAME" | ||
echo "DEPLOY_PATH: $deployPath" | ||
|
||
echo "Deploy on: $thisPath" | ||
ls -lAhF | ||
|
||
echo "$envPath" | ||
cat $envPath | ||
|
||
echoStep () { | ||
echo "🔸 $1" | ||
} | ||
|
||
remoteShell () { | ||
server=$1; shift; | ||
echo "🔸 remoteShell => $server" | ||
ssh -o "ConnectTimeout=5" -tt -q $server $@ | ||
} | ||
|
||
if [ ! -f $envPath ] | ||
then | ||
echo "❌ $envPath not found!" | ||
cp .env.example $envPath | ||
$editor $envPath | ||
fi | ||
|
||
echoStep "Sync..." | ||
|
||
remoteShell $DEPLOY_HOST "mkdir -p $deployPath" | ||
|
||
cp -afv $envPath .env | ||
$rsync ./ $DEPLOY_HOST:$deployPath | ||
rm -fv .env | ||
|
||
if [ "${1:-}" = "down" ] | ||
then | ||
echoStep "Down..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && docker compose down --remove-orphans" | ||
|
||
elif [ "${1:-}" = "logs" ] | ||
then | ||
echoStep "Logs..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && docker compose logs --tail=300 --follow" || true | ||
|
||
elif [ "${1:-}" = "up" ] | ||
then | ||
echoStep "Up..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && chmod +x _up.sh && ./_up.sh" | ||
|
||
else | ||
echoStep "List..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && docker compose ps --all" | ||
fi |
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,69 +1,3 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
trap "echo '❌ Error'" ERR | ||
|
||
thisPath="$(pwd)" | ||
thisBasename="$(basename "$thisPath")" | ||
cd $thisPath; | ||
rsync="rsync -Prlptzhv --delete --exclude=_data --exclude=.env.* --exclude=deploy* --exclude=*.md --exclude=.DS*" | ||
|
||
if command -v code >/dev/null 2>&1 | ||
then | ||
editor="code --wait" | ||
else | ||
editor="nano" | ||
fi | ||
|
||
if [ -z ${DEPLOY_HOST:-} ] | ||
then | ||
echo "❌ Please set deploy host env by 'export DEPLOY_HOST=root@srv1.alwatr.io'" | ||
exit 1 | ||
fi | ||
|
||
if [ -z ${DEPLOY_NAME:-} ] | ||
then | ||
echo "❌ Please set deploy name env by 'DEPLOY_NAME=$thisBasename ./deploy.sh'" | ||
exit 1 | ||
fi | ||
|
||
DEPLOY_NAME=${DEPLOY_NAME:-$thisBasename} | ||
deployPath="/srv/$DEPLOY_NAME/" | ||
envPath=".env.$DEPLOY_NAME" | ||
|
||
echo "DEPLOY_HOST: $DEPLOY_HOST" | ||
echo "DEPLOY_NAME: $DEPLOY_NAME" | ||
echo "DEPLOY_PATH: $deployPath" | ||
|
||
echoStep () { | ||
echo "🔸 $1" | ||
} | ||
|
||
remoteShell () { | ||
server=$1; shift; | ||
echo "🔸 remoteShell => $server" | ||
ssh -o "ConnectTimeout=5" -tt -q $server $@ | ||
} | ||
|
||
if [ ! -f $envPath ] | ||
then | ||
echo "❌ $envPath not found!" | ||
cp .env.example $envPath | ||
$editor $envPath | ||
fi | ||
|
||
echoStep "Sync..." | ||
|
||
remoteShell $DEPLOY_HOST "mkdir -p $deployPath" | ||
|
||
cp -afv $envPath .env | ||
$rsync ./ $DEPLOY_HOST:$deployPath | ||
rm -fv .env | ||
|
||
if [[ "${1:-}" == "--down" ]] | ||
then | ||
echoStep "Down..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && docker compose down --remove-orphans" | ||
else | ||
echoStep "Up..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && chmod +x _up.sh && ./_up.sh" | ||
fi | ||
source ../lib/deploy.sh |
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,69 +1,3 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
trap "echo '❌ Error'" ERR | ||
|
||
thisPath="$(pwd)" | ||
thisBasename="$(basename "$thisPath")" | ||
cd $thisPath; | ||
rsync="rsync -Prlptzhv --delete --exclude=_data --exclude=.env.* --exclude=deploy* --exclude=*.md --exclude=.DS*" | ||
|
||
if command -v code >/dev/null 2>&1 | ||
then | ||
editor="code --wait" | ||
else | ||
editor="nano" | ||
fi | ||
|
||
if [ -z ${DEPLOY_HOST:-} ] | ||
then | ||
echo "❌ Please set deploy host env by 'export DEPLOY_HOST=root@srv1.alwatr.io'" | ||
exit 1 | ||
fi | ||
|
||
if [ -z ${DEPLOY_NAME:-} ] | ||
then | ||
echo "❌ Please set deploy name env by 'DEPLOY_NAME=$thisBasename ./deploy.sh'" | ||
exit 1 | ||
fi | ||
|
||
DEPLOY_NAME=${DEPLOY_NAME:-$thisBasename} | ||
deployPath="/srv/$DEPLOY_NAME/" | ||
envPath=".env.$DEPLOY_NAME" | ||
|
||
echo "DEPLOY_HOST: $DEPLOY_HOST" | ||
echo "DEPLOY_NAME: $DEPLOY_NAME" | ||
echo "DEPLOY_PATH: $deployPath" | ||
|
||
echoStep () { | ||
echo "🔸 $1" | ||
} | ||
|
||
remoteShell () { | ||
server=$1; shift; | ||
echo "🔸 remoteShell => $server" | ||
ssh -o "ConnectTimeout=5" -tt -q $server $@ | ||
} | ||
|
||
if [ ! -f $envPath ] | ||
then | ||
echo "❌ $envPath not found!" | ||
cp .env.example $envPath | ||
$editor $envPath | ||
fi | ||
|
||
echoStep "Sync..." | ||
|
||
remoteShell $DEPLOY_HOST "mkdir -p $deployPath" | ||
|
||
cp -afv $envPath .env | ||
$rsync ./ $DEPLOY_HOST:$deployPath | ||
rm -fv .env | ||
|
||
if [[ "${1:-}" == "--down" ]] | ||
then | ||
echoStep "Down..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && docker compose down --remove-orphans" | ||
else | ||
echoStep "Up..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && chmod +x _up.sh && ./_up.sh" | ||
fi | ||
source ../lib/deploy.sh |
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,69 +1,3 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
trap "echo '❌ Error'" ERR | ||
|
||
thisPath="$(pwd)" | ||
thisBasename="$(basename "$thisPath")" | ||
cd $thisPath; | ||
rsync="rsync -Prlptzhv --delete --exclude=_data --exclude=.env.* --exclude=deploy* --exclude=*.md --exclude=.DS*" | ||
|
||
if command -v code >/dev/null 2>&1 | ||
then | ||
editor="code --wait" | ||
else | ||
editor="nano" | ||
fi | ||
|
||
if [ -z ${DEPLOY_HOST:-} ] | ||
then | ||
echo "❌ Please set deploy host env by 'export DEPLOY_HOST=root@srv1.alwatr.io'" | ||
exit 1 | ||
fi | ||
|
||
if [ -z ${DEPLOY_NAME:-} ] | ||
then | ||
echo "❌ Please set deploy name env by 'DEPLOY_NAME=$thisBasename ./deploy.sh'" | ||
exit 1 | ||
fi | ||
|
||
DEPLOY_NAME=${DEPLOY_NAME:-$thisBasename} | ||
deployPath="/srv/$DEPLOY_NAME/" | ||
envPath=".env.$DEPLOY_NAME" | ||
|
||
echo "DEPLOY_HOST: $DEPLOY_HOST" | ||
echo "DEPLOY_NAME: $DEPLOY_NAME" | ||
echo "DEPLOY_PATH: $deployPath" | ||
|
||
echoStep () { | ||
echo "🔸 $1" | ||
} | ||
|
||
remoteShell () { | ||
server=$1; shift; | ||
echo "🔸 remoteShell => $server" | ||
ssh -o "ConnectTimeout=5" -tt -q $server $@ | ||
} | ||
|
||
if [ ! -f $envPath ] | ||
then | ||
echo "❌ $envPath not found!" | ||
cp .env.example $envPath | ||
$editor $envPath | ||
fi | ||
|
||
echoStep "Sync..." | ||
|
||
remoteShell $DEPLOY_HOST "mkdir -p $deployPath" | ||
|
||
cp -afv $envPath .env | ||
$rsync ./ $DEPLOY_HOST:$deployPath | ||
rm -fv .env | ||
|
||
if [[ "${1:-}" == "--down" ]] | ||
then | ||
echoStep "Down..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && docker compose down --remove-orphans" | ||
else | ||
echoStep "Up..." | ||
remoteShell $DEPLOY_HOST "cd $deployPath && chmod +x _up.sh && ./_up.sh" | ||
fi | ||
source ../lib/deploy.sh |
Oops, something went wrong.