From aac7e6be90b4d571a5c8947672629f5e55368648 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 22 Apr 2020 11:45:11 +0200 Subject: [PATCH] lib: fix ram usage due to bootstrap bootstrap now exits (0) when all services are up, instead continuously running. This is combined with a simple bash script, which does this job instead. This also adds /bootstrap.sh as docker ENTRYPOINT --- Dockerfile | 3 +++ docker/bootstrap.sh | 3 +++ passbook/lib/management/commands/bootstrap.py | 15 ++------------- 3 files changed, 8 insertions(+), 13 deletions(-) create mode 100755 docker/bootstrap.sh diff --git a/Dockerfile b/Dockerfile index 3693620ac..6f533468b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,10 @@ RUN apt-get update && \ COPY ./passbook/ /app/passbook COPY ./manage.py /app/ COPY ./docker/uwsgi.ini /app/ +COPY ./docker/bootstrap.sh /bootstrap.sh WORKDIR /app/ USER passbook + +ENTRYPOINT [ "/bootstrap.sh" ] diff --git a/docker/bootstrap.sh b/docker/bootstrap.sh new file mode 100755 index 000000000..67cd1a5a8 --- /dev/null +++ b/docker/bootstrap.sh @@ -0,0 +1,3 @@ +#!/bin/bash -ex +/app/manage.py bootstrap +$@ diff --git a/passbook/lib/management/commands/bootstrap.py b/passbook/lib/management/commands/bootstrap.py index 7a172d51a..30bd046aa 100644 --- a/passbook/lib/management/commands/bootstrap.py +++ b/passbook/lib/management/commands/bootstrap.py @@ -1,10 +1,7 @@ """passbook management command to bootstrap""" from argparse import REMAINDER -from subprocess import Popen # nosec from sys import exit as _exit -from sys import stderr, stdin, stdout from time import sleep -from typing import List from django.core.management.base import BaseCommand from django.db import connection @@ -53,13 +50,5 @@ class Command(BaseCommand): while should_check: should_check = not (self.check_database() and self.check_cache()) sleep(1) - LOGGER.info("Dependencies are up, starting command...") - commands: List[str] = options.get("command", ["exit", "1"]) - proc = Popen(args=commands, stdout=stdout, stderr=stderr, stdin=stdin) # nosec - try: - proc.wait() - _exit(proc.returncode) - except KeyboardInterrupt: - LOGGER.info("Killing process") - proc.kill() - _exit(254) + LOGGER.info("Dependencies are up, exiting...") + _exit(0)