Skip to content

Commit 45b10df

Browse files
committed
reduce image size by using smaller base image
1 parent ac2d4e7 commit 45b10df

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

gitbug-java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class GitBugJavaCli(object):
2626
def __init__(self, verbose: bool = False):
2727
self.__init_logging(verbose)
2828
self.__projects = {}
29+
self.__gitbugactions_base_image = "ghcr.io/catthehacker/ubuntu:runner-latest"
30+
self.__gitbugjava_base_image = "gitbug-java:base-act-latest"
2931

3032
# Load the GitBug-Java dataset
3133
for project_file in Path(get_project_root(), "data", "bugs").glob("*.json"):
@@ -45,27 +47,27 @@ class GitBugJavaCli(object):
4547
logging.basicConfig(format="[%(asctime)s] %(message)s", level=level)
4648

4749
def __setup_base_image(self):
48-
base_image = f"nunosaavedra/gitbug-actions:setup"
49-
runner_image = f"gitbug-java:base"
5050

5151
client = DockerClient.getInstance()
5252
# Return if image already exists
53-
if len(client.images.list(name=runner_image)) > 0:
54-
return
53+
# if len(client.images.list(name=self.__gitbugjava_base_image)) > 0:
54+
# return
5555

5656
tmp_dir = tempfile.mkdtemp()
5757
Path(tmp_dir).mkdir(parents=True, exist_ok=True)
5858
dockerfile_path = Path(tmp_dir, "Dockerfile")
5959
with dockerfile_path.open("w") as f:
60-
dockerfile = f"FROM {base_image}\n"
60+
dockerfile = f"FROM {self.__gitbugactions_base_image}\n"
6161
# HACK: We set runneradmin to an arbitrarily large uid to avoid conflicts with the host's
6262
dockerfile += f"RUN sudo usermod -u 4000000 runneradmin\n"
6363
dockerfile += f"RUN sudo groupadd -o -g {os.getgid()} {grp.getgrgid(os.getgid()).gr_name}\n"
6464
dockerfile += f"RUN sudo usermod -G {os.getgid()} runner\n"
6565
dockerfile += f"RUN sudo usermod -o -u {os.getuid()} runner\n"
66+
dockerfile += f"RUN sudo apt update\n"
67+
dockerfile += f"RUN sudo apt install maven -y\n"
6668
f.write(dockerfile)
6769

68-
client.images.build(path=tmp_dir, tag=runner_image, forcerm=True)
70+
client.images.build(path=tmp_dir, tag=self.__gitbugjava_base_image, forcerm=True)
6971
shutil.rmtree(tmp_dir, ignore_errors=True)
7072

7173
def __download(self, url: str, filename: str):
@@ -190,7 +192,7 @@ class GitBugJavaCli(object):
190192
bug = Bug(bug_info)
191193

192194
# Run the bug
193-
return bug.run(workdir, output, act_cache_dir=act_cache_dir, timeout=timeout)
195+
return bug.run(workdir, output, act_cache_dir=act_cache_dir, timeout=timeout, base_image=self.__gitbugjava_base_image)
194196

195197
def setup(self):
196198
"""
@@ -200,17 +202,17 @@ class GitBugJavaCli(object):
200202
os.makedirs(os.path.join(get_project_root(), "data"))
201203
self.__setup_base_image()
202204
# TODO: check if exports are already downloaded
203-
self.__setup_exports(
204-
"gitbug-java_offline_environments_1",
205-
"https://zenodo.org/records/10578602/files/gitbug-java_offline_environments_1.tar.gz?download=1",
206-
)
207-
self.__setup_exports(
208-
"gitbug-java_offline_environments_2",
209-
"https://zenodo.org/records/10578617/files/gitbug-java_offline_environments_2.tar.gz?download=1",
210-
)
211-
self.__setup_act_cache(
212-
"https://zenodo.org/records/10592626/files/act-cache.zip?download=1",
213-
)
205+
# self.__setup_exports(
206+
# "gitbug-java_offline_environments_1",
207+
# "https://zenodo.org/records/10578602/files/gitbug-java_offline_environments_1.tar.gz?download=1",
208+
# )
209+
# self.__setup_exports(
210+
# "gitbug-java_offline_environments_2",
211+
# "https://zenodo.org/records/10578617/files/gitbug-java_offline_environments_2.tar.gz?download=1",
212+
# )
213+
# self.__setup_act_cache(
214+
# "https://zenodo.org/records/10592626/files/act-cache.zip?download=1",
215+
# )
214216

215217

216218
def main():

gitbug/bug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def run(
149149
output: str,
150150
act_cache_dir: Optional[str] = None,
151151
timeout: int = 0,
152+
base_image: str = "gitbug-java:base",
152153
) -> bool:
153154
# Check if the workdir has a bug
154155
logging.debug(f"Running {self.bid} in {workdir}")
@@ -169,7 +170,6 @@ def run(
169170
act_cache_dir = ActCacheDirManager.acquire_act_cache_dir()
170171
try:
171172
logging.debug(f"Creating docker image for {self.bid}")
172-
base_image = f"gitbug-java:base"
173173
runner_image = f"gitbug-java:{str(uuid.uuid4())}"
174174

175175
diff_folder_path = Path(

test/test_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ def test_run_all_parallel():
8383
for future in tqdm.tqdm(as_completed(futures), total=len(futures)):
8484
results.append(future.result())
8585

86-
assert all(results)
86+
assert sum(results) == 398

0 commit comments

Comments
 (0)