Skip to content

Commit

Permalink
feat(deploys): refactor deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Aug 15, 2022
1 parent 4998b90 commit 26c41d6
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/lab/wordpress/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORDPRESS_VERSION=6.0
NGINX_MEMOTY_LIMIT=256m
PHP_MEMOTY_LIMIT=2048m
## Remove _data/wp-config.php to appy
WORDPRESS_DB_HOST=mariadb.alwatr.io
WORDPRESS_DB_HOST=mariadb_database_1.alwatr-private-network
WORDPRESS_DB_USER=alwatr
WORDPRESS_DB_PASSWORD=secret-password
WORDPRESS_DB_NAME=database
Expand Down
2 changes: 1 addition & 1 deletion packages/lab/wordpress/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi

if [ -z ${DEPLOY_PATH:-} ]
then
echo '❌ Plsease set deploy path env by `DEPLOY_PATH=wp-test ./deploy.sh`'
echo "❌ Plsease set deploy path env by 'DEPLOY_PATH=$thisBasename ./deploy.sh'"
exit 1
fi

Expand Down
30 changes: 20 additions & 10 deletions packages/service/adminer/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ set -Eeuo pipefail
trap "echo '❌ Error'" ERR

thisPath="$(pwd)"
projectName="$(basename "$thisPath")"
thisBasename="$(basename "$thisPath")"
cd $thisPath;

host=${1:-}; shift;
if [ -z "$host" ]
if [ -z ${DEPLOY_HOST:-} ]
then
echo "Pass the host as the first argument."
echo '❌ Plsease set deploy host env by `export DEPLOY_HOST=root@srv1.alwatr.io`'
exit 1
fi

if [ -z ${DEPLOY_PATH:-} ]
then
echo "❌ Plsease set deploy path env by 'DEPLOY_PATH=$thisBasename ./deploy.sh'"
exit 1
fi

DEPLOY_PATH="/srv/${DEPLOY_PATH:-$thisBasename}/"

echo "DEPLOY_HOST: $DEPLOY_HOST"
echo "DEPLOY_PATH: $DEPLOY_PATH"

echoStep () {
echo "🔸 $1"
}

remoteShell() {
remoteShell () {
server=$1; shift;
echo "🔸 remoteShell => $server"
ssh -o "ConnectTimeout=5" -tt -q $server $@ || echo "❌ remoteShell error for $server"
ssh -o "ConnectTimeout=5" -tt -q $server $@
}

if [ ! -f .env ]
Expand All @@ -32,15 +42,15 @@ fi

echoStep "Sync..."

remoteShell $host "mkdir -p /srv/$projectName"
remoteShell $DEPLOY_HOST "mkdir -p $DEPLOY_PATH"

rsync -Pazh --del ./_*.sh ./.env ./*.yml $host:/srv/$projectName/
rsync -Pazh --del ./_*.sh ./.env ./*.yml $DEPLOY_HOST:$DEPLOY_PATH/

if [[ "${1:-}" == "--down" ]]
then
echoStep "Down..."
remoteShell $host "cd /srv/$projectName && docker-compose down --remove-orphans"
remoteShell $DEPLOY_HOST "cd $DEPLOY_PATH && docker-compose down --remove-orphans"
else
echoStep "Up..."
remoteShell $host "cd /srv/$projectName && chmod +x _up.sh && ./_up.sh"
remoteShell $DEPLOY_HOST "cd $DEPLOY_PATH && chmod +x _up.sh && ./_up.sh"
fi
1 change: 0 additions & 1 deletion packages/service/adminer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ services:

labels:
traefik.enable: true
traefik.backend: adminer
traefik.port: 9000
traefik.frontend.rule: Host:${DOMAIN}
traefik.frontend.entryPoints: http, https
Expand Down
4 changes: 3 additions & 1 deletion packages/service/mariadb/_up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ docker network create alwatr-private-network || echo "network exist"
docker-compose pull
# docker-compose build --pull

echoStep "Starting..."
echoStep "Fix permitions..."

docker-compose stop
mysqlPath=/var/lib/mysql
docker-compose run --rm --name 'fix-db' --user=root database \
bash -c "ls -lahF $mysqlPath; chown -Rv mysql:mysql $mysqlPath; ls -lahF $mysqlPath;"

echoStep "Starting..."

docker-compose up --detach --remove-orphans # --force-recreate

echoStep "Done"
Expand Down
28 changes: 19 additions & 9 deletions packages/service/mariadb/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ set -Eeuo pipefail
trap "echo '❌ Error'" ERR

thisPath="$(pwd)"
projectName="$(basename "$thisPath")"
thisBasename="$(basename "$thisPath")"
cd $thisPath;

host=${1:-}; shift;
if [ -z "$host" ]
if [ -z ${DEPLOY_HOST:-} ]
then
echo "Pass the host as the first argument."
echo '❌ Plsease set deploy host env by `export DEPLOY_HOST=root@srv1.alwatr.io`'
exit 1
fi

if [ -z ${DEPLOY_PATH:-} ]
then
echo "❌ Plsease set deploy path env by 'DEPLOY_PATH=$thisBasename ./deploy.sh'"
exit 1
fi

DEPLOY_PATH="/srv/${DEPLOY_PATH:-$thisBasename}/"

echo "DEPLOY_HOST: $DEPLOY_HOST"
echo "DEPLOY_PATH: $DEPLOY_PATH"

echoStep () {
echo "🔸 $1"
}

remoteShell() {
server=$1; shift;
echo "🔸 remoteShell => $server"
ssh -o "ConnectTimeout=5" -tt -q $server $@ || echo "❌ remoteShell error for $server"
ssh -o "ConnectTimeout=5" -tt -q $server $@
}

if [ ! -f .env ]
Expand All @@ -32,15 +42,15 @@ fi

echoStep "Sync..."

remoteShell $host "mkdir -p /srv/$projectName"
remoteShell $DEPLOY_HOST "mkdir -p $DEPLOY_PATH"

rsync -Pazh --del ./_*.sh ./.env ./*.yml $host:/srv/$projectName/
rsync -Pazh --del ./_*.sh ./.env ./*.yml $DEPLOY_HOST:$DEPLOY_PATH/

if [[ "${1:-}" == "--down" ]]
then
echoStep "Down..."
remoteShell $host "cd /srv/$projectName && docker-compose down --remove-orphans"
remoteShell $DEPLOY_HOST "cd $DEPLOY_PATH && docker-compose down --remove-orphans"
else
echoStep "Up..."
remoteShell $host "cd /srv/$projectName && chmod +x _up.sh && ./_up.sh"
remoteShell $DEPLOY_HOST "cd $DEPLOY_PATH && chmod +x _up.sh && ./_up.sh"
fi
4 changes: 1 addition & 3 deletions packages/service/mariadb/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ services:
hostname: mariadb.alwatr.io

networks:
alwatr-private-network:
aliases:
- mariadb.alwatr.io
- alwatr-private-network

cpu_shares: 4096
mem_limit: ${MEMOTY_LIMIT}
Expand Down
30 changes: 20 additions & 10 deletions packages/service/traefik-proxy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ set -Eeuo pipefail
trap "echo '❌ Error'" ERR

thisPath="$(pwd)"
projectName="$(basename "$thisPath")"
thisBasename="$(basename "$thisPath")"
cd $thisPath;

host=${1:-}; shift;
if [ -z "$host" ]
if [ -z ${DEPLOY_HOST:-} ]
then
echo "Pass the host as the first argument."
echo '❌ Plsease set deploy host env by `export DEPLOY_HOST=root@srv1.alwatr.io`'
exit 1
fi

if [ -z ${DEPLOY_PATH:-} ]
then
echo "❌ Plsease set deploy path env by 'DEPLOY_PATH=$thisBasename ./deploy.sh'"
exit 1
fi

DEPLOY_PATH="/srv/${DEPLOY_PATH:-$thisBasename}/"

echo "DEPLOY_HOST: $DEPLOY_HOST"
echo "DEPLOY_PATH: $DEPLOY_PATH"

echoStep () {
echo "🔸 $1"
}

remoteShell() {
remoteShell () {
server=$1; shift;
echo "🔸 remoteShell => $server"
ssh -o "ConnectTimeout=5" -tt -q $server $@ || echo "❌ remoteShell error for $server"
ssh -o "ConnectTimeout=5" -tt -q $server $@
}

if [ ! -f .env ]
Expand All @@ -32,15 +42,15 @@ fi

echoStep "Sync..."

remoteShell $host "mkdir -p /srv/$projectName"
remoteShell $DEPLOY_HOST "mkdir -p $DEPLOY_PATH"

rsync -Pazh --del ./_*.sh ./.env ./*.yml ./*.toml $host:/srv/$projectName/
rsync -Pazh --del ./_*.sh ./.env ./*.yml ./*.toml $DEPLOY_HOST:$DEPLOY_PATH/

if [[ "${1:-}" == "--down" ]]
then
echoStep "Down..."
remoteShell $host "cd /srv/$projectName && docker-compose down --remove-orphans"
remoteShell $DEPLOY_HOST "cd $DEPLOY_PATH && docker-compose down --remove-orphans"
else
echoStep "Up..."
remoteShell $host "cd /srv/$projectName && chmod +x _up.sh && ./_up.sh"
remoteShell $DEPLOY_HOST "cd $DEPLOY_PATH && chmod +x _up.sh && ./_up.sh"
fi
1 change: 0 additions & 1 deletion packages/service/traefik-proxy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ services:

labels:
traefik.enable: true
traefik.backend: traefik-proxy
traefik.port: 8080
traefik.frontend.rule: Host:${DOMAIN}
traefik.frontend.entryPoints: http, https
Expand Down

0 comments on commit 26c41d6

Please sign in to comment.