mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00

- All files moved to k8s/nginx-3scale with directory structure consistent with k8s/nginx-http(s) - Top level LICENCES.md updated - Renaming entry point script to nginx_openresty_entrypoint.bash
59 lines
2.2 KiB
Bash
Executable File
59 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Openresty vars
|
|
dns_server=`printenv DNS_SERVER`
|
|
openresty_frontend_port=`printenv OPENRESTY_FRONTEND_PORT`
|
|
|
|
|
|
# BigchainDB vars
|
|
bdb_backend_host=`printenv BIGCHAINDB_BACKEND_HOST`
|
|
bdb_api_port=`printenv BIGCHAINDB_API_PORT`
|
|
|
|
|
|
# Read the 3scale credentials from the mountpoint
|
|
# Should be mounted at the following directory
|
|
THREESCALE_CREDENTIALS_DIR=/usr/local/openresty/nginx/conf/threescale
|
|
|
|
threescale_secret_token=`cat ${THREESCALE_CREDENTIALS_DIR}/secret-token`
|
|
threescale_service_id=`cat ${THREESCALE_CREDENTIALS_DIR}/service-id`
|
|
threescale_version_header=`cat ${THREESCALE_CREDENTIALS_DIR}/version-header`
|
|
threescale_service_token=`cat ${THREESCALE_CREDENTIALS_DIR}/service-token`
|
|
|
|
|
|
# sanity checks TODO(Krish): hardening
|
|
if [[ -z "${dns_server}" || \
|
|
-z "${openresty_frontend_port}" || \
|
|
-z "${bdb_backend_host}" || \
|
|
-z "${bdb_api_port}" || \
|
|
-z "${threescale_secret_token}" || \
|
|
-z "${threescale_service_id}" || \
|
|
-z "${threescale_version_header}" || \
|
|
-z "${threescale_service_token}" ]]; then
|
|
echo "Invalid environment settings detected. Exiting!"
|
|
exit 1
|
|
fi
|
|
|
|
NGINX_LUA_FILE=/usr/local/openresty/nginx/conf/nginx.lua
|
|
NGINX_CONF_FILE=/usr/local/openresty/nginx/conf/nginx.conf
|
|
|
|
# configure the nginx.lua file with env variables
|
|
sed -i "s|SERVICE_ID|${threescale_service_id}|g" ${NGINX_LUA_FILE}
|
|
sed -i "s|THREESCALE_RESPONSE_SECRET_TOKEN|${threescale_secret_token}|g" ${NGINX_LUA_FILE}
|
|
sed -i "s|SERVICE_TOKEN|${threescale_service_token}|g" ${NGINX_LUA_FILE}
|
|
|
|
# configure the nginx.conf file with env variables
|
|
sed -i "s|DNS_SERVER|${dns_server}|g" ${NGINX_CONF_FILE}
|
|
sed -i "s|OPENRESTY_FRONTEND_PORT|${openresty_frontend_port}|g" ${NGINX_CONF_FILE}
|
|
sed -i "s|BIGCHAINDB_BACKEND_HOST|${bdb_backend_host}|g" ${NGINX_CONF_FILE}
|
|
sed -i "s|BIGCHAINDB_API_PORT|${bdb_api_port}|g" ${NGINX_CONF_FILE}
|
|
sed -i "s|THREESCALE_RESPONSE_SECRET_TOKEN|${threescale_secret_token}|g" $NGINX_CONF_FILE
|
|
sed -i "s|SERVICE_ID|${threescale_service_id}|g" $NGINX_CONF_FILE
|
|
sed -i "s|THREESCALE_VERSION_HEADER|${threescale_version_header}|g" $NGINX_CONF_FILE
|
|
sed -i "s|SERVICE_TOKEN|${threescale_service_token}|g" $NGINX_CONF_FILE
|
|
|
|
|
|
# start nginx
|
|
echo "INFO: starting nginx..."
|
|
exec /usr/local/openresty/nginx/sbin/nginx -c ${NGINX_CONF_FILE}
|