Skip to content

Commit

Permalink
Merge pull request #220 from AliMD/feat/wp
Browse files Browse the repository at this point in the history
Improve classic deploy script
  • Loading branch information
alimd authored Aug 22, 2022
2 parents 1f0192e + cdabd95 commit 7226ee7
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 335 deletions.
68 changes: 1 addition & 67 deletions packages/classic-cloud/adminer/deploy.sh
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
86 changes: 86 additions & 0 deletions packages/classic-cloud/lib/deploy.sh
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
68 changes: 1 addition & 67 deletions packages/classic-cloud/mariadb/deploy.sh
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
68 changes: 1 addition & 67 deletions packages/classic-cloud/php-apache/deploy.sh
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
68 changes: 1 addition & 67 deletions packages/classic-cloud/traefik-proxy/deploy.sh
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
Loading

0 comments on commit 7226ee7

Please sign in to comment.