Skip to content

Commit

Permalink
Fixed logs not showing up immediately in docker container.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbollen23 committed Sep 13, 2024
1 parent b921255 commit 0814314
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .build-files/Dockerfile.loon.local
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY . .

# Run a command to keep the container running
# Specifying config and overwriting.
CMD ["python3", "build.py", "-o", "--config-file", ".build-files/config-local.json"]
CMD ["python3", "-u", "build.py", "-os", "--config-file", ".build-files/config-local.json"]
2 changes: 1 addition & 1 deletion .build-files/Dockerfile.loon.minio
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY . .

# Run a command to keep the container running
# Specifying config and overwriting.
CMD ["python3", "build.py", "-o", "--config-file", ".build-files/config-standard.json"]
CMD ["python3", "-u", "build.py", "-os", "--config-file", ".build-files/config-standard.json"]
1 change: 1 addition & 0 deletions .build-files/docker-compose-local.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- "80:80"
depends_on:
- server
- celery
env_file:
- path: ${DOCKER_ENV_FILE} # relative to docker compose (has to be in same directory)
required: true
Expand Down
1 change: 1 addition & 0 deletions .build-files/docker-compose.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- ${SSL_MAPPING:-/dev/null:/dev/null}
depends_on:
- server
- celery
env_file:
- path: ${DOCKER_ENV_FILE} # relative to docker compose (has to be in same directory)
required: true
Expand Down
53 changes: 33 additions & 20 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,26 @@ def follow_logs(service_name, logs_path, verbose=False, detached=False):
# Optionally send std error to subprocess.PIPE and then take STDERR and log to error file


def build_containers(env_file):
def build_containers(env_file, disable_spinner=False):
global stop_spinner
stop_spinner = False
""" Build the containers. """
# print("Building Containers...")
spinner_thread = threading.Thread(target=spinner, args=("Building containers...",))
spinner_thread.start()
if not disable_spinner:
stop_spinner = False
""" Build the containers. """
spinner_thread = threading.Thread(target=spinner, args=("Building containers...",))
spinner_thread.start()
else:
print("Building containers...")

process = run_command(f"docker-compose -f .build-files/docker-compose.yml"
f" --env-file {env_file} build")
process.wait() # Wait for the build to complete

stop_spinner = True
spinner_thread.join() # Ensure spinner thread completes
print("\nBuild complete.") # Print new line after spinner stops
if not disable_spinner:
stop_spinner = True
spinner_thread.join() # Ensure spinner thread completes
print("\nBuild complete.") # Print new line after spinner stops
else:
print("Build Complete.")


def follow_all_logs(logs_path, services, verbose=False, detached=False):
Expand All @@ -274,21 +280,26 @@ def follow_all_logs(logs_path, services, verbose=False, detached=False):
log_thread.start()


def start_containers(env_file):
def start_containers(env_file, disable_spinner=False):
global stop_spinner
stop_spinner = False
""" Start the containers in detached mode. """
spinner_thread = threading.Thread(target=spinner, args=("Starting containers...",))
spinner_thread.start()
if not disable_spinner:
stop_spinner = False
""" Start the containers in detached mode. """
spinner_thread = threading.Thread(target=spinner, args=("Starting containers...",))
spinner_thread.start()
else:
print("Starting containers...")
process = run_command(f"docker-compose -f .build-files/docker-compose.yml"
f" --env-file {env_file} up -d")

process.wait() # Wait for the containers to start

stop_spinner = True
spinner_thread.join() # Ensure spinner thread completes

print("\nContainers started.")
if not disable_spinner:
stop_spinner = True
spinner_thread.join() # Ensure spinner thread completes
print("\nContainers started.")
else:
print("Build Complete.")


def check_containers_status(services, detached=False):
Expand Down Expand Up @@ -362,6 +373,8 @@ def spinner(msg):
"corresponding environment file.")
parser.add_argument("-o", "--overwrite", action="store_true",
help="If present, overwrites chosen config with current env variables")
parser.add_argument("-s", "--disable-spinner", action="store_true", required=False,
help="Disables spinner")

args = parser.parse_args()

Expand Down Expand Up @@ -404,8 +417,8 @@ def spinner(msg):
signal.signal(signal.SIGINT, cleanup_and_exit)

# Build, run, then follow all logs. Begin monitoring process
build_containers(f'.build-files/{args.env_file}')
start_containers(f'.build-files/{args.env_file}')
build_containers(f'.build-files/{args.env_file}', args.disable_spinner)
start_containers(f'.build-files/{args.env_file}', args.disable_spinner)
follow_all_logs(logs_path, services, args.verbose, args.detached)
check_containers_status(services, args.detached)
else:
Expand Down

0 comments on commit 0814314

Please sign in to comment.