build_remote.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. import subprocess
  3. import sys
  4. from urllib.parse import urlparse
  5. from git import Repo
  6. # Helper script to be able to build on remote repos using git to push local changes
  7. # (e.g. particularly helpful to target a remote windows build system)
  8. #
  9. # Typical windows remote git config looks like this:
  10. #
  11. #[remote "windows-pa"]
  12. # url = jdoe@desktop-foo:C:/Users/Jdoe/code/ollama
  13. # fetch = +refs/heads/*:refs/remotes/windows-pa/*
  14. # uploadpack = powershell git upload-pack
  15. # receivepack = powershell git receive-pack
  16. #
  17. # TODO - add argpare and make this more configurable
  18. # - force flag becomes optional
  19. # - generate, build or test ...
  20. # Note: remote repo will need this run once:
  21. # git config --local receive.denyCurrentBranch updateInstead
  22. repo = Repo(".")
  23. # On linux, add links in /usr/local/bin to the go binaries to avoid needing this
  24. # GoCmd = "/usr/local/go/bin/go"
  25. GoCmd = "go"
  26. if repo.is_dirty():
  27. print("Tree is dirty. Commit your changes before running this script")
  28. sys.exit(1)
  29. if len(sys.argv) != 2:
  30. print("Please specify the remote name: " + ', '.join([r.name for r in repo.remotes]))
  31. sys.exit(1)
  32. remote_name = sys.argv[1]
  33. remote = {r.name: r for r in repo.remotes}[remote_name]
  34. raw_url = list(remote.urls)[0]
  35. url = urlparse(raw_url)
  36. # Windows urls don't quite parse properly
  37. if url.scheme == "" and url.netloc == "":
  38. url = urlparse("ssh://" + raw_url)
  39. print("URL: " + str(url))
  40. netloc = url.netloc.split(":")[0]
  41. path = url.path
  42. branch_name = repo.active_branch.name
  43. print("Force pushing content to remote...")
  44. # Use with care given the force push
  45. remote.push(force=True).raise_if_error()
  46. print("Ensuring correct branch checked out on remote via ssh...")
  47. subprocess.check_call(['ssh', netloc, 'cd', path, ';', 'git', 'checkout', branch_name])
  48. # TODO - add some hardening to try to figure out how to set up the path properly
  49. # subprocess.check_call(['ssh', netloc, 'cd', path, ';', 'env'])
  50. # TODO - or consider paramiko maybe
  51. print("Running Windows Build Script")
  52. subprocess.check_call(['ssh', netloc, 'cd', path, ';', "powershell", "-ExecutionPolicy", "Bypass", "-File", "./scripts/build_windows.ps1"])
  53. # print("Building")
  54. # subprocess.check_call(['ssh', netloc, 'cd', path, ';', GoCmd, 'build', '.'])
  55. print("Copying built result")
  56. subprocess.check_call(['scp', netloc +":"+ path + "/ollama.exe", './dist/'])
  57. print("Copying installer")
  58. subprocess.check_call(['scp', netloc +":"+ path + "/dist/Ollama Setup.exe", './dist/'])