Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for the docker deploy script to execute the reload cmd with the user root #5083

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .test-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PDNS_Url=http://192.168.42.199:8000
PDNS_ServerId=localhost
PDNS_Token=aaff153f99761ce9931f6717016ad2f4-0b87b0a7263927744a361008e0c5110b
DEPLOY_DOCKER_CONTAINER_LABEL=sh.acme.autoload.domain=test.elaon.de
DEPLOY_DOCKER_CONTAINER_KEY_FILE=/opt/emqx/etc/certs/key.pem
DEPLOY_DOCKER_CONTAINER_CERT_FILE="/opt/emqx/etc/certs/cert.pem"
DEPLOY_DOCKER_CONTAINER_CA_FILE="/opt/emqx/etc/certs/cacert.pem"
DEPLOY_DOCKER_CONTAINER_FULLCHAIN_FILE="/opt/emqx/etc/certs/full.pem"
DEPLOY_DOCKER_CONTAINER_RELOAD_CMD="chmod 664 /opt/emqx/etc/certs/*.pem && /opt/emqx/bin/emqx stop"
#DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT="true"
29 changes: 27 additions & 2 deletions deploy/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
#DEPLOY_DOCKER_CONTAINER_CA_FILE="/path/to/ca.pem"
#DEPLOY_DOCKER_CONTAINER_FULLCHAIN_FILE="/path/to/fullchain.pem"
#DEPLOY_DOCKER_CONTAINER_RELOAD_CMD="service nginx force-reload"
#DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT="false"

_DEPLOY_DOCKER_WIKI="https://github.com/acmesh-official/acme.sh/wiki/deploy-to-docker-containers"

_DOCKER_HOST_DEFAULT="/var/run/docker.sock"

_RUN_AS_ROOT="false"

docker_deploy() {
_cdomain="$1"
_ckey="$2"
Expand Down Expand Up @@ -94,6 +97,18 @@ docker_deploy() {
_savedeployconf DEPLOY_DOCKER_CONTAINER_RELOAD_CMD "$DEPLOY_DOCKER_CONTAINER_RELOAD_CMD" "base64"
fi

_getdeployconf DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT
if [ "$DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT" == "true" ]; then
DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT="true"
_RUN_AS_ROOT="true"
else
DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT="false"
fi
_debug2 DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT "$DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT"
if [ "$DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT" ]; then
_savedeployconf DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT "$DEPLOY_DOCKER_CONTAINER_RUN_AS_ROOT"
fi

_cid="$(_get_id "$DEPLOY_DOCKER_CONTAINER_LABEL")"
_info "Container id: $_cid"
if [ -z "$_cid" ]; then
Expand Down Expand Up @@ -163,16 +178,26 @@ _docker_exec() {
_dcid="$1"
shift
if [ "$_USE_DOCKER_COMMAND" ]; then
docker exec -i "$_dcid" sh -c "$*"
_OPTS=""
if [ "$_RUN_AS_ROOT" == "true" ]; then
_OPTS="-u root"
_debug2 "Run docker exec with user root"
fi
docker exec $_OPTS -i "$_dcid" sh -c "$*"
elif [ "$_USE_REST" ]; then
_err "Not implemented yet."
return 1
elif [ "$_USE_UNIX_SOCKET" ]; then
_cmd="$*"
#_cmd="$(printf "%s" "$_cmd" | sed 's/ /","/g')"
_debug2 _cmd "$_cmd"
_OPTS=""
if [ "$_RUN_AS_ROOT" == "true" ]; then
_OPTS='"User": "root", '
_debug2 "Run docker exec with user root"
fi
#create exec instance:
cjson="$(_curl_unix_sock "$_DOCKER_SOCK" POST "/containers/$_dcid/exec" "{\"Cmd\": [\"sh\", \"-c\", \"$_cmd\"]}")"
cjson="$(_curl_unix_sock "$_DOCKER_SOCK" POST "/containers/$_dcid/exec" "{$_OPTS\"Cmd\": [\"sh\", \"-c\", \"$_cmd\"]}")"
_debug2 cjson "$cjson"
execid="$(echo "$cjson" | cut -d '"' -f 4)"
_debug execid "$execid"
Expand Down