Skip to content

Commit

Permalink
feat: prevent Writer Framework version mismatch local/cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienArcellier committed Jan 17, 2025
1 parent bbb6baa commit 3b4c30a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
31 changes: 20 additions & 11 deletions src/writer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@ def upload_package(deploy_url, tar, token, env, verbose=False, sleep_interval=5)
time.sleep(sleep_interval)
start_time = end_time

_check_version_integrity(deploy_url)

if status == "COMPLETED":
_check_version_integrity(url, token)
print("Deployment successful")
print(f"URL: {url}")
sys.exit(0)
Expand Down Expand Up @@ -324,16 +323,26 @@ def unauthorized_error():
sys.exit(1)


def _check_version_integrity(app_url: str):
def _check_version_integrity(app_url: str, token: str):
"""
Check if the writer version in the deployment package is newer than the writer version running on the server.
>>> _check_version_integrity("https://xxxxxxxxxxxxxxxx.ai.writer.build", "xxxxxxxxxxxxxxxxxxxxxxxxxx")
"""
with requests.get(f"{app_url}/_meta") as resp:
data = resp.json()
if "writer_version_dev" not in data or "writer_version_run" not in data:
return

if Version(data["writer_version_dev"]) > Version(data["writer_version_run"]):
print(f"[WARNING] The writer version in the deployment package ({data['writer_version_dev']}) is newer than the writer version running on the server ({data['writer_version_run']}).")
return
try:
with requests.get(
f"{app_url}/_meta",
headers={
"Authorization": f"Bearer {token}",
},
) as resp:
data = resp.json()
if "writer_version_dev" not in data or "writer_version_run" not in data:
return

if Version(data["writer_version_dev"]) > Version(data["writer_version_run"]):
print(f"[WARNING] The writer version in the deployment package ({data['writer_version_dev']}) is newer than the writer version running on the server ({data['writer_version_run']}).")
return
except requests.exceptions.RequestException as e:
print("Ignore local / cloud version integrity check")
logging.debug(f"Error checking version integrity {e}", exc_info=e)
3 changes: 1 addition & 2 deletions src/writer/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
from pydantic import ValidationError
from starlette.websockets import WebSocket, WebSocketDisconnect, WebSocketState


from writer import VERSION, abstract, wf_project, crypto
from writer import VERSION, abstract, crypto, wf_project
from writer.app_runner import AppRunner
from writer.ss_types import (
AppProcessServerResponse,
Expand Down

0 comments on commit 3b4c30a

Please sign in to comment.