Skip to content

Commit 73f504b

Browse files
committed
add wsgi var
1 parent 8a6e4d1 commit 73f504b

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ ENV BASE_URL="api.opencitations.net" \
77
LOG_DIR="/mnt/log_dir/oc_api" \
88
SPARQL_ENDPOINT_INDEX="http://qlever-service.default.svc.cluster.local:7011" \
99
SPARQL_ENDPOINT_META="http://virtuoso-service.default.svc.cluster.local:8890/sparql" \
10-
SYNC_ENABLED="true"
10+
SYNC_ENABLED="true"
11+
12+
# Specify that we are using gunicorn as the WSGI server (mandatory)
13+
# Do not change this value unless you modify api_oc.py accordingly
14+
ENV WSGI_SERVER="gunicorn"
1115

1216
# Install system dependencies required for Python package compilation
1317
RUN apt-get update && \
@@ -24,10 +28,6 @@ COPY . .
2428

2529
# Install Python dependencies from requirements.txt
2630
RUN pip install -r requirements.txt
27-
# Check if synchronization is enabled annd updatge requirements if needed
28-
RUN if [ "$SYNC_ENABLED" = "true" ]; then \
29-
python3 sync_static.py --auto ; \
30-
fi
3131

3232
# Expose the port that our service will listen on
3333
EXPOSE 8080

api_oc.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ def sync_static_files():
124124
except Exception as e:
125125
print(f"Unexpected error during synchronization: {e}")
126126

127+
def initialize_application():
128+
"""
129+
Initialize application: print configuration and sync static files if enabled.
130+
This runs both when started with gunicorn and when run directly with python.
131+
"""
132+
print("=" * 60)
133+
print("Starting API OpenCitations web application...")
134+
print("=" * 60)
135+
print(f"Configuration: Base URL={env_config['base_url']}")
136+
print(f"Sync enabled: {env_config['sync_enabled']}")
137+
print(f"Redis enabled: {env_config['redis']['enabled']}")
138+
print(f"Redis host: {env_config['redis']['host']}")
139+
print(f"SPARQL Index endpoint: {env_config['sparql_endpoint_index']}")
140+
print(f"SPARQL Meta endpoint: {env_config['sparql_endpoint_meta']}")
141+
print("=" * 60)
142+
143+
# Sync static files if enabled
144+
if env_config["sync_enabled"]:
145+
print("Static sync is enabled (SYNC_ENABLED=true)")
146+
sync_static_files()
147+
else:
148+
print("Static sync is disabled")
149+
127150
def validateAccessToken():
128151
if not env_config["redis"]["enabled"]:
129152
# If Redis is not enabled, skip token validation
@@ -413,8 +436,12 @@ def GET(self, dataset, call):
413436
"404 ", {"Content-Type": content_type}, "No API operation found at URL '%s'" % call)
414437

415438

439+
if os.getenv("WSGI_SERVER") == "gunicorn":
440+
print("Detected gunicorn environment (WSGI_SERVER=gunicorn)")
441+
initialize_application()
442+
416443

417-
# Run the application
444+
# Run the application on localhost for testing/development
418445
if __name__ == "__main__":
419446
# Add startup log
420447
print("Starting API OpenCitations web application...")

docker_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.0sync-test3
1+
1.4.1sync-test4

0 commit comments

Comments
 (0)