Fix social deploy pack to skip __pycache__ and extract safely on 82.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
e65728601f
commit
8b7222127c
@ -63,6 +63,30 @@ def run(c: paramiko.SSHClient, cmd: str, timeout: int = 1200) -> tuple[str, int]
|
|||||||
return out, code
|
return out, code
|
||||||
|
|
||||||
|
|
||||||
|
_SKIP_DIR = {"__pycache__", "node_modules", ".next", ".git"}
|
||||||
|
|
||||||
|
|
||||||
|
def _add_tree(tar: tarfile.TarFile, path: Path, arcname: str) -> None:
|
||||||
|
if path.is_file():
|
||||||
|
if path.suffix == ".pyc":
|
||||||
|
return
|
||||||
|
tar.add(path, arcname=arcname)
|
||||||
|
return
|
||||||
|
for root, dirs, files in os.walk(path):
|
||||||
|
dirs[:] = [d for d in dirs if d not in _SKIP_DIR]
|
||||||
|
root_path = Path(root)
|
||||||
|
rel_root = root_path.relative_to(path)
|
||||||
|
for name in files:
|
||||||
|
if name.endswith(".pyc"):
|
||||||
|
continue
|
||||||
|
fp = root_path / name
|
||||||
|
if str(rel_root) == ".":
|
||||||
|
arc = f"{arcname}/{name}"
|
||||||
|
else:
|
||||||
|
arc = f"{arcname}/{rel_root.as_posix()}/{name}"
|
||||||
|
tar.add(fp, arcname=arc)
|
||||||
|
|
||||||
|
|
||||||
def pack() -> Path:
|
def pack() -> Path:
|
||||||
tmp = Path(tempfile.mkdtemp()) / "social82.tgz"
|
tmp = Path(tempfile.mkdtemp()) / "social82.tgz"
|
||||||
with tarfile.open(tmp, "w:gz") as tar:
|
with tarfile.open(tmp, "w:gz") as tar:
|
||||||
@ -71,7 +95,7 @@ def pack() -> Path:
|
|||||||
if not p.exists():
|
if not p.exists():
|
||||||
print("skip missing", rel)
|
print("skip missing", rel)
|
||||||
continue
|
continue
|
||||||
tar.add(p, arcname=rel)
|
_add_tree(tar, p, rel)
|
||||||
print("packed", tmp, "bytes", tmp.stat().st_size)
|
print("packed", tmp, "bytes", tmp.stat().st_size)
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
@ -92,7 +116,9 @@ def main() -> int:
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
cd {APP}
|
cd {APP}
|
||||||
sudo cp -a data/remote-config.json /tmp/remote-config.pre-social.json || true
|
sudo cp -a data/remote-config.json /tmp/remote-config.pre-social.json || true
|
||||||
tar -xzf /tmp/social82.tgz
|
sudo chown -R ubuntu:ubuntu {APP}
|
||||||
|
find {APP}/apps/api/services/social_svc -type d -name '__pycache__' -prune -exec rm -rf {{}} + 2>/dev/null || true
|
||||||
|
tar -xzf /tmp/social82.tgz --no-same-owner
|
||||||
# restore operational remote-config then merge social module key via python
|
# restore operational remote-config then merge social module key via python
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import json
|
import json
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user