77tailored specifically for Docker environments.
88"""
99import os
10+ import shutil
1011import tempfile
1112from pathlib import Path
1213from typing import Dict , List
1314
1415from pythainer .builders .cmds import (
1516 AddPkgDockerBuildCommand ,
17+ CopyDockerBuildCommand ,
1618 DockerBuildCommand ,
1719 StrDockerBuildCommand ,
1820)
@@ -220,16 +222,15 @@ def add_packages(self, packages: List[str]) -> None:
220222 """
221223 self ._build_commands .append (AddPkgDockerBuildCommand (packages = packages ))
222224
223- def copy (self , filename : PathType , destination : PathType ) -> None :
225+ def copy (self , source_path : Path , destination_path : Path ) -> None :
224226 """
225227 Copies a file to the docker container
226228
227229 Parameters:
228- filename (PathType ): The file to copy to the container.
229- destination (PathType ): The location to place the file within the Docker container.
230+ source_path (Path ): The file or folder to copy to the container.
231+ destination_path (Path ): The location to place the file or folder within the Docker container.
230232 """
231- cmd = f"COPY { filename } { destination } "
232- self ._build_commands .append (StrDockerBuildCommand (cmd ))
233+ self ._build_commands .append (CopyDockerBuildCommand (source_path ,destination_path ))
233234
234235
235236class DockerBuilder (PartialDockerBuilder ):
@@ -389,19 +390,25 @@ def build(self, dockerfile_savepath: PathType = "", docker_context: PathType = "
389390 Parameters:
390391 dockerfile_savepath (PathType): Optional path to save the Dockerfile used for the build.
391392 """
393+
392394 main_dir = Path ("/tmp/pythainer/docker/" )
393395 mkdir (main_dir )
394396 with tempfile .TemporaryDirectory (
395397 prefix = "/tmp/pythainer/docker/docker-build-" ,
396398 dir = main_dir ,
397399 ) as temp_dir :
400+
398401 temp_path = Path (temp_dir )
399402 dockerfile_path = (temp_path / "Dockerfile" ).resolve ()
400403 dockerfile_paths = [dockerfile_path ] + (
401404 [dockerfile_savepath ] if dockerfile_savepath else []
402405 )
403406 self .generate_dockerfile (dockerfile_paths = dockerfile_paths )
404407
408+ data_path = main_dir / "data"
409+
410+ shutil .move (data_path , temp_path )
411+
405412 command = self .get_build_commands (
406413 dockerfile_path = dockerfile_path ,
407414 docker_build_dir = Path (docker_context ).resolve () if docker_context else temp_path ,
@@ -418,6 +425,7 @@ def build(self, dockerfile_savepath: PathType = "", docker_context: PathType = "
418425 output_is_log = True ,
419426 )
420427
428+
421429 def get_runner (
422430 self ,
423431 workdir : PathType | None = None ,
0 commit comments