Skip to content

Commit

Permalink
πŸ› Fix: don't disable access log if ACCESS_LOG was not set
Browse files Browse the repository at this point in the history
* βœ… Fix tests
  • Loading branch information
Rafael Weingartner-Ortner authored and RafaelWO committed Oct 9, 2023
1 parent 17a4692 commit 2fc3255
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docker-images/start-reload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export APP_MODULE=${APP_MODULE:-"$MODULE_NAME:$VARIABLE_NAME"}
HOST=${HOST:-0.0.0.0}
PORT=${PORT:-80}
LOG_LEVEL=${LOG_LEVEL:-info}
ACCESS_LOG=${ACCESS_LOG-"-"} # Set ACCESS_LOG="-" only if unset

# If ACCESS_LOG was set and is null, disable access log
ACCESS_LOG_OPTION=""
if [ -z "$ACCESS_LOG" ] ; then
ACCESS_LOG_OPTION="--no-access-log"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_03_reload/test_env_vars_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..utils import (
CONTAINER_NAME,
get_config,
get_process_names,
get_logs,
get_response_text1,
remove_previous_container,
Expand All @@ -26,8 +26,8 @@ def verify_container(container: DockerClient, response_text: str) -> None:
assert "Uvicorn running on http://0.0.0.0:80" in logs
response = requests.get("http://127.0.0.1:8000")
assert response.text == response_text
config_data = get_config(container)
assert config_data["accesslog"] == "-"
uvicorn_cmd = get_process_names(container, name="uvicorn")[0]
assert "--no-access-log" not in uvicorn_cmd


def test_env_vars_1() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_03_reload/test_env_vars_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import docker
from docker.models.containers import Container

from ..utils import CONTAINER_NAME, get_config, get_logs, remove_previous_container
from ..utils import CONTAINER_NAME, get_process_names, get_logs, remove_previous_container

client = docker.from_env()

Expand All @@ -17,8 +17,8 @@ def verify_container(container: Container) -> None:
"Running inside /app/prestart.sh, you could add migrations to this file" in logs
)
assert "Uvicorn running on http://127.0.0.1:80" in logs
config_data = get_config(container)
assert config_data["accesslog"] is None
uvicorn_cmd = get_process_names(container, name="uvicorn")[0]
assert "--no-access-log" in uvicorn_cmd


def test_env_vars_2() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
IMAGE_NAME = "uvicorn-gunicorn-testimage"


def get_process_names(container: Container) -> List[str]:
def get_process_names(container: Container, name: str = "gunicorn") -> List[str]:
top = container.top()
process_commands = [p[7] for p in top["Processes"]]
gunicorn_processes = [p for p in process_commands if "gunicorn" in p]
return gunicorn_processes
processes = [p for p in process_commands if name in p]
return processes


def get_gunicorn_conf_path(container: Container) -> str:
Expand Down

0 comments on commit 2fc3255

Please sign in to comment.