Skip to content

WIP: reduce image size by using smaller base image #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions gitbug-java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class GitBugJavaCli(object):
def __init__(self, verbose: bool = False):
self.__init_logging(verbose)
self.__projects = {}
self.__gitbugactions_base_image = "ghcr.io/catthehacker/ubuntu:runner-latest"
self.__gitbugjava_base_image = "gitbug-java:base-act-latest"

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

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

client = DockerClient.getInstance()
# Return if image already exists
if len(client.images.list(name=runner_image)) > 0:
return
# if len(client.images.list(name=self.__gitbugjava_base_image)) > 0:
# return

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

client.images.build(path=tmp_dir, tag=runner_image, forcerm=True)
client.images.build(path=tmp_dir, tag=self.__gitbugjava_base_image, forcerm=True)
shutil.rmtree(tmp_dir, ignore_errors=True)

def __download(self, url: str, filename: str):
Expand Down Expand Up @@ -190,7 +192,7 @@ class GitBugJavaCli(object):
bug = Bug(bug_info)

# Run the bug
return bug.run(workdir, output, act_cache_dir=act_cache_dir, timeout=timeout)
return bug.run(workdir, output, act_cache_dir=act_cache_dir, timeout=timeout, base_image=self.__gitbugjava_base_image)

def setup(self):
"""
Expand All @@ -200,17 +202,17 @@ class GitBugJavaCli(object):
os.makedirs(os.path.join(get_project_root(), "data"))
self.__setup_base_image()
# TODO: check if exports are already downloaded
self.__setup_exports(
"gitbug-java_offline_environments_1",
"https://zenodo.org/records/10578602/files/gitbug-java_offline_environments_1.tar.gz?download=1",
)
self.__setup_exports(
"gitbug-java_offline_environments_2",
"https://zenodo.org/records/10578617/files/gitbug-java_offline_environments_2.tar.gz?download=1",
)
self.__setup_act_cache(
"https://zenodo.org/records/10592626/files/act-cache.zip?download=1",
)
# self.__setup_exports(
# "gitbug-java_offline_environments_1",
# "https://zenodo.org/records/10578602/files/gitbug-java_offline_environments_1.tar.gz?download=1",
# )
# self.__setup_exports(
# "gitbug-java_offline_environments_2",
# "https://zenodo.org/records/10578617/files/gitbug-java_offline_environments_2.tar.gz?download=1",
# )
# self.__setup_act_cache(
# "https://zenodo.org/records/10592626/files/act-cache.zip?download=1",
# )


def main():
Expand Down
2 changes: 1 addition & 1 deletion gitbug/bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def run(
output: str,
act_cache_dir: Optional[str] = None,
timeout: int = 0,
base_image: str = "gitbug-java:base",
) -> bool:
# Check if the workdir has a bug
logging.debug(f"Running {self.bid} in {workdir}")
Expand All @@ -169,7 +170,6 @@ def run(
act_cache_dir = ActCacheDirManager.acquire_act_cache_dir()
try:
logging.debug(f"Creating docker image for {self.bid}")
base_image = f"gitbug-java:base"
runner_image = f"gitbug-java:{str(uuid.uuid4())}"

diff_folder_path = Path(
Expand Down
2 changes: 1 addition & 1 deletion test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def test_run_all_parallel():
for future in tqdm.tqdm(as_completed(futures), total=len(futures)):
results.append(future.result())

assert all(results)
assert sum(results) == 398