fix: install snapshots
This commit is contained in:
parent
c949ea17b2
commit
745d3f9d35
@ -28,6 +28,7 @@ web_app = FastAPI()
|
|||||||
print(config)
|
print(config)
|
||||||
print("deploy_test ", deploy_test)
|
print("deploy_test ", deploy_test)
|
||||||
stub = Stub(name=config["name"])
|
stub = Stub(name=config["name"])
|
||||||
|
# print(stub.app_id)
|
||||||
|
|
||||||
if not deploy_test:
|
if not deploy_test:
|
||||||
# dockerfile_image = Image.from_dockerfile(f"{current_directory}/Dockerfile", context_mount=Mount.from_local_dir(f"{current_directory}/data", remote_path="/data"))
|
# dockerfile_image = Image.from_dockerfile(f"{current_directory}/Dockerfile", context_mount=Mount.from_local_dir(f"{current_directory}/data", remote_path="/data"))
|
||||||
@ -36,6 +37,10 @@ if not deploy_test:
|
|||||||
dockerfile_image = (
|
dockerfile_image = (
|
||||||
modal.Image.debian_slim()
|
modal.Image.debian_slim()
|
||||||
.apt_install("git", "wget")
|
.apt_install("git", "wget")
|
||||||
|
.pip_install(
|
||||||
|
"git+https://github.com/modal-labs/asgiproxy.git", "httpx", "tqdm"
|
||||||
|
)
|
||||||
|
.apt_install("libgl1-mesa-glx", "libglib2.0-0")
|
||||||
.run_commands(
|
.run_commands(
|
||||||
# Basic comfyui setup
|
# Basic comfyui setup
|
||||||
"git clone https://github.com/comfyanonymous/ComfyUI.git /comfyui",
|
"git clone https://github.com/comfyanonymous/ComfyUI.git /comfyui",
|
||||||
@ -50,7 +55,6 @@ if not deploy_test:
|
|||||||
"cd /comfyui/custom_nodes && git clone https://github.com/BennyKok/comfyui-deploy.git",
|
"cd /comfyui/custom_nodes && git clone https://github.com/BennyKok/comfyui-deploy.git",
|
||||||
)
|
)
|
||||||
.copy_local_file(f"{current_directory}/data/extra_model_paths.yaml", "/comfyui")
|
.copy_local_file(f"{current_directory}/data/extra_model_paths.yaml", "/comfyui")
|
||||||
.copy_local_file(f"{current_directory}/data/snapshot.json", "/comfyui/custom_nodes/ComfyUI-Manager/startup-scripts/restore-snapshot.json")
|
|
||||||
|
|
||||||
.copy_local_file(f"{current_directory}/data/start.sh", "/start.sh")
|
.copy_local_file(f"{current_directory}/data/start.sh", "/start.sh")
|
||||||
.run_commands("chmod +x /start.sh")
|
.run_commands("chmod +x /start.sh")
|
||||||
@ -61,9 +65,9 @@ if not deploy_test:
|
|||||||
|
|
||||||
.run_commands("python install_deps.py")
|
.run_commands("python install_deps.py")
|
||||||
|
|
||||||
.pip_install(
|
.copy_local_file(f"{current_directory}/data/restore_snapshot.py", "/")
|
||||||
"git+https://github.com/modal-labs/asgiproxy.git", "httpx", "tqdm"
|
.copy_local_file(f"{current_directory}/data/snapshot.json", "/comfyui/custom_nodes/ComfyUI-Manager/startup-scripts/restore-snapshot.json")
|
||||||
)
|
.run_commands("python restore_snapshot.py")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Time to wait between API check attempts in milliseconds
|
# Time to wait between API check attempts in milliseconds
|
||||||
@ -295,4 +299,4 @@ def comfyui_app():
|
|||||||
},
|
},
|
||||||
)()
|
)()
|
||||||
|
|
||||||
return make_simple_proxy_app(ProxyContext(config))
|
return make_simple_proxy_app(ProxyContext(config))
|
85
builder/modal-builder/src/template/data/restore_snapshot.py
Normal file
85
builder/modal-builder/src/template/data/restore_snapshot.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import json
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
import subprocess
|
||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# Set up the logger
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
# Start the server
|
||||||
|
# server_process = subprocess.Popen(command, cwd="/comfyui", stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
def check_server(url, retries=50, delay=500):
|
||||||
|
for i in range(retries):
|
||||||
|
try:
|
||||||
|
response = requests.head(url)
|
||||||
|
|
||||||
|
# If the response status code is 200, the server is up and running
|
||||||
|
if response.status_code == 200:
|
||||||
|
print(f"builder - API is reachable")
|
||||||
|
return True
|
||||||
|
except requests.RequestException as e:
|
||||||
|
# If an exception occurs, the server may not be ready
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Wait for the specified delay before retrying
|
||||||
|
time.sleep(delay / 1000)
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"builder- Failed to connect to server at {url} after {retries} attempts."
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Define the messages to look for
|
||||||
|
# success_message = "[ComfyUI-Manager] Restore snapshot done."
|
||||||
|
success_message = "To see the GUI go to: http://127.0.0.1:8188"
|
||||||
|
failure_message = "[ComfyUI-Manager] Restore snapshot failed."
|
||||||
|
|
||||||
|
async def read_stream(stream, isStderr):
|
||||||
|
while True:
|
||||||
|
line = await stream.readline()
|
||||||
|
if line:
|
||||||
|
l = line.decode('utf-8').strip()
|
||||||
|
|
||||||
|
if l == "":
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not isStderr:
|
||||||
|
logging.info(l)
|
||||||
|
|
||||||
|
# If the output matches one of the messages, print it and break the loop
|
||||||
|
if success_message in l:
|
||||||
|
logging.info("Snapshot restore succeeded.")
|
||||||
|
break
|
||||||
|
elif failure_message in l:
|
||||||
|
logging.info("Snapshot restore failed.")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# is error
|
||||||
|
# logger.error(l)
|
||||||
|
logging.error(l)
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
command = "python main.py --disable-auto-launch --disable-metadata --cpu"
|
||||||
|
|
||||||
|
server_process = await asyncio.subprocess.create_subprocess_shell(command,
|
||||||
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
stderr=asyncio.subprocess.PIPE,
|
||||||
|
cwd="/comfyui")
|
||||||
|
|
||||||
|
stdout_task = asyncio.create_task(
|
||||||
|
read_stream(server_process.stdout, False))
|
||||||
|
stderr_task = asyncio.create_task(
|
||||||
|
read_stream(server_process.stderr, True))
|
||||||
|
|
||||||
|
await asyncio.wait([stdout_task, stderr_task])
|
||||||
|
|
||||||
|
print("Finished restoring snapshots.")
|
||||||
|
|
||||||
|
asyncio.run(main())
|
Loading…
x
Reference in New Issue
Block a user