Skip to content

Commit 4f888e2

Browse files
dalcinljoerick
andcommitted
feature: Automatically pass SOURCE_DATE_EPOCH to Linux containers
Co-authored-by: Joe Rickerby <[email protected]>
1 parent e5d0cc0 commit 4f888e2

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

cibuildwheel/oci_container.py

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def __enter__(self) -> OCIContainer:
115115
self.engine.name,
116116
"create",
117117
"--env=CIBUILDWHEEL",
118+
"--env=SOURCE_DATE_EPOCH",
118119
f"--name={self.name}",
119120
"--interactive",
120121
"--volume=/:/host", # ignored on CircleCI

docs/options.md

+3
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ A list of environment variables to pass into the linux container during the buil
664664

665665
To specify more than one environment variable, separate the variable names by spaces.
666666

667+
!!! note
668+
cibuildwheel automatically passes the environment variable [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/docs/source-date-epoch/) if defined.
669+
667670
#### Examples
668671

669672
!!! tab examples "Environment passthrough"

unit_test/oci_container_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ def test_environment(container_engine):
7272
)
7373

7474

75+
def test_environment_pass(container_engine, monkeypatch):
76+
monkeypatch.setenv("CIBUILDWHEEL", "1")
77+
monkeypatch.setenv("SOURCE_DATE_EPOCH", "1489957071")
78+
with OCIContainer(engine=container_engine, image=DEFAULT_IMAGE) as container:
79+
assert container.call(["sh", "-c", "echo $CIBUILDWHEEL"], capture_output=True) == "1\n"
80+
assert (
81+
container.call(["sh", "-c", "echo $SOURCE_DATE_EPOCH"], capture_output=True)
82+
== "1489957071\n"
83+
)
84+
85+
7586
def test_cwd(container_engine):
7687
with OCIContainer(
7788
engine=container_engine, image=DEFAULT_IMAGE, cwd="/cibuildwheel/working_directory"

0 commit comments

Comments
 (0)