@@ -17,13 +17,22 @@ bootstrap_fn() {
1717 exit 1
1818 fi
1919
20- # First, validate the config file
21- if [ ! -f " $config_file " ]; then
22- echo " Missing $config_file . Did you forget to mount the config file?"
20+ if [ -z " ${CONFIG_JSON:- } " ]; then
21+ if [ -f " $config_file " ]; then
22+ CONFIG_JSON=$( cat " $config_file " )
23+ else
24+ echo " Missing $config_file . Did you forget to mount the config file?"
25+ exit 1
26+ fi
27+ fi
28+
29+ echo " $CONFIG_JSON " | jq empty 2> /dev/null
30+ if [ $? -ne 0 ]; then
31+ echo " Failed to parse the config file"
2332 exit 1
2433 fi
2534
26- num_domains=$( jq -e -r ' .domains | length' " $config_file " )
35+ num_domains=$( echo " $CONFIG_JSON " | jq -e -r ' .domains | length' )
2736 if [ $? -ne 0 ] || [ " $num_domains " -lt 1 ]; then
2837 echo " No domains listed in the config"
2938 exit 1
@@ -39,9 +48,9 @@ bootstrap_fn() {
3948 else
4049 # Install acme.sh with the email in the config, ensure the account_thumbprint
4150 if [ ! -d " $acme_dir " ]; then
42- email=$( jq -e -r ' .email' " $config_file " )
51+ email=$( echo " $CONFIG_JSON " | jq -e -r ' .email' )
4352 if [ $? -ne 0 ]; then
44- echo " $config_file is missing the email to use when registering the SSL certificates"
53+ echo " The config is missing the email to use when registering the SSL certificates"
4554 exit 1
4655 fi
4756 echo " Installing acme.sh"
@@ -74,8 +83,8 @@ bootstrap_fn() {
7483 echo " Creating the self-signed certificate"
7584
7685 mkdir -p " $cert_dir " || exit 1
77- subject=$( jq -e -r ' .domains[0].name' " $config_file " )
78- alt_names=$( jq -e -r ' .domains | map([.name] + .aliases) | flatten | map("DNS:" + .) | join(",")' " $config_file " )
86+ subject=$( echo " $CONFIG_JSON " | jq -e -r ' .domains[0].name' )
87+ alt_names=$( echo " $CONFIG_JSON " | jq -e -r ' .domains | map([.name] + .aliases) | flatten | map("DNS:" + .) | join(",")' )
7988 echo " subject: $subject "
8089 echo " alt_names: $alt_names "
8190 openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -nodes \
@@ -85,7 +94,7 @@ bootstrap_fn() {
8594 -addext " subjectAltName=$alt_names " || exit 1
8695 fi
8796
88- domains=$( jq -e -r ' .domains[].name' " $config_file " )
97+ domains=$( echo " $CONFIG_JSON " | jq -e -r ' .domains[].name' )
8998 # Note that this script assumes that the config.json is trusted input
9099 # and the domain doesn't have e.g. ../../ in it
91100 for domain in $domains ; do
@@ -105,7 +114,7 @@ bootstrap_fn() {
105114 cat /dev/null > " $data_dir /nginx_generated.conf"
106115 i=0
107116 while [ " $i " -lt " $num_domains " ]; do
108- domain_json=$( jq -e " .domains[$i ]" " $config_file " )
117+ domain_json=$( echo " $CONFIG_JSON " | jq -e " .domains[$i ]" )
109118 domain=$( echo " $domain_json " | jq -e -r ' .name' )
110119 if [ $? -ne 0 ]; then
111120 echo " Failed to get the name for $domain_json "
0 commit comments