TNO Intern

Commit d1ba1220 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Cleaning up the module removing the docker implementation

parent f9549c1f
Loading
Loading
Loading
Loading

models/.gitignore

deleted100644 → 0
+0 −1
Original line number Diff line number Diff line
**/*
 No newline at end of file

pythermogis.py

deleted100644 → 0
+0 −23
Original line number Diff line number Diff line
import sys

import yaml

from src.thermogis.TechnoEconomicWrapper import edit_wp5_configuration_file, run_wp5_docker_image
from src.datamodels.configuration import Config


def run(config_file):
    with open(config_file, "r") as f:
        config_dict = yaml.load(f,Loader=yaml.FullLoader)
    config = Config(**config_dict)
    xml_file = config.model_path / "xml" / "doublet.xml"

    # edit the xml file that the ThermoGIS docker image will be run on
    edit_wp5_configuration_file(config, xml_file)

    # run the ThermoGIS docker image
    run_wp5_docker_image(config)


if __name__ == '__main__':
    run(sys.argv[1])
 No newline at end of file

src/utils/docker_util.py

deleted100644 → 0
+0 −52
Original line number Diff line number Diff line
import pathlib as Path
from docker import DockerClient


def docker_build(client: DockerClient, docker_path: Path, image_tag: str):
    """
    Build a docker image
    :param client: a DockerClient instance
    :param docker_path: the path to the directory containing the Dockerfile
    :param image_tag: the name of the image that will be built
    """
    try:
        # Stream logs from the build process
        response = client.api.build(
            path=str(docker_path),
            tag=image_tag,
            rm=True,  # Remove intermediate containers
            decode=True,  # Decode JSON logs
        )

        for line in response:
            if 'stream' in line:
                print(line['stream'].strip())
    except Exception as e:
        print(f"Error: {e}")


def docker_run(client: DockerClient, image_tag: str, command: list[str], volumes: list[str]):
    """
    Run a docker image
    :param client: a DockerClient instance
    :param image_tag: the name of the image to be run
    :param command: a list of commands which will be appended to the ENTRYPOINT of the image; usually paths to configuration files
    :param volumes: a list of bind-volumes; connecting local filesystem to the filesystem within the docker container
    """
    try:
        # Run a container and stream its logs
        container = client.containers.run(
            image_tag,  # Replace with your image
            command=command,
            volumes=volumes,
            detach=True,
        )

        # Stream logs
        for line in container.logs(stream=True):
            print(line.decode('utf-8').strip())  # Decode bytes and print

        # Cleanup: remove the container
        container.remove()
    except Exception as e:
        print(f"Error: {e}")
+0 −17099

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −837

File deleted.

Preview size limit exceeded, changes collapsed.

Loading