predeploy-runner-abhishek 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv/
11
+
12
+ # Environment variables
13
+ .env
14
+ .env*.local
15
+
16
+ # Cache and coverage directories
17
+ .mypy_cache/
18
+ .pytest_cache/
19
+ .coverage
20
+ htmlcov/
21
+
22
+ # Frontend builds and node_modules
23
+ frontend/node_modules/
24
+ frontend/.next/
25
+
26
+ # Temporary secret files
27
+ *-secrets.json
28
+ *.secret.json
29
+
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.5
2
+ Name: predeploy-runner-abhishek
3
+ Version: 0.1.0
4
+ Summary: A lightweight, reusable pre-deployment gate runner for Python services
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+
8
+ # Pre-Deployment Runner
9
+
10
+ A lightweight, reusable pre-deployment gate runner for Python services.
11
+
12
+ ## Overview
13
+
14
+ Validates environment variables and health status before starting critical services.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ uv add predeploy-runner-abhishek
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Set `PREDEPLOY_REQUIRED_VARS` as a comma-separated list:
25
+
26
+ ```bash
27
+ export PREDEPLOY_REQUIRED_VARS="DATABASE_URL,REDIS_URL,API_PORT"
28
+ pre-deploy-runner
29
+ ```
@@ -0,0 +1,22 @@
1
+ # Pre-Deployment Runner
2
+
3
+ A lightweight, reusable pre-deployment gate runner for Python services.
4
+
5
+ ## Overview
6
+
7
+ Validates environment variables and health status before starting critical services.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ uv add predeploy-runner-abhishek
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Set `PREDEPLOY_REQUIRED_VARS` as a comma-separated list:
18
+
19
+ ```bash
20
+ export PREDEPLOY_REQUIRED_VARS="DATABASE_URL,REDIS_URL,API_PORT"
21
+ pre-deploy-runner
22
+ ```
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "predeploy-runner-abhishek"
7
+ version = "0.1.0"
8
+ description = "A lightweight, reusable pre-deployment gate runner for Python services"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = []
12
+
13
+ [project.scripts]
14
+ pre-deploy-runner = "predeploy_runner.runner:main"
15
+
16
+ [tool.hatch.build.targets.wheel]
17
+ packages = ["src/predeploy_runner"]
18
+
19
+ [dependency-groups]
20
+ dev = [
21
+ "pytest>=8.0.0",
22
+ ]
@@ -0,0 +1,7 @@
1
+ """
2
+ predeploy_runner package
3
+ """
4
+ from predeploy_runner.runner import verify_environment, check_tcp_service
5
+
6
+ __all__ = ["verify_environment", "check_tcp_service"]
7
+ __version__ = "0.1.0"
@@ -0,0 +1,88 @@
1
+ """
2
+ Simple, reusable pre-deployment gate runner tailored for Day 4 Film Review Platform.
3
+ Performs:
4
+ 1. Environment variables check
5
+ 2. TCP connectivity check (Database, Redis, etc.)
6
+ """
7
+ import os
8
+ import sys
9
+ import socket
10
+ from typing import List, Tuple
11
+ from urllib.parse import urlparse
12
+
13
+ # Default required environment variables for Day 4 Film Review Platform
14
+ DEFAULT_REQUIRED_VARS = [
15
+ "TOKEN_ACCESS_TOKEN_EXPIRE_MINUTES",
16
+ "TOKEN_REFRESH_TOKEN_EXPIRE_DAYS",
17
+ "API_VERSION",
18
+ "REDIS_URL",
19
+ "AWS_SECRET_ID",
20
+ "AWS_SECRETS_ENDPOINT_URL",
21
+ ]
22
+
23
+
24
+ def verify_environment(required_vars: List[str]) -> Tuple[bool, List[str]]:
25
+ """Check that all required environment variables are set and non-empty."""
26
+ missing = [var for var in required_vars if not os.getenv(var)]
27
+ return len(missing) == 0, missing
28
+
29
+
30
+ def check_tcp_service(host: str, port: int, timeout: float = 3.0) -> bool:
31
+ """Verify TCP connectivity to a host and port."""
32
+ try:
33
+ with socket.create_connection((host, port), timeout=timeout):
34
+ return True
35
+ except OSError:
36
+ return False
37
+
38
+
39
+ def check_url_connectivity(url: str, default_port: int = 80, timeout: float = 3.0) -> bool:
40
+ """Extract host and port from URL and verify TCP reachability."""
41
+ if not url:
42
+ return False
43
+ parsed = urlparse(url)
44
+ host = parsed.hostname or "localhost"
45
+ port = parsed.port or default_port
46
+ return check_tcp_service(host, port, timeout=timeout)
47
+
48
+
49
+ def main() -> None:
50
+ """CLI Entrypoint for pre-deploy gate checks."""
51
+ print("==========================================================")
52
+ print("==> [Pre-Deployment Gate] Step 1: Environment Variables")
53
+ print("==========================================================")
54
+
55
+ # Allow custom comma-separated list, or use Day 4 defaults
56
+ custom_vars = os.getenv("PREDEPLOY_REQUIRED_VARS")
57
+ if custom_vars:
58
+ vars_to_check = [v.strip() for v in custom_vars.split(",") if v.strip()]
59
+ else:
60
+ vars_to_check = DEFAULT_REQUIRED_VARS
61
+
62
+ ok, missing = verify_environment(vars_to_check)
63
+ if not ok:
64
+ print(f"[FATAL] Pre-deployment checks failed! Missing variables: {', '.join(missing)}", file=sys.stderr)
65
+ print("Refusing to start application in an unconfigured state.", file=sys.stderr)
66
+ sys.exit(1)
67
+
68
+ print(f"[SUCCESS] All {len(vars_to_check)} required environment variables are present.")
69
+
70
+ # Step 2: Check Redis URL reachability if specified
71
+ redis_url = os.getenv("REDIS_URL")
72
+ if redis_url:
73
+ print("==========================================================")
74
+ print("==> [Pre-Deployment Gate] Step 2: Redis Service Reachability")
75
+ print("==========================================================")
76
+ # If reachable or skipped in test mode
77
+ if check_url_connectivity(redis_url, default_port=6379, timeout=2.0):
78
+ print("[SUCCESS] Redis service connection verified.")
79
+ else:
80
+ print(f"[WARNING] Could not connect to Redis at {redis_url} (ignoring if mock/local).")
81
+
82
+ print("==========================================================")
83
+ print("==> [Pre-Deployment Gate] All pre-deployment checks passed!")
84
+ print("==========================================================")
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main()
@@ -0,0 +1,30 @@
1
+ from predeploy_runner.runner import (
2
+ verify_environment,
3
+ check_tcp_service,
4
+ check_url_connectivity,
5
+ DEFAULT_REQUIRED_VARS,
6
+ )
7
+
8
+
9
+ def test_verify_environment_success(monkeypatch):
10
+ for var in DEFAULT_REQUIRED_VARS:
11
+ monkeypatch.setenv(var, "dummy_value")
12
+
13
+ ok, missing = verify_environment(DEFAULT_REQUIRED_VARS)
14
+ assert ok is True
15
+ assert missing == []
16
+
17
+
18
+ def test_verify_environment_failure(monkeypatch):
19
+ # Unset one mandatory variable
20
+ for var in DEFAULT_REQUIRED_VARS:
21
+ monkeypatch.setenv(var, "dummy_value")
22
+ monkeypatch.delenv("REDIS_URL", raising=False)
23
+
24
+ ok, missing = verify_environment(DEFAULT_REQUIRED_VARS)
25
+ assert ok is False
26
+ assert "REDIS_URL" in missing
27
+
28
+
29
+ def test_check_url_connectivity_invalid():
30
+ assert check_url_connectivity("") is False