From ffa7ecb11509759270445be1e7dfc15d8ce6f3c9 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Tue, 18 Feb 2025 22:57:34 +0400 Subject: [PATCH] initial commit: add dockerfile --- Dockerfile | 11 +++++++++++ entrypoint.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2a1e173 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM alpine:latest + +RUN apk add --no-cache nginx python3 py3-virtualenv + +RUN python3 -m venv /venv +RUN /venv/bin/pip install -U pip certbot certbot-nginx + +RUN apk del py3-virtualenv && rm -rf /var/cache/apk + +COPY ./entrypoint.sh / +CMD ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..3cf3352 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,33 @@ +#!/bin/ash + +if [ ! -e /etc/letsencrypt ] +then + echo "[!!] Certbot directory is not initialized" + echo "[!!] Either it's the first run or you forgot to add a volume" + + # check if stdin (fd 0) is assigned to a tty + [ ! -t 0 ] && echo "Not a TTY! Exiting" && exit 1 + + /venv/bin/certbot certonly --nginx + exit $? +fi + +/usr/sbin/nginx -c /etc/nginx/nginx.conf & +ngpid=$! +waitpid="" + +ctrlc () { + kill -QUIT "$ngpid" + [ -n "$waitpid" ] && kill -INT "$waitpid" +} + +trap ctrlc INT +trap ctrlc TERM + +while true +do + /venv/bin/certbot renew --post-hook "kill -HUP $ngpid" + sleep 12h & + waitpid=$! + wait +done