autoconf - use DNS for Swarm instances discovery
This commit is contained in:
parent
24d9cce82f
commit
652614f41b
@ -13,7 +13,8 @@ RUN chmod +x /tmp/docker.sh && \
|
|||||||
rm -f /tmp/docker.sh
|
rm -f /tmp/docker.sh
|
||||||
|
|
||||||
# Fix CVE-2021-22901, CVE-2021-22898, CVE-2021-22897, CVE-2021-33560 and CVE-2021-36159
|
# Fix CVE-2021-22901, CVE-2021-22898, CVE-2021-22897, CVE-2021-33560 and CVE-2021-36159
|
||||||
RUN apk add "curl>=7.77.0-r0" "libgcrypt>=1.8.8-r0" "apk-tools>=2.12.6-r0"
|
RUN apk add "curl>=7.77.0-r0" "libgcrypt>=1.8.8-r0"
|
||||||
|
RUN apk add "apk-tools>=2.12.6-r0"
|
||||||
|
|
||||||
VOLUME /www /http-confs /server-confs /modsec-confs /modsec-crs-confs /cache /pre-server-confs /acme-challenge /plugins
|
VOLUME /www /http-confs /server-confs /modsec-confs /modsec-crs-confs /cache /pre-server-confs /acme-challenge /plugins
|
||||||
|
|
||||||
|
|||||||
@ -8,10 +8,10 @@ if [ "$?" -ne 0 ] ; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$SWARM_MODE" = "yes" ] ; then
|
#if [ "$SWARM_MODE" = "yes" ] ; then
|
||||||
chown -R root:nginx /etc/nginx
|
# chown -R root:nginx /etc/nginx
|
||||||
chmod -R 770 /etc/nginx
|
# chmod -R 770 /etc/nginx
|
||||||
fi
|
#fi
|
||||||
|
|
||||||
# trap SIGTERM and SIGINT
|
# trap SIGTERM and SIGINT
|
||||||
function trap_exit() {
|
function trap_exit() {
|
||||||
|
|||||||
@ -2,3 +2,4 @@ docker
|
|||||||
requests
|
requests
|
||||||
jinja2
|
jinja2
|
||||||
kubernetes
|
kubernetes
|
||||||
|
dnspython
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import subprocess, shutil, os, traceback, requests, time
|
import subprocess, shutil, os, traceback, requests, time, dns.resolver
|
||||||
|
|
||||||
import Controller
|
import Controller
|
||||||
|
|
||||||
@ -76,9 +76,9 @@ class Config :
|
|||||||
def wait(self, instances) :
|
def wait(self, instances) :
|
||||||
ret = True
|
ret = True
|
||||||
if self.__type == Controller.Type.DOCKER :
|
if self.__type == Controller.Type.DOCKER :
|
||||||
ret = self.__wait_docker()
|
ret = self.__wait_docker(instances)
|
||||||
elif self.__type == Controller.Type.SWARM or self.__type == Controller.Type.KUBERNETES :
|
elif self.__type == Controller.Type.SWARM or self.__type == Controller.Type.KUBERNETES :
|
||||||
ret = self.__wait_api()
|
ret = self.__wait_api(instances)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def __wait_docker(self, instances) :
|
def __wait_docker(self, instances) :
|
||||||
@ -110,7 +110,7 @@ class Config :
|
|||||||
started = True
|
started = True
|
||||||
break
|
break
|
||||||
i = i + 1
|
i = i + 1
|
||||||
log("config", "INFO" "waiting " + str(i) + " seconds before retrying to contact bunkerized-nginx instances")
|
log("config", "INFO", "waiting " + str(i) + " seconds before retrying to contact bunkerized-nginx instances")
|
||||||
if started :
|
if started :
|
||||||
log("config", "INFO", "bunkerized-nginx instances started")
|
log("config", "INFO", "bunkerized-nginx instances started")
|
||||||
return True
|
return True
|
||||||
@ -126,17 +126,19 @@ class Config :
|
|||||||
if self.__type == Controller.Type.SWARM :
|
if self.__type == Controller.Type.SWARM :
|
||||||
for instance in instances :
|
for instance in instances :
|
||||||
name = instance.name
|
name = instance.name
|
||||||
for task in instance.tasks() :
|
try :
|
||||||
nodeID = task["NodeID"]
|
dns_result = dns.resolver.query("tasks." + name)
|
||||||
taskID = task["ID"]
|
for ip in dns_result :
|
||||||
url = "http://" + name + "." + nodeID + "." + taskID + ":8080" + self.__api_uri + path
|
urls.append("http://" + ip.to_text() + ":8080" + self.__api_uri + path)
|
||||||
urls.append(url)
|
except :
|
||||||
|
ret = False
|
||||||
elif self.__type == Controller.Type.KUBERNETES :
|
elif self.__type == Controller.Type.KUBERNETES :
|
||||||
log("config", "ERROR", "TODO get urls for k8s")
|
log("config", "ERROR", "TODO get urls for k8s")
|
||||||
|
|
||||||
for url in urls :
|
for url in urls :
|
||||||
|
req = None
|
||||||
try :
|
try :
|
||||||
req = requests.post("http://" + fqdn + ":8080" + self.__api + path)
|
req = requests.post(url)
|
||||||
except :
|
except :
|
||||||
pass
|
pass
|
||||||
if req and req.status_code == 200 and req.text == "ok" :
|
if req and req.status_code == 200 and req.text == "ok" :
|
||||||
|
|||||||
@ -40,6 +40,12 @@ if current_env != {} :
|
|||||||
else :
|
else :
|
||||||
log("autoconf", "ERROR", "error while generating initial configuration")
|
log("autoconf", "ERROR", "error while generating initial configuration")
|
||||||
|
|
||||||
|
# Wait for instances
|
||||||
|
if controller.wait() :
|
||||||
|
log("autoconf", "INFO", "bunkerized-nginx instances started")
|
||||||
|
else :
|
||||||
|
log("autoconf", "ERROR", "bunkerized-nginx instances not started")
|
||||||
|
|
||||||
# Process events
|
# Process events
|
||||||
log("autoconf", "INFO", "waiting for events ...")
|
log("autoconf", "INFO", "waiting for events ...")
|
||||||
controller.process_events(current_env)
|
controller.process_events(current_env)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user