Sing Yu Chan
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
48 additions and
11 deletions
-
.github/workflows/dockerhub.yml
-
docker/Dockerfile
-
docker/entry.sh
-
docker/restart-container.sh
|
|
|
@ -8,10 +8,9 @@ on: |
|
|
|
- '*' |
|
|
|
paths: |
|
|
|
- '**.sh' |
|
|
|
- "Dockerfile" |
|
|
|
- "docker/**" |
|
|
|
- '.github/workflows/dockerhub.yml' |
|
|
|
|
|
|
|
|
|
|
|
jobs: |
|
|
|
CheckToken: |
|
|
|
runs-on: ubuntu-latest |
|
|
|
@ -30,7 +29,7 @@ jobs: |
|
|
|
fi |
|
|
|
- name: Check the value |
|
|
|
run: echo ${{ steps.step_one.outputs.hasToken }} |
|
|
|
|
|
|
|
|
|
|
|
build: |
|
|
|
runs-on: ubuntu-latest |
|
|
|
needs: CheckToken |
|
|
|
|
|
|
|
@ -62,14 +62,8 @@ RUN for verb in help \ |
|
|
|
printf -- "%b" "#!/usr/bin/env sh\n/root/.acme.sh/acme.sh --${verb} --config-home /acme.sh \"\$@\"" >/usr/local/bin/--${verb} && chmod +x /usr/local/bin/--${verb} \ |
|
|
|
; done |
|
|
|
|
|
|
|
RUN printf "%b" '#!'"/usr/bin/env sh\n \ |
|
|
|
if [ \"\$1\" = \"daemon\" ]; then \n \ |
|
|
|
trap \"echo stop && killall crond && exit 0\" SIGTERM SIGINT \n \ |
|
|
|
crond && sleep infinity &\n \ |
|
|
|
wait \n \ |
|
|
|
else \n \ |
|
|
|
exec -- \"\$@\"\n \ |
|
|
|
fi" >/entry.sh && chmod +x /entry.sh |
|
|
|
COPY entry.sh / |
|
|
|
COPY restart-container.sh /usr/local/bin/ |
|
|
|
|
|
|
|
VOLUME /acme.sh |
|
|
|
|
|
|
|
@ -0,0 +1,9 @@ |
|
|
|
#!/usr/bin/env sh |
|
|
|
|
|
|
|
if [ "$1" = "daemon" ]; then |
|
|
|
trap "echo stop && killall crond && exit 0" SIGTERM SIGINT |
|
|
|
crond && sleep infinity & |
|
|
|
wait |
|
|
|
else |
|
|
|
exec -- "$@" |
|
|
|
fi |
|
|
|
@ -0,0 +1,35 @@ |
|
|
|
#!/bin/sh |
|
|
|
# |
|
|
|
# Usage: |
|
|
|
# restart-container.sh <container_name_1> <container_name_2> <container_name_n...> |
|
|
|
# |
|
|
|
# The design idea was derived from docker.sh by acmesh-official |
|
|
|
# |
|
|
|
# https://github.com/acmesh-official/acme.sh/blob/5b8d7a3/deploy/docker.sh |
|
|
|
# |
|
|
|
|
|
|
|
DOCKER_DAEMON_SOCKET="/var/run/docker.sock" |
|
|
|
|
|
|
|
_get_container_id_by_name() { |
|
|
|
local container_name="$1" |
|
|
|
curl --silent --unix-socket "$DOCKER_DAEMON_SOCKET" -X GET "http://localhost/containers/json?filters=%7B%22name%22%3A%5B%22${container_name}%22%5D%7D" | |
|
|
|
tr '{,' '\n' | |
|
|
|
grep -i '"id":' | |
|
|
|
head -n 1 | |
|
|
|
cut -d '"' -f 4 |
|
|
|
} |
|
|
|
|
|
|
|
_restart_container_by_id() { |
|
|
|
local container_name="$1" |
|
|
|
local container_id="$(_get_container_id_by_name $container_name)" |
|
|
|
curl --silent --unix-socket "$DOCKER_DAEMON_SOCKET" -X POST http://localhost/containers/${container_id}/restart |
|
|
|
} |
|
|
|
|
|
|
|
_restart_container_by_name() { |
|
|
|
local container_name="$1" |
|
|
|
curl --silent --unix-socket "$DOCKER_DAEMON_SOCKET" -X POST http://localhost/containers/${container_name}/restart |
|
|
|
} |
|
|
|
|
|
|
|
for container_name in "$@"; do |
|
|
|
_restart_container_by_name "$container_name" |
|
|
|
done |