-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_e2e_python_lambda.py
More file actions
64 lines (52 loc) · 2.09 KB
/
Copy pathtest_e2e_python_lambda.py
File metadata and controls
64 lines (52 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""End-to-end: real docker build of a trivial Python lambda, twice, sha-compare."""
import hashlib
import shutil
import subprocess
from pathlib import Path
import pytest
from repro_lambda.docker_runner import build_python_lambda
from repro_lambda.manifest import BuilderConfig
from repro_lambda.source_stager import stage_source
def _sha256(path: Path) -> str:
h = hashlib.sha256()
with path.open("rb") as f:
for chunk in iter(lambda: f.read(64 * 1024), b""):
h.update(chunk)
return h.hexdigest()
@pytest.mark.docker
def test_two_independent_builds_produce_byte_identical_zips(tmp_path: Path):
if shutil.which("docker") is None:
pytest.skip("docker not available")
repo = tmp_path / "repo"
repo.mkdir()
subprocess.run(["git", "init", "-q"], cwd=repo, check=True)
subprocess.run(["git", "config", "user.email", "t@t"], cwd=repo, check=True)
subprocess.run(["git", "config", "user.name", "t"], cwd=repo, check=True)
h = repo / "handler"
h.mkdir()
(h / "app.py").write_text(
"def lambda_handler(event, context):\n return {'statusCode': 200, 'body': 'ok'}\n"
)
(h / "requirements.arm64.lock").write_text("")
subprocess.run(["git", "add", "."], cwd=repo, check=True)
subprocess.run(["git", "commit", "-q", "-m", "init"], cwd=repo, check=True)
builder = BuilderConfig(
base_image_python="public.ecr.aws/lambda/python:3.13",
include_patterns=["**/*.py"],
exclude_patterns=["__pycache__/**", "*.pyc"],
)
shas: list[str] = []
for run_index in range(2):
stage = tmp_path / f"stage{run_index}"
stage_source(repo, "handler", builder, stage)
(stage / "requirements.lock").write_bytes((h / "requirements.arm64.lock").read_bytes())
out = stage / "lambda.zip"
build_python_lambda(
stage_dir=stage,
out_zip=out,
base_image=builder.base_image_python,
arch="arm64",
python_version="3.13",
)
shas.append(_sha256(out))
assert shas[0] == shas[1], f"non-reproducible: {shas[0]} vs {shas[1]}"