mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 06:08:13 +02:00
made docker client local to handlers and lazy
loaded so that we don't have to start docker if we don't want it
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
import os, re, docker, signal, javalang
|
import os, re, docker, signal, javalang, time
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from typing import Iterable, Tuple, Iterator
|
from typing import Iterable, Optional, Tuple, Iterator
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from javalang.tree import PackageDeclaration
|
from javalang.tree import PackageDeclaration
|
||||||
import tarfile
|
import tarfile
|
||||||
@ -16,17 +16,18 @@ GROUP_ID = os.getgid()
|
|||||||
|
|
||||||
|
|
||||||
class BuildHandler(ABC):
|
class BuildHandler(ABC):
|
||||||
|
DOCKER_CLIENT: Optional[docker.DockerClient] = None
|
||||||
|
|
||||||
def __init__(self, repo_path: str, build_file: str, updates: dict) -> None:
|
def __init__(self, repo_path: str, build_file: str, updates: dict) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.path: str = repo_path
|
self.path: str = repo_path
|
||||||
self.build_file: str = build_file
|
self.build_file: str = build_file
|
||||||
self.updates = updates
|
self.updates = updates
|
||||||
|
|
||||||
def set_client(self, client: docker.DockerClient):
|
|
||||||
self.client = client
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.container = self.client.containers.run(
|
if BuildHandler.DOCKER_CLIENT is None:
|
||||||
|
BuildHandler.DOCKER_CLIENT = docker.from_env()
|
||||||
|
self.container = BuildHandler.DOCKER_CLIENT.containers.run(
|
||||||
image=self.container_name(),
|
image=self.container_name(),
|
||||||
command="tail -f /dev/null", # to keep the container alive
|
command="tail -f /dev/null", # to keep the container alive
|
||||||
volumes={os.path.abspath(self.path): {"bind": "/repo", "mode": "rw"}},
|
volumes={os.path.abspath(self.path): {"bind": "/repo", "mode": "rw"}},
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import os
|
import sys
|
||||||
import sys, docker
|
|
||||||
from utils.handlers import get_build_handler
|
from utils.handlers import get_build_handler
|
||||||
from .paths import get_project_path
|
from .paths import get_project_path
|
||||||
from sacrebleu import sentence_bleu as bleu
|
from sacrebleu import sentence_bleu as bleu
|
||||||
@ -11,8 +10,6 @@ REFERENCE_MAP = Dataset.from_json(
|
|||||||
|
|
||||||
ARCHIVES_ROOT = str(get_project_path('../data/archives'))
|
ARCHIVES_ROOT = str(get_project_path('../data/archives'))
|
||||||
|
|
||||||
DOCKER_CLIENT = docker.from_env()
|
|
||||||
|
|
||||||
|
|
||||||
def evaluate_comments(answers: dict[str, str], percent_cb):
|
def evaluate_comments(answers: dict[str, str], percent_cb):
|
||||||
total = len(answers)
|
total = len(answers)
|
||||||
@ -57,7 +54,6 @@ def evaluate_refinement(answers: dict[str, dict[str, str]], percent_cb):
|
|||||||
build_handler = get_build_handler(
|
build_handler = get_build_handler(
|
||||||
ARCHIVES_ROOT, entry.metadata.archive_name(ArchiveState.MERGED)
|
ARCHIVES_ROOT, entry.metadata.archive_name(ArchiveState.MERGED)
|
||||||
)
|
)
|
||||||
build_handler.set_client(DOCKER_CLIENT)
|
|
||||||
current_progress += 1
|
current_progress += 1
|
||||||
percent_cb(current_progress / total_number_of_steps * 100)
|
percent_cb(current_progress / total_number_of_steps * 100)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Reference in New Issue
Block a user