diff --git a/packages/nginx/debug.sh b/packages/nginx/debug.sh new file mode 100755 index 00000000..f84994ea --- /dev/null +++ b/packages/nginx/debug.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail +trap "echo '❌ Error'" ERR + +ALWATR_LIB=../../../alwatr/cloud/classic/lib +source $ALWATR_LIB/common.sh + +command="${1:-help}" +[ ! -z "${1:-}" ] && shift + +sshPort=404 +deployHost=mci2.alwatr.ir +deployUser=root +deployPath=/tmp/alwatr-store-nginx +deployPort="8585" +containerName=alwatr-store-nginx-debug +imageName=alwatr/store-nginx:debug +remoteHost="$deployUser@$deployHost" +remotePath="$remoteHost:$deployPath" + +function remoteShellInPath() { + remoteShell "cd $deployPath/; $@" +} + +function command_sync() { + echoStep "Sync..." + syncDeployment ./ $remotePath/ +} + +function command_build() { + command_sync + echoStep "Build..." + remoteShellInPath "docker build --pull --tag $imageName ." +} + +function command_down() { + echoStep "Down..." + remoteShellInPath "docker rm --volumes --force $containerName" +} + +function command_up() { + command_down + command_build + echoStep "Up..." + + remoteShellInPath " + docker run \ + --detach --interactive --tty \ + --name $containerName \ + --publish $deployPort:80 \ + --volume $deployPath/temp:/data \ + $imageName + " + command_logs +} + +function command_logs() { + echoStep "Logs..." + remoteShellInPath "docker logs --tail=2000 --follow $containerName" || true +} + +function command_curl() { + local url="http://$deployHost:$deployPort$1"; shift + local auth="authorization: $1"; shift + echoStep "Curl: $url ($auth)" + curl --compressed --insecure --silent --show-error --header "$auth" "$@" $url | jq + echoGap +} + +function command_request() { + local uri="$1"; shift + echoStep "Request: $uri" + command_curl $uri '' "$@" || true + command_curl $uri 'Alwatr anonymous:anonymous' "$@" || true + command_curl $uri 'Alwatr Ual1md:Jafang' "$@" || true + command_curl $uri 'Alwatr Ual1md1:T0k3n1' "$@" || true + command_curl $uri 'Alwatr Ual1md2:T0k3n2' "$@" || true + command_curl $uri 'Alwatr Uadm1n:T0k3nA' "$@" || true +} + +function command_test() { + echoStep "Test..." + command_request /api/s5/debug-info-110 --verbose + + echoStep "Test Home..." + command_request / + command_request /api/s5/ + + echoStep "Test Public..." + command_request /api/s5/p/post-list.col.asj + + echoStep "Test Secret..." + command_request /api/s5/.s/.store.col.asj + + echoStep "Test Authentificated..." + command_request /api/s5/a/posts/intro-to-alwatr-store.doc.asj + + echoStep "Test Managers..." + command_request /api/s5/m/user-list.col.asj + + echoStep "Test PerUser..." + command_request /api/s5/u/Ual/Ual1md1/info.doc.asj + command_request /api/s5/u/Ual/Ual1md1/404.doc.asj + command_request /api/s5/u/Ual/Ual1md2/info.doc.asj + + echoStep "Test PerOwner..." + command_request /api/s5/o/D3v/D3v1ce1/info.doc.asj + command_request /api/s5/o/T0k/T0k3n1/info.doc.asj + + echoStep "Test Other..." + command_request /api/s5/test.json + command_request /api/s5/p/post-list.col.asj.bak +} + +function command_exec() { + echoStep "Execute... $@" + remoteShellInPath "docker exec --interactive --tty $containerName $@" +} + +function command_help() { + echo " + Alwatr Store Nginx Debug and test. + + Usage: ./debug.sh COMMAND [OPTIONS] + + Command: + up Sync, Build, Create containers. + down Down and remove containers (no file removed). + build Sync, Build/rebuild containers. + sync Upload all files with remote host (exclude \"_data\"). + logs View output from all containers. + rm Down and remove containers and delete all files. + exec Execute a command in a running container. + test Execute tests requests. + docker Direct access to docker. + " +} + +if [ "$command" == 'help' ]; then + command_help + exit +fi + +sshAgent +command_${command} $@