Skip to content

Commit 6992c1a

Browse files
committed
try a container for e3sm-diags
1 parent 7506d65 commit 6992c1a

File tree

4 files changed

+181
-0
lines changed

4 files changed

+181
-0
lines changed

.github/workflows/e3sm-diags.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: e3sm-diags
2+
3+
on:
4+
merge_group:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
paths:
9+
- 'e3sm-diags/**'
10+
- '.github/workflows/e3sm-diags.yaml'
11+
push:
12+
branches: [ main ]
13+
paths:
14+
- 'e3sm-diags/**'
15+
- '.github/workflows/e3sm-diags.yaml'
16+
tags:
17+
- 'e3sm-diags-*'
18+
19+
jobs:
20+
ocis:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
id-token: write
26+
strategy:
27+
fail-fast: false
28+
29+
steps:
30+
-
31+
name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
submodules: recursive
35+
show-progress: false
36+
persist-credentials: false
37+
-
38+
name: GHCR
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
-
45+
name: Meta
46+
id: meta
47+
uses: docker/metadata-action@v5
48+
with:
49+
images: |
50+
ghcr.io/${{ github.repository }}-e3sm-diags
51+
-
52+
name: QEMU
53+
uses: docker/setup-qemu-action@v3
54+
-
55+
name: Buildx
56+
uses: docker/setup-buildx-action@v3
57+
-
58+
name: Push
59+
uses: docker/build-push-action@v6
60+
with:
61+
context: e3sm-diags/
62+
file: e3sm-diags/Dockerfile
63+
push: ${{ github.event_name != 'pull_request' }}
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}

e3sm-diags/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python
2+
3+
RUN mkdir -p /e3sm_diags_downloaded_data/tests/integration
4+
5+
COPY download_files.py /app/download_files.py
6+
RUN chmod +x /app/download_files.py
7+
RUN /app/download_files.py
8+
9+
ENTRYPOINT ["/bin/bash", "--rcfile", "/etc/profile", "-l"]

e3sm-diags/download_files.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import re
5+
import urllib.request
6+
from typing import List
7+
8+
TEST_ROOT_PATH = "/e3sm_diags_downloaded_data/tests/integration/"
9+
TEST_DATA_DIR = "integration_test_data"
10+
TEST_IMAGES_DIR = "integration_test_images"
11+
12+
13+
# https://stackoverflow.com/questions/49113616/how-to-download-file-using-python
14+
def retrieve_file(url, file_path):
15+
dir_path = os.path.join(*os.path.split(file_path)[:-1])
16+
# https://stackoverflow.com/questions/12517451/automatically-creating-directories-with-file-output
17+
if dir_path:
18+
os.makedirs(dir_path, exist_ok=True)
19+
print("Downloading {} to {}".format(url, file_path))
20+
urllib.request.urlretrieve(url, file_path)
21+
return file_path
22+
23+
24+
def download_files(url_prefix, url_suffix, directory_prefix=None):
25+
print(f"Downloading {url_suffix}")
26+
print("url_prefix={}".format(url_prefix))
27+
print("url_suffix={}".format(url_suffix))
28+
print("(local) directory_prefix={}".format(directory_prefix))
29+
30+
url = os.path.join(url_prefix, url_suffix)
31+
32+
if directory_prefix:
33+
links_file_path = os.path.join(directory_prefix, url_suffix)
34+
else:
35+
links_file_path = url_suffix
36+
37+
links_file_path = "{}.html".format(links_file_path)
38+
print(
39+
"Downloading files from {}; checking for links on {}".format(
40+
url, links_file_path
41+
)
42+
)
43+
html_path = retrieve_file(url, links_file_path)
44+
links: List[str] = []
45+
46+
with open(html_path, "r") as html:
47+
for line in html:
48+
match_object = re.search(r'href=[\'"]?([^\'" >]+)', line)
49+
if match_object:
50+
link = match_object.group(1)
51+
# Ignore parent directory and sorting links
52+
if (
53+
("../" not in link)
54+
and (not link.startswith("/"))
55+
and ("?" not in link)
56+
):
57+
print("Found a link: {}".format(link))
58+
links.append(link)
59+
60+
if os.path.exists(links_file_path):
61+
os.remove(links_file_path)
62+
63+
files = []
64+
directories = []
65+
66+
for link in links:
67+
if link.endswith("/"):
68+
# List directories to download.
69+
directories.append(link)
70+
else:
71+
# List '.csv', '.mat', '.nc', and '.png' files to download.
72+
files.append(link)
73+
74+
print("\n###Downloading files")
75+
76+
if directory_prefix:
77+
new_directory_prefix = os.path.join(directory_prefix, url_suffix)
78+
else:
79+
new_directory_prefix = url_suffix
80+
for f in files:
81+
url_to_download = os.path.join(url, f)
82+
file_path = os.path.join(new_directory_prefix, f)
83+
retrieve_file(url_to_download, file_path)
84+
85+
print("\n###Downloading directories")
86+
for d in directories:
87+
new_directory = d.rstrip("/")
88+
download_files(url, new_directory, directory_prefix=new_directory_prefix)
89+
90+
91+
def download():
92+
download_files(
93+
"https://web.lcrc.anl.gov/public/e3sm/e3sm_diags_test_data/integration",
94+
TEST_DATA_DIR,
95+
directory_prefix=TEST_ROOT_PATH,
96+
)
97+
download_files(
98+
"https://web.lcrc.anl.gov/public/e3sm/e3sm_diags_test_data/integration/expected",
99+
TEST_IMAGES_DIR,
100+
directory_prefix=TEST_ROOT_PATH,
101+
)
102+
print(f"Downloaded {TEST_DATA_DIR} and {TEST_ROOT_PATH}")
103+
104+
105+
if __name__ == "__main__":
106+
download()

e3sm-diags/readme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A container housing test data for e3sm_diags

0 commit comments

Comments
 (0)