代码拉取完成,页面将自动刷新
#!/usr/bin/env bash
################################
## used to deploy the lib artifact from remove maven center to the standalone docker container
################################
usage(){
echo 'usage: CONTAINER=<container> deploy-artifact.sh [OPTIONS] <artifact>'
echo 'artifact'
echo ' the maven dependency e.g. org.json:json:20230227'
echo 'OPTIONS:'
echo ' -h --help for help'
echo ' -f --force force to add new jar, default to reject'
echo ' -r --restart restart container only'
exit -1
}
######################
deploy_container=${CONTAINER}
####################
if [ ! $deploy_container ];then
usage
fi
#########################
ENDPOINT="http://localhost" # for SOCK_OPT
SOCK_OPT='--unix-socket /var/run/docker.sock'
## working dir within container => /webapps
getworkingdir(){
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 | jq '.HostConfig.Binds[] | match(\"[a-z_/]*:/webapps*\").string'" > /dev/stderr
local binds=$(curl $SOCK_OPT -s $endpoint/containers/$container/json | jq '.HostConfig.Binds[] | match("[a-z_/]*:/webapps*").string')
# for workingdir_nginx
#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}
bind=${bind%:/webapps}
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
getcomposeworkingdir(){
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
}
### ################################
### main
####################################
artifact=
artifact_opt=
force_opt=
restart_opt=
for opt in $@;do
if [[ $opt = -h || $opt = '--help' ]];then
usage
elif [[ $opt = -f || $opt = '--force' ]];then
force_opt=$opt
elif [[ $opt = '-r' || $opt = '--restart' ]];then
restart_opt=$opt
else
artifact_opt=$opt
fi
done
if [ $restart_opt ];then
echo "restarting $deploy_container"
unset $artifact_opt
fi
if [ ! $artifact_opt ];then
usage
fi
main_deploy_artifact(){
artifact=$1
webapps_workingdir=$(getcomposeworkingdir $ENDPOINT $deploy_container )
echo "compose_working_dir=$webapps_workingdir" > /dev/stderr
if [ ! $webapps_workdingdir ];then
webapps_workingdir=$(getworkingdir $ENDPOINT $deploy_container )
echo "webapps_working_dir=$webapps_workingdir" > /dev/stderr
fi
if [ ! $webapps_workingdir ];then
echo "fail to get webapps working dir from container: $container !" > /dev/stderr
exit -2
fi
if [ ! -d $webapps_workingdir ];then
echo "$webapps_workingdir not exists !" > /dev/stderr
exit -2
fi
docker run --rm -v $webapps_workingdir:/webapps zelejs/allin-web:deploy-lib $artifact $force_opt
}
#############################################
## main
#############################################
## stop container first
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
echo stopped: $status !
## restart or deploy
main_deploy_artifact $artifact_opt
## restart container
echo restarting container $deploy_container ..
restartcontainer $ENDPOINT $deploy_container
status=$(getcontainerstatus $ENDPOINT $deploy_container)
echo restarted: $status ..
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。