Skip to content

Commit 1316d5f

Browse files
authored
Docker: Add missing package to Python venv (#2917)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 47e0d21 commit 1316d5f

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Base/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ RUN apt-get -qqy update \
7777
&& apt-get upgrade -yq \
7878
&& apt-get -qqy --no-install-recommends install \
7979
python3 python3-pip python3-venv \
80-
&& python3 -m pip install --upgrade setuptools virtualenv requests --break-system-packages \
80+
&& python3 -m pip install --upgrade setuptools virtualenv --break-system-packages \
8181
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
8282
&& echo "source $VENV_PATH/bin/activate" >> /etc/bash.bashrc
8383

@@ -187,7 +187,7 @@ RUN ARCH=$(if [ "$(dpkg --print-architecture)" = "amd64" ]; then echo "x86_64";
187187
USER ${SEL_UID}:${SEL_GID}
188188

189189
RUN python3 -m venv $VENV_PATH \
190-
&& $VENV_PATH/bin/python3 -m pip install --upgrade pip setuptools virtualenv psutil \
190+
&& $VENV_PATH/bin/python3 -m pip install --upgrade pip setuptools virtualenv psutil requests \
191191
&& wget -q https://github.com/Supervisor/supervisor/archive/refs/heads/main.zip -O /tmp/supervisor.zip \
192192
&& unzip /tmp/supervisor.zip -d /tmp \
193193
&& cd /tmp/supervisor-main \

Video/validate_endpoint.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import sys
44
import os
55
import base64
6-
import json
76
from datetime import datetime
87
from datetime import timezone
9-
from urllib.parse import urlparse
108
import requests
11-
from requests.adapters import HTTPAdapter
129

1310

1411
def get_timestamp():
@@ -49,14 +46,15 @@ def get_basic_auth():
4946
return {}
5047

5148

52-
def validate_endpoint(endpoint, graphql_endpoint=False, max_time=1):
49+
def validate_endpoint(endpoint, graphql_endpoint=False, connection_timeout=5, read_timeout=5):
5350
"""
5451
Validate an endpoint by making HTTP request and checking status code.
5552
5653
Args:
5754
endpoint (str): The endpoint URL to validate
5855
graphql_endpoint (bool): Whether this is a GraphQL endpoint
59-
max_time (int): Maximum time for request in seconds
56+
connection_timeout (int): Connection timeout in seconds
57+
read_timeout (int): Read timeout in seconds
6058
"""
6159
process_name = "endpoint.checks"
6260
session = create_session()
@@ -75,22 +73,23 @@ def validate_endpoint(endpoint, graphql_endpoint=False, max_time=1):
7573
endpoint,
7674
headers=headers,
7775
json=data,
78-
timeout=max_time,
76+
timeout=(connection_timeout, read_timeout),
7977
verify=False # Equivalent to curl's -k flag
8078
)
8179
else:
8280
# Regular endpoint check
8381
response = session.get(
8482
endpoint,
8583
headers=headers,
86-
timeout=max_time,
84+
timeout=(connection_timeout, read_timeout),
8785
verify=False # Equivalent to curl's -k flag
8886
)
8987

9088
status_code = response.status_code
9189

9290
except requests.exceptions.Timeout:
93-
print(f"{get_timestamp()} [{process_name}] - Endpoint {endpoint} timed out after {max_time} seconds")
91+
print(
92+
f"{get_timestamp()} [{process_name}] - Endpoint {endpoint} timed out (connection: {connection_timeout}s, read: {read_timeout}s)")
9493
return False
9594
except requests.exceptions.ConnectionError:
9695
print(f"{get_timestamp()} [{process_name}] - Failed to connect to endpoint {endpoint}")
@@ -104,12 +103,14 @@ def validate_endpoint(endpoint, graphql_endpoint=False, max_time=1):
104103
print(f"{get_timestamp()} [{process_name}] - Endpoint {endpoint} is not found - status code: {status_code}")
105104
return False
106105
elif status_code == 401:
107-
print(f"{get_timestamp()} [{process_name}] - Endpoint {endpoint} requires authentication - status code: {status_code}. Please provide valid credentials via SE_ROUTER_USERNAME and SE_ROUTER_PASSWORD environment variables.")
106+
print(
107+
f"{get_timestamp()} [{process_name}] - Endpoint {endpoint} requires authentication - status code: {status_code}. Please provide valid credentials via SE_ROUTER_USERNAME and SE_ROUTER_PASSWORD environment variables.")
108108
return False
109109
elif status_code != 200:
110110
print(f"{get_timestamp()} [{process_name}] - Endpoint {endpoint} is not available - status code: {status_code}")
111111
return False
112112

113+
print(f"{get_timestamp()} [{process_name}] - Endpoint {endpoint} is reachable - status code: {status_code}")
113114
return True
114115

115116

@@ -123,10 +124,10 @@ def main():
123124

124125
endpoint = sys.argv[1]
125126
graphql_endpoint = len(sys.argv) > 2 and sys.argv[2].lower() == 'true'
126-
max_time = int(os.environ.get('SE_ENDPOINT_CHECK_TIMEOUT', 1))
127+
max_time = int(os.environ.get('SE_ENDPOINT_CHECK_TIMEOUT', 5))
127128

128129
# Validate the endpoint
129-
success = validate_endpoint(endpoint, graphql_endpoint, max_time)
130+
success = validate_endpoint(endpoint, graphql_endpoint, max_time, max_time)
130131

131132
# Exit with appropriate code
132133
sys.exit(0 if success else 1)

0 commit comments

Comments
 (0)