Merge pull request #786 from bunkerity/dev

Merge branch "dev" into branch "ui"
This commit is contained in:
Théophile Diot 2023-12-01 08:57:56 +00:00 committed by GitHub
commit 700b434f4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 45 deletions

4
.gitattributes vendored
View File

@ -6,6 +6,8 @@ src/common/core/modsecurity/files/** -text -eol linguist-vendored=true
src/ui/static/js/editor/** -text -eol linguist-vendored=true
src/ui/static/js/utils/purify/** -text -eol linguist-vendored=true
src/ui/static/webfonts/** -text -eol linguist-vendored=true
src/ui/templates/*.html -text -eol linguist-vendored=true
src/common/core/antibot/files/*.html -text -eol linguist-vendored=true
# Files
src/deps/misc/lua-pack.Makefile -linguist-vendored=true
@ -15,3 +17,5 @@ src/ui/static/css/flatpickr.css -linguist-vendored=true
src/ui/static/css/flatpickr.dark.css -linguist-vendored=true
src/ui/static/js/tsparticles.bundle.min.js -linguist-vendored=true
src/ui/static/js/utils/flatpickr.js -linguist-vendored=true
src/common/core/errors/files/error.html -linguist-vendored=true
src/common/core/misc/files/default.html -linguist-vendored=true

View File

@ -84,7 +84,7 @@ jobs:
# Compute metadata
- name: Extract metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
uses: docker/metadata-action@e6428a5c4e294a61438ed7f43155db912025b6b3 # v5.2.0
with:
images: bunkerity/${{ inputs.IMAGE }}
# Build cached image

View File

@ -135,7 +135,7 @@ jobs:
- name: Extract metadata
if: inputs.TEST == true
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
uses: docker/metadata-action@e6428a5c4e294a61438ed7f43155db912025b6b3 # v5.2.0
with:
images: ghcr.io/bunkerity/${{ inputs.LINUX }}-tests:${{ inputs.RELEASE }}
- name: Build test image

View File

@ -63,7 +63,7 @@ jobs:
# Compute metadata
- name: Extract metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
uses: docker/metadata-action@e6428a5c4e294a61438ed7f43155db912025b6b3 # v5.2.0
with:
images: bunkerity/${{ inputs.IMAGE }}
# Build and push

View File

@ -450,6 +450,23 @@ if __name__ == "__main__":
else:
logger.info(f"Successfully sent {CACHE_PATH} folder")
def listen_for_instances_reload(db: Database):
from docker import DockerClient
global SCHEDULER
docker_client = DockerClient(base_url=getenv("DOCKER_HOST", "unix:///var/run/docker.sock"))
for event in docker_client.events(decode=True, filters={"type": "container", "label": "bunkerweb.INSTANCE"}):
if event["Action"] in ("start", "die"):
logger.info(f"🐋 Detected {event['Action']} event on container {event['Actor']['Attributes']['name']}")
SCHEDULER.auto_setup()
db.update_instances([api_to_instance(api) for api in SCHEDULER.apis], changed=event["Action"] == "die")
if event["Action"] == "start":
db.checked_changes(value=True)
if INTEGRATION == "Docker":
Thread(target=listen_for_instances_reload, args=(db,), name="listen_for_instances_reload").start()
while True:
threads.clear()
ret = db.checked_changes(CHANGES)
@ -508,6 +525,8 @@ if __name__ == "__main__":
thread = Thread(target=send_nginx_configs)
thread.start()
threads.append(thread)
elif INTEGRATION != "Linux":
logger.warning("No BunkerWeb instance found, skipping nginx configs sending ...")
try:
if SCHEDULER.apis:
@ -523,7 +542,7 @@ if __name__ == "__main__":
logger.info("Successfully reloaded nginx")
else:
logger.error("Error while reloading nginx")
else:
elif INTEGRATION == "Linux":
# Reload nginx
logger.info("Reloading nginx ...")
proc = subprocess_run([join(sep, "usr", "sbin", "nginx"), "-s", "reload"], stdin=DEVNULL, stderr=STDOUT, env=env.copy(), check=False, stdout=PIPE)
@ -533,46 +552,8 @@ if __name__ == "__main__":
logger.error(
f"Error while reloading nginx - returncode: {proc.returncode} - error: {proc.stdout.decode('utf-8') if proc.stdout else 'no output'}",
)
# # Stop temp nginx
# logger.info("Stopping temp nginx ...")
# proc = subprocess_run(
# [join(sep, "usr", "sbin", "nginx"), "-s", "stop"],
# stdin=DEVNULL,
# stderr=STDOUT,
# env=env.copy(),
# check=False,
# )
# if proc.returncode == 0:
# logger.info("Successfully sent stop signal to temp nginx")
# i = 0
# while i < 20:
# if not Path(sep, "var", "run", "bunkerweb", "nginx.pid").is_file():
# break
# logger.warning("Waiting for temp nginx to stop ...")
# sleep(1)
# i += 1
# if i >= 20:
# logger.error("Timeout error while waiting for temp nginx to stop")
# else:
# # Start nginx
# logger.info("Starting nginx ...")
# proc = subprocess_run(
# [join(sep, "usr", "sbin", "nginx"), "-e", "/var/log/bunkerweb/error.log"],
# stdin=DEVNULL,
# stderr=STDOUT,
# env=env.copy(),
# check=False,
# )
# if proc.returncode == 0:
# logger.info("Successfully started nginx")
# else:
# logger.error(
# f"Error while starting nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
# )
# else:
# logger.error(
# f"Error while sending stop signal to temp nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
# )
else:
logger.warning("No BunkerWeb instance found, skipping nginx reload ...")
except:
logger.error(
f"Exception while reloading after running jobs once scheduling : {format_exc()}",
@ -659,7 +640,6 @@ if __name__ == "__main__":
logger.info("Instances changed, generating ...")
INSTANCES_NEED_GENERATION = True
CONFIG_NEED_GENERATION = True
RUN_JOBS_ONCE = True
NEED_RELOAD = True
FIRST_RUN = False