代码拉取完成,页面将自动刷新
同步操作将从 SmallSaaS/jenkins_scripts 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env bash
######################
deploy_container=${CONTAINER}
####################
if [ ! $deploy_container ];then
echo env CONTAINER not yet exported !
exit
fi
#########################
ENDPOINT="http://localhost"
SOCK_OPT='--unix-socket /var/run/docker.sock'
## workding_dir within container /webapps
workingdir_nginx(){
endpoint=$1
container=$2
# echo "curl -s $endpoint/containers/$container/json | jq '.HostConfig.Binds[] | match(\"([a-z/]+):[a-z/]*/webapps[a-z/]*\").string'"
# local binds=$(curl -s $endpoint/containers/$container/json | jq '.HostConfig.Binds[] | match("([a-z/]+):[a-z/]*/webapps[a-z/]*").string')
echo curl $SOCK_OPT -s $endpoint/containers/$container/json > /dev/stderr
local binds=$(curl $SOCK_OPT -s $endpoint/containers/$container/json | jq '.HostConfig.Binds[] | match("[a-z/]*/usr/share/nginx/html:rw").string')
for bind in $binds;do
bind=${bind%\"}
bind=${bind#\"}
bind=${bind%:rw}
echo $bind
done
}
getcontainerjsonvalue(){
endpoint=$1
container=$2
jq_filter="$3"
# echo "curl -s $endpoint/containers/$container/json | jq '.HostConfig.Binds[] | match(\"([a-z/]+):[a-z/]*/webapps[a-z/]*\").string'"
# local binds=$(curl -s $endpoint/containers/$container/json | jq '.HostConfig.Binds[] | match("([a-z/]+):[a-z/]*/webapps[a-z/]*").string')
echo "curl $SOCK_OPT -s $endpoint/containers/$container/json | jq $jq_filter" > /dev/stderr
local result=$(curl $SOCK_OPT -s $endpoint/containers/$container/json | jq $jq_filter)
result=${result%\"}
result=${result#\"}
echo $result
}
## working dir from filesystem
getcontainerworkingdir(){
endpoint=$1
container=$2
echo $(getcontainerjsonvalue $endpoint $container '.Config.Labels."com.docker.compose.project.working_dir"')
}
getcontainerstatus(){
endpoint=$1
container=$2
echo $(getcontainerjsonvalue $endpoint $container '.State.Status')
}
stopcontainer(){
endpoint=$1
container=$2
echo curl $SOCK_OPT -s -X POST $endpoint/containers/$container/stop > /dev/stderr
curl $SOCK_OPT -s -X POST $endpoint/containers/$container/stop
}
restartcontainer(){
endpoint=$1
container=$2
echo curl $SOCK_OPT -s -X POST $endpoint/containers/$container/restart > /dev/stderr
curl $SOCK_OPT -s -X POST $endpoint/containers/$container/restart
}
puttartocontainer(){
endpoint=$1
container=$2
working_dir=$3
tarbin=$4
echo curl $SOCK_OPT -X PUT ${endpoint}/containers/${container}/archive?path=$working_dir -H \'Content-Type: application/x-tar\' --data-binary @$tarbin > /dev/stderr
curl $SOCK_OPT -X PUT ${endpoint}/containers/${container}/archive?path=$working_dir -H 'Content-Type: application/x-tar' --data-binary @$tarbin
rm -f $tarbin
}
buildtar(){
targetpath=$1
local dir=${targetpath%\/*}
local target=${targetpath##*\/}
if [[ $dir = $target ]];then
dir='.'
fi
wdir=${PWD}
cd $dir
if [ ! -f $target.tar.gz ];then
echo tar zcvf $target.tar.gz $target > /dev/stderr
tar zcvf $target.tar.gz $target > /dev/null
fi
cd $wdir
echo $targetpath.tar.gz
}
### start to deploy
if [ ! -d dist ];then
echo no dist to deploy !
exit
fi
## stop container first
status=$(getcontainerstatus $ENDPOINT $deploy_container)
if [[ $status = running ]];then
echo stopping container $deploy_container ..
stopcontainer $ENDPOINT $deploy_container
status=$(getcontainerstatus $ENDPOINT $deploy_container)
if [[ ! $status = 'exited' ]];then
echo "fatal: fail to stop $deploy_container: $status !"
exit
fi
fi
echo stopped: $status !
## build tar
if [ -f dist.tar.gz ];then
rm -f dist.tar.gz
fi
echo build tar dist.tar.gz ..
disttar=$(buildtar dist)
##method 1# put standalone
echo deploying dist.tar.gz ..
working_dir=$(workingdir_nginx $ENDPOINT $deploy_container 2> /dev/null)
echo puttartocontainer $ENDPOINT $deploy_container $working_dir $disttar
puttartocontainer $ENDPOINT $deploy_container $working_dir $disttar
##method 2 filesystem working dir
fswdir=$(getcontainerworkingdir $ENDPOINT $deploy_container)
echo fswdir=$fswdir
# app=${deploy_standalone#*/}
# ls -l $working_dir/$app
# echo cp $deploy_standalone $working_dir
# cp $deploy_standalone $working_dir
# ls -l $working_dir/$app
## restart container
echo restarting container $deploy_container ..
restartcontainer $ENDPOINT $deploy_container
status=$(getcontainerstatus $ENDPOINT $deploy_container)
echo restarted: $status ..
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。