Skip to content

Commit b391051

Browse files
committed
tmp
1 parent ccd763e commit b391051

File tree

4 files changed

+133
-64
lines changed

4 files changed

+133
-64
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
FROM bids/base_validator
22

33
# Update system
4-
RUN apt-get -qq update && apt-get -qq install -y \
5-
unzip \
6-
xorg \
7-
wget && \
4+
RUN apt-get -qq update -qq && \
5+
apt-get -qq install -qq -y --no-install-recommends \
6+
unzip \
7+
xorg \
8+
wget && \
9+
apt-get clean && \
810
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
911

1012
# Install MATLAB MCR
11-
ENV MATLAB_VERSION %%MATLAB_VERSION%%
13+
ENV MATLAB_VERSION {{ MATLAB_VERSION }}
1214
RUN mkdir /opt/mcr_install && \
1315
mkdir /opt/mcr && \
14-
wget --quiet -P /opt/mcr_install %%MCR_LINK%% && \
16+
wget --quiet -P /opt/mcr_install {{ MCR_LINK }} && \
1517
unzip -q /opt/mcr_install/*${MATLAB_VERSION}*.zip -d /opt/mcr_install && \
1618
cd /opt/mcr_install && mkdir save && \
19+
{{#core_only}}
1720
for f in $(grep -E '(xml|enc)$' productdata/1000.txt) ; do cp --parents archives/$f save/ ; done && \
1821
for f in $(grep -E '(xml|enc)$' productdata/35000.txt) ; do cp --parents archives/$f save/ ; done && \
1922
for f in $(grep -E '(xml|enc)$' productdata/35010.txt) ; do cp --parents archives/$f save/ ; done && \
2023
rm -rf archives && mv save/archives . && rmdir save && \
24+
{{/core_only}}
2125
/opt/mcr_install/install -destinationFolder /opt/mcr -agreeToLicense yes -mode silent && \
22-
rm -rf /opt/mcr_install /tmp/* && \
26+
{{#core_only}}
2327
rm -rf /opt/mcr/*/cefclient && \
2428
rm -rf /opt/mcr/*/mcr/toolbox/matlab/maps && \
2529
rm -rf /opt/mcr/*/java/jarext && \
@@ -34,9 +38,11 @@ RUN mkdir /opt/mcr_install && \
3438
rm -rf /opt/mcr/*/bin/glnxa64/libQt* && \
3539
rm -rf /opt/mcr/*/bin/glnxa64/qtwebengine && \
3640
rm -rf /opt/mcr/*/bin/glnxa64/cef_resources
41+
{{/core_only}}
42+
rm -rf /opt/mcr_install /tmp/*
3743

3844
# Configure environment
39-
ENV MCR_VERSION %%MCR_VERSION%%
45+
ENV MCR_VERSION {{ MCR_VERSION }}
4046
ENV LD_LIBRARY_PATH /opt/mcr/${MCR_VERSION}/runtime/glnxa64:/opt/mcr/${MCR_VERSION}/bin/glnxa64:/opt/mcr/${MCR_VERSION}/sys/os/glnxa64:/opt/mcr/${MCR_VERSION}/sys/opengl/lib/glnxa64
4147
ENV MCR_INHIBIT_CTF_LOCK 1
4248
ENV MCR_HOME /opt/mcr/${MCR_VERSION}

Dockerfile-full.template renamed to Dockerfile-full.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ RUN apt-get -qq update -qq && \
1010
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
1111

1212
# Install MATLAB MCR
13-
ENV MATLAB_VERSION %%MATLAB_VERSION%%
13+
ENV MATLAB_VERSION {{ MATLAB_VERSION }}
1414
RUN mkdir /opt/mcr_install && \
1515
mkdir /opt/mcr && \
16-
wget --quiet -P /opt/mcr_install %%MCR_LINK%% && \
17-
unzip -q /opt/mcr_install/*.zip -d /opt/mcr_install && \
16+
wget --quiet -P /opt/mcr_install {{ MCR_LINK }} && \
17+
unzip -q /opt/mcr_install/*${MATLAB_VERSION}*.zip -d /opt/mcr_install && \
1818
/opt/mcr_install/install -destinationFolder /opt/mcr -agreeToLicense yes -mode silent && \
1919
rm -rf /opt/mcr_install /tmp/*
2020

2121
# Configure environment
22-
ENV MCR_VERSION %%MCR_VERSION%%
22+
ENV MCR_VERSION {{ MCR_VERSION }}
2323
ENV LD_LIBRARY_PATH /opt/mcr/${MCR_VERSION}/runtime/glnxa64:/opt/mcr/${MCR_VERSION}/bin/glnxa64:/opt/mcr/${MCR_VERSION}/sys/os/glnxa64:/opt/mcr/${MCR_VERSION}/sys/opengl/lib/glnxa64
2424
ENV MCR_INHIBIT_CTF_LOCK 1
2525

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rich
2+
beautifulsoup4
3+
packaging
4+
chevron

update.py

Lines changed: 111 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,91 +23,150 @@
2323
2424
Update.py should be run often enough to catch individual Matlab release updates.
2525
"""
26+
import pathlib
2627
import re
2728
from subprocess import DEVNULL
2829
from subprocess import run
2930
from urllib import request
3031

32+
import chevron
3133
from bs4 import BeautifulSoup
3234
from packaging import version
35+
from rich import print
36+
3337

3438
REL_URL = "https://www.mathworks.com/products/compiler/matlab-runtime.html"
3539
VER_LIMIT = "9.3" # release URLs get weird before that..
40+
DRY_RUN = True
41+
42+
variants = [("Dockerfile-full.mustache", ""), ("Dockerfile-core.mustache", "-core")]
3643

3744

3845
def call(cmd, split=True):
3946
if split:
4047
cmd = cmd.split()
48+
print(f"[green]{' '.join(cmd)}[/green]")
49+
if DRY_RUN:
50+
return True
4151
process = run(cmd, stdout=DEVNULL, stderr=DEVNULL)
4252
return process.returncode == 0
4353

4454

45-
with request.urlopen(REL_URL) as res:
46-
if res.status != 200:
47-
raise RuntimeError("Could not open matlab release URL")
48-
html = res.read()
49-
50-
soup = BeautifulSoup(html, "html.parser")
51-
ver_re = re.compile(r"(R2\d{3}.) \((\d\.\d)\)")
52-
rel_re = re.compile(r"Release/(\d+)/")
53-
54-
dockers = []
55-
for row in soup.find_all("table")[0].find_all("tr"):
56-
tds = row.find_all("td")
57-
if len(tds) >= 4:
58-
name = tds[0].text
59-
match = ver_re.match(name)
60-
if not match:
61-
continue
62-
mcr_name, mcr_ver = match.groups()
63-
if version.parse(mcr_ver) <= version.parse(VER_LIMIT):
64-
continue
65-
try:
66-
link = tds[2].a.get("href")
67-
except (KeyError, ValueError):
68-
raise RuntimeError("Error parsing matlab release page")
69-
if "glnxa64" not in link:
70-
raise RuntimeError("Error parsing matlab release page link")
71-
if match := rel_re.search(link):
72-
mcr_ver = f"{mcr_ver}.{match.groups()[0]}"
73-
dockers.append((mcr_name, mcr_ver, link))
55+
def add_dockerfile_to_branch(new_tags, docker):
7456

75-
76-
variants = [("Dockerfile-full.template", ""), ("Dockerfile-core.template", "-core")]
77-
new_tags = []
78-
79-
for docker in dockers:
8057
mcr_name, mcr_ver, link = docker
58+
8159
if len(mcr_ver.split(".")) == 2:
8260
mcr_ver = f"{mcr_ver}.0"
8361
mcr_ver_maj = ".".join(mcr_ver.split(".")[:2])
8462
mcr_ver_dir = f'v{mcr_ver_maj.replace(".", "")}'
63+
64+
print(f"\n[blue]{mcr_name}[/blue]")
65+
8566
if not call(f"git checkout {mcr_name}"):
8667
call(f"git checkout -b {mcr_name}")
68+
8769
for (template, suffix) in variants:
70+
8871
tag = f"{mcr_ver}{suffix}"
89-
if call(f"git rev-parse --verify {tag}"):
90-
print(f"Skipping {mcr_name}/{tag}, already present")
72+
73+
if not DRY_RUN and call(f"git rev-parse --verify {tag}"):
74+
print(f"[red]Skipping {mcr_name}-{tag}, already present[/red]")
9175
continue
92-
print(f"Adding {mcr_name}/{tag}")
76+
print(f"\n[blue]Adding {mcr_name}-{tag}[/blue]")
77+
9378
if not call("git merge master"):
9479
raise RuntimeError("Merging master failed, will not continue")
95-
with open(template) as f:
96-
lines = f.read()
97-
lines = lines.replace("%%MATLAB_VERSION%%", mcr_name)
98-
lines = lines.replace("%%MCR_VERSION%%", mcr_ver_dir)
99-
lines = lines.replace("%%MCR_LINK%%", link)
80+
81+
lines = pathlib.Path(template).read_text()
82+
lines = lines.replace("%%MATLAB_VERSION%%", mcr_name)
83+
lines = lines.replace("%%MCR_VERSION%%", mcr_ver_dir)
84+
lines = lines.replace("%%MCR_LINK%%", link)
85+
if not DRY_RUN:
10086
with open("Dockerfile", "w+") as f2:
10187
f2.write(lines)
102-
call("git add Dockerfile")
103-
# Tag X.Y.Z[-variant] - see circle CI for shared tag X.Y[-variant]
104-
call(["git", "commit", "-m", "Auto-Update"], split=False)
105-
call(f"git tag {tag}")
106-
new_tags.append(tag)
88+
89+
with open(template) as f:
90+
content = chevron.render(
91+
f,
92+
{
93+
"MATLAB_VERSION": mcr_name,
94+
"MCR_VERSION": mcr_ver_dir,
95+
"MCR_LINK": link,
96+
},
97+
)
98+
with open("Dockerfile", "w+") as f2:
99+
f2.write(content)
100+
101+
call("git add Dockerfile")
102+
# Tag X.Y.Z[-variant] - see circle CI for shared tag X.Y[-variant]
103+
call(["git", "commit", "-m", "Auto-Update"], split=False)
104+
105+
call(f"git tag {tag}")
106+
107+
new_tags.append(tag)
108+
107109
call("git checkout master")
108110

109-
if new_tags:
110-
print("New tags have been added, verify and update to git with:")
111-
print("git push --all")
112-
for tag in reversed(new_tags):
113-
print(f"git push origin {tag}")
111+
return new_tags
112+
113+
114+
def list_mcr(soup):
115+
116+
ver_re = re.compile(r"(R2\d{3}.) \((\d\.\d+)\)")
117+
rel_re = re.compile(r"Release/(\d+)/")
118+
119+
dockers = []
120+
for row in soup.find_all("table")[0].find_all("tr"):
121+
122+
tds = row.find_all("td")
123+
124+
if len(tds) >= 4:
125+
name = tds[0].text
126+
match = ver_re.match(name)
127+
if not match:
128+
continue
129+
mcr_name, mcr_ver = match.groups()
130+
131+
if version.parse(mcr_ver) <= version.parse(VER_LIMIT):
132+
continue
133+
try:
134+
link = tds[2].a.get("href")
135+
except (KeyError, ValueError) as e:
136+
raise RuntimeError("Error parsing matlab release page") from e
137+
138+
if "glnxa64" not in link:
139+
raise RuntimeError("Error parsing matlab release page link")
140+
141+
if match := rel_re.search(link):
142+
mcr_ver = f"{mcr_ver}.{match.groups()[0]}"
143+
144+
dockers.append((mcr_name, mcr_ver, link))
145+
146+
return dockers
147+
148+
149+
def main():
150+
151+
with request.urlopen(REL_URL) as res:
152+
if res.status != 200:
153+
raise RuntimeError("Could not open matlab release URL")
154+
html = res.read()
155+
156+
soup = BeautifulSoup(html, "html.parser")
157+
158+
dockers = list_mcr(soup)
159+
160+
new_tags = []
161+
for docker in dockers:
162+
new_tags = add_dockerfile_to_branch(new_tags, docker)
163+
164+
if new_tags:
165+
print("\nNew tags have been added, verify and update to git with:")
166+
print("git push --all")
167+
for tag in reversed(new_tags):
168+
print(f"git push origin {tag}")
169+
170+
171+
if __name__ == "__main__":
172+
main()

0 commit comments

Comments
 (0)