Skip to content
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

Cleanup files after serving #886

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
3 changes: 3 additions & 0 deletions agenta-cli/agenta/cli/variant_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def add_variant(
image: Image = client.send_docker_tar(
app_id, base_name, tar_path, host, api_key
)
if tar_path.exists():
tar_path.unlink()

# docker_image: DockerImage = build_and_upload_docker_image(
# folder=app_path, app_name=app_name, variant_name=variant_name)
except Exception as ex:
Expand Down
16 changes: 15 additions & 1 deletion agenta-cli/agenta/docker/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

DEBUG = False


def create_dockerfile(out_folder: Path):
"""Creates a dockerfile based on the template in the out_folder.
Expand Down Expand Up @@ -47,7 +49,7 @@ def build_tar_docker_container(folder: Path, file_name: Path) -> Path:
if tarfile_path.exists():
tarfile_path.unlink()

dockerfile_path = create_dockerfile(folder)
create_dockerfile(folder)
shutil.copytree(Path(__file__).parent.parent, folder / "agenta", dirs_exist_ok=True)
shutil.copy(Path(__file__).parent / "docker-assets" / "main.py", folder)
shutil.copy(Path(__file__).parent / "docker-assets" / "lambda_function.py", folder)
Expand Down Expand Up @@ -82,6 +84,18 @@ def ignore_patterns(path, names):
# Create the tar.gz file
with tarfile.open(tarfile_path, "w:gz") as tar:
tar.add(temp_path, arcname=folder.name)
if not DEBUG:
# Clean up - remove specified files and folders
for item in ["agenta", "main.py", "lambda_function.py", "entrypoint.sh"]:
path = folder / item
if path.exists():
if path.is_dir():
shutil.rmtree(path)
else:
path.unlink()

for dockerfile in folder.glob("Dockerfile*"):
dockerfile.unlink()

# dockerfile_path.unlink()
return tarfile_path
Expand Down
Loading