run_deploy_script.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import os
  2. import subprocess
  3. import streamlit as st
  4. def get_1pw_deployer_private_key():
  5. return "000"
  6. def build_deploy_command(chain_name):
  7. return f"./deploy.sh {chain_name}"
  8. def run_deploy_script(chain_name: str):
  9. # Create a placeholder for the output
  10. with st.expander("Deployment logs", expanded=True):
  11. script_logs_div = st.code("")
  12. script_logs = ""
  13. env = os.environ.copy()
  14. env.update({"PK": get_1pw_deployer_private_key()})
  15. deploy_command = build_deploy_command(chain_name)
  16. process = subprocess.Popen(
  17. [
  18. "bash",
  19. "-c",
  20. f"source ~/.nvm/nvm.sh && nvm use 22.11.0 && {deploy_command}",
  21. ],
  22. stdout=subprocess.PIPE,
  23. stderr=subprocess.PIPE,
  24. text=True,
  25. bufsize=1,
  26. universal_newlines=True,
  27. cwd="/Users/tejasbadadare/dev/pyth-crosschain/target_chains/ethereum/contracts",
  28. env=env,
  29. )
  30. script_logs += f"Started deploying in process {process.pid}\n"
  31. # Stream output
  32. while True:
  33. output = process.stdout.readline()
  34. error = process.stderr.readline()
  35. if output:
  36. script_logs += output.strip() + "\n"
  37. if error:
  38. script_logs += error.strip() + "\n"
  39. script_logs_div.code(script_logs)
  40. # Check if process has finished
  41. if process.poll() is not None:
  42. # Dump any remaining output
  43. remaining_output, remaining_error = process.communicate()
  44. if remaining_output:
  45. script_logs += remaining_output.strip() + "\n"
  46. if remaining_error:
  47. script_logs += remaining_error.strip() + "\n"
  48. script_logs_div.code(script_logs)
  49. break
  50. # Get the return code
  51. if process.returncode == 0:
  52. st.success("Deployment script executed successfully!")
  53. else:
  54. st.error("Deployment script failed!")