Skip to content

Commit 598cc6a

Browse files
committed
tests: sample images files can run from a locally sourced file archive
1 parent ad21537 commit 598cc6a

File tree

2 files changed

+60
-26
lines changed

2 files changed

+60
-26
lines changed

ci/docker/linux/jenkins/Dockerfile

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ARG CONAN_USER_HOME=/conan
22

33
ARG CONAN_HOME=${CONAN_USER_HOME}/.conan2
44

5+
56
ARG CONAN_CENTER_PROXY_V2_URL=https://center2.conan.io
67
# If you want to use a diffrent remote for Conan, such as a proxy. Set the CONAN_CENTER_PROXY_V2_URL
78
# Not this is only for building the image. The actual conan center proxy URL is set in the remotes.json file.
@@ -12,6 +13,8 @@ ARG PIP_DOWNLOAD_CACHE=/.cache/pip
1213
ARG UV_CACHE_DIR=/.cache/uv
1314
# UV Cache directory. Change this only if you need to override the default location.
1415

16+
ARG SAMPLE_IMAGES_URL=https://nexus.library.illinois.edu/repository/sample-data/images/metadata_test_images.tar.gz
17+
1518
FROM ghcr.io/astral-sh/uv:latest AS uv_builder
1619

1720
FROM ubuntu:24.04 AS base_image
@@ -112,6 +115,21 @@ RUN --mount=type=cache,target=${PIP_DOWNLOAD_CACHE} \
112115

113116
# shared files are needed to run the Build C++ Tests stage
114117

118+
#==============================================================================
119+
120+
121+
FROM base_image AS sample_files_downloader
122+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
123+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
124+
apt-get update && \
125+
apt-get install -y --no-install-recommends wget
126+
127+
ARG SAMPLE_IMAGES_URL
128+
ENV EXPECTED_SHA256="eee5fa3641628c7365e14de3f58da069cb332dc13a4b739dc168a1617109ebbf"
129+
RUN mkdir /sampledata && wget $SAMPLE_IMAGES_URL -P /sampledata && echo "$EXPECTED_SHA256 /sampledata/metadata_test_images.tar.gz" | sha256sum --check
130+
131+
132+
115133
FROM base_image
116134
COPY --from=uv_builder /uv /uvx /bin/
117135
# -----------------------------------------------------------------------------
@@ -136,14 +154,15 @@ RUN ln -s /opt/drmemory/bin64/drmemory /usr/local/bin/drmemory && \
136154

137155
ARG PIP_EXTRA_INDEX_URL
138156

139-
ENV PIP_NO_CACHE_DIR=1
140-
141157
ARG CONAN_USER_HOME
142-
ENV CONAN_USER_HOME=${CONAN_USER_HOME}
143158
ARG CONAN_HOME
144-
ENV CONAN_HOME=${CONAN_HOME}
145159
COPY --from=conan_builder --chmod=777 ${CONAN_HOME} ${CONAN_HOME}
146-
ENV TZ=UTC
160+
COPY --from=sample_files_downloader /sampledata /sampledata
161+
ENV TZ=UTC \
162+
PIP_NO_CACHE_DIR=1 \
163+
CONAN_USER_HOME=${CONAN_USER_HOME} \
164+
SAMPLE_IMAGES_ARCHIVE=/sampledata/metadata_test_images.tar.gz \
165+
CONAN_HOME=${CONAN_HOME}
147166

148167
# To help mark the image as a CI image so it can be cleaned up more easily
149168
LABEL purpose=ci

tests/test_integration.py

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import shutil
23

34
import pytest
@@ -11,25 +12,20 @@
1112

1213
# TEST_PATH = os.path.join(os.path.dirname(__file__), "henrytestmetadata")
1314
SAMPLE_IMAGES = "https://nexus.library.illinois.edu/repository/sample-data/images/metadata_test_images.tar.gz"
15+
SAMPLE_IMAGES_SHA256 = "eee5fa3641628c7365e14de3f58da069cb332dc13a4b739dc168a1617109ebbf"
1416

17+
# To save time from redownloading the metadata_test_images.tar.gz file every time,
18+
# download it locally and set the environment variable SAMPLE_IMAGES_ARCHIVE
19+
# to the path of the downloaded file
1520

16-
def download_images(url, destination):
17-
with TemporaryDirectory() as download_path:
18-
print("Downloading {}".format(url), flush=True)
19-
urllib.request.urlretrieve(url,
20-
filename=os.path.join(download_path,
21-
"sample_images.tar.gz"))
22-
if not os.path.exists(
23-
os.path.join(download_path, "sample_images.tar.gz")):
24-
raise FileNotFoundError("sample images not download")
25-
print("Extracting images")
26-
with tarfile.open(os.path.join(download_path, "sample_images.tar.gz"),
27-
"r:gz") as archive_file:
28-
for item in archive_file.getmembers():
29-
print("Extracting {}".format(item.name))
30-
archive_file.extract(item, path=destination)
31-
pass
21+
def download_images(url, download_path):
3222

23+
print(f"Downloading {url}")
24+
output = os.path.join(download_path, "sample_images.tar.gz")
25+
urllib.request.urlretrieve(url, filename=output)
26+
if not os.path.exists(output):
27+
raise FileNotFoundError("sample images not download")
28+
return output
3329

3430
@pytest.fixture(scope="session")
3531
def sample_data():
@@ -40,14 +36,33 @@ def sample_data():
4036
if os.path.exists(sample_images_path):
4137
print("{} already exits".format(sample_images_path))
4238
else:
43-
print("Downloading sample images")
44-
if not os.path.exists(sample_images_path):
45-
download_images(
46-
url=SAMPLE_IMAGES,
47-
destination=test_path)
39+
archive = os.getenv('SAMPLE_IMAGES_ARCHIVE')
40+
if not archive:
41+
print("Downloading sample images")
42+
if not os.path.exists(sample_images_path):
43+
archive = download_images(
44+
url=SAMPLE_IMAGES,
45+
download_path=test_path
46+
)
47+
if not os.path.exists(archive):
48+
raise FileNotFoundError(f"sample image archive not found. {archive} does not exist.")
49+
verify_hash(archive, sha256_hash=SAMPLE_IMAGES_SHA256)
50+
extract_images(path=archive, destination=test_path)
4851
yield sample_images_path
4952
shutil.rmtree(sample_images_path)
5053

54+
def extract_images(path, destination):
55+
print("Extracting images")
56+
with tarfile.open(path, "r:gz") as archive_file:
57+
for item in archive_file.getmembers():
58+
print("Extracting {}".format(item.name))
59+
archive_file.extract(item, path=destination)
60+
61+
def verify_hash(path, sha256_hash):
62+
with open(path, "rb") as f:
63+
file_hash = hashlib.sha256(f.read()).hexdigest()
64+
assert file_hash == sha256_hash
65+
5166

5267
@pytest.mark.integration
5368
@pytest.mark.parametrize("test_file,profile_name", [

0 commit comments

Comments
 (0)