Skip to content

Commit

Permalink
fix deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Dec 12, 2024
1 parent 6702ba1 commit cb52de1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
33 changes: 32 additions & 1 deletion deploy.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import asyncio
import logging
import os
import sys
from base64 import b16decode, b32encode
from pathlib import Path
from shutil import make_archive
from typing import Tuple
from zipfile import BadZipFile

import magic
from aleph.sdk import AuthenticatedAlephHttpClient
from aleph.sdk.account import _load_account
from aleph.sdk.conf import settings
from aleph.sdk.types import AccountFromPrivateKey, StorageEnum
from aleph_client.utils import create_archive
from aleph.sdk.utils import try_open_zip
from aleph_message.models import ItemHash, StoreMessage
from aleph_message.models.execution import Encoding
from aleph_message.status import MessageStatus

logging.basicConfig(level=logging.DEBUG)
Expand All @@ -19,6 +24,32 @@
channel = "aleph-infrastructure"


def create_archive(path: Path) -> Tuple[Path, Encoding]:
"""Create a zip archive from a directory"""
if os.path.isdir(path):
if settings.CODE_USES_SQUASHFS:
logger.debug("Creating squashfs archive...")
archive_path = Path(f"{path}.squashfs")
os.system(f"mksquashfs {path} {archive_path} -noappend")
assert archive_path.is_file()
return archive_path, Encoding.squashfs
else:
logger.debug("Creating zip archive...")
make_archive(str(path), "zip", path)
archive_path = Path(f"{path}.zip")
return archive_path, Encoding.zip
elif os.path.isfile(path):
if path.suffix == ".squashfs" or (
magic and magic.from_file(path).startswith("Squashfs filesystem")
):
return path, Encoding.squashfs
else:
try_open_zip(Path(path))
return path, Encoding.zip
else:
raise FileNotFoundError("No file or directory to create the archive from")


async def deploy_program():
path = Path(__file__).parent / "src"
try:
Expand Down
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ dependencies = [
"isort==5.13.2",
"fastapi==0.115.6",
"aiohttp==3.11.10",
"pytest==8.3.4",
"aioresponses==0.7.7",
"pytest==8.3.4",
"aioresponses==0.7.7",
"aleph-sdk-python==1.2.1",
]
[tool.hatch.envs.linting.scripts]
typing = "mypy {args:.}"
Expand Down Expand Up @@ -122,3 +123,8 @@ fail_under = 100
[tool.coverage.paths]
aleph_vm = ["src/monitoring_proxy"]
tests = ["tests", "src/monitoring_proxy"]

[tool.coverage.run]
omit = [
"deploy.py"
]

0 comments on commit cb52de1

Please sign in to comment.