From 884cbcc5317dbfcb4bb8fcf51d9533e9eedac1f1 Mon Sep 17 00:00:00 2001 From: Sebastian Macarescu Date: Mon, 25 May 2020 19:00:00 +0300 Subject: [PATCH] add basic redis --- .gitattributes | 1 + Dockerfile | 4 ++++ entrypoint.sh | 2 +- snippets/resty-http.conf | 11 ++++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..526c8a3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 936abd8..ad25e7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,10 @@ ENV DIFFIE_HELLMAN='' \ FORCE_HTTPS='true' \ SITES='' \ LETSENCRYPT_URL='https://acme-v02.api.letsencrypt.org/directory' \ + STORAGE_ADAPTER='file' \ + REDIS_HOST='' \ + REDIS_DB='' \ + REDIS_KEY_PREFIX='' \ RESOLVER_ADDRESS='8.8.8.8' # Here we install open resty and generate dhparam.pem file. diff --git a/entrypoint.sh b/entrypoint.sh index 6fed376..6bf4f69 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -59,7 +59,7 @@ fi # let's substitute $ALLOWED_DOMAINS, $LETSENCRYPT_URL and $RESOLVER_ADDRESS into OpenResty configuration -envsubst '$ALLOWED_DOMAINS,$LETSENCRYPT_URL,$RESOLVER_ADDRESS' \ +envsubst '$ALLOWED_DOMAINS,$LETSENCRYPT_URL,$RESOLVER_ADDRESS,$STORAGE_ADAPTER,$REDIS_HOST,$REDIS_DB,$REDIS_KEY_PREFIX' \ < ${RESTY_CONF_DIR}/resty-http.conf \ > ${RESTY_CONF_DIR}/resty-http.conf.copy \ && mv ${RESTY_CONF_DIR}/resty-http.conf.copy ${RESTY_CONF_DIR}/resty-http.conf diff --git a/snippets/resty-http.conf b/snippets/resty-http.conf index 626ddad..f3ed8ae 100644 --- a/snippets/resty-http.conf +++ b/snippets/resty-http.conf @@ -1,7 +1,7 @@ # The "auto_ssl" shared dict should be defined with enough storage space to # hold your certificate data. 1MB of storage holds certificates for # approximately 100 separate domains. -lua_shared_dict auto_ssl 1m; +lua_shared_dict auto_ssl 10m; # The "auto_ssl" shared dict is used to temporarily store various settings # like the secret used by the hook server on port 8999. Do not change or @@ -27,6 +27,15 @@ init_by_lua_block { return ngx.re.match(domain, '$ALLOWED_DOMAINS', 'ijo') end) + if "$STORAGE_ADAPTER" == "redis" then + auto_ssl:set("storage_adapter", "resty.auto-ssl.storage_adapters.redis") + auto_ssl:set("redis", { + host = "$REDIS_HOST", + db = "$REDIS_DB", + prefix = "$REDIS_KEY_PREFIX" + }) + end + auto_ssl:init() }