start.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import os
  2. import subprocess
  3. import socket
  4. from pathlib import Path
  5. data_sources = [
  6. Path.home() / "Documents" / "cv",
  7. Path.home() / "Documents" / "formations" / "5_jours"
  8. ]
  9. def to_volume_string(vol: str | Path):
  10. return f"-v {vol}:/mnt/source{vol}:ro"
  11. def main():
  12. hostname = socket.gethostname()
  13. container_name = "borgmatic"
  14. ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
  15. config_path = Path.cwd() / "data" / "borgmatic.d"
  16. credentials_path = Path.cwd() / "data" / "credentials"
  17. ssh_config_path = Path.home() / ".ssh"
  18. volumes = [
  19. f"{config_path}:/etc/borgmatic.d/",
  20. f"{credentials_path}:/credentials/",
  21. f"{ssh_config_path}:/root/.ssh",
  22. "borg_config:/root/.config/borg",
  23. "borg_cache:/root/.cache/borg",
  24. "borgmatic_state:/root/.local/state/borgmatic",
  25. ]
  26. if ssh_auth_sock:
  27. volumes += [f"{ssh_auth_sock}:{ssh_auth_sock}:Z"]
  28. volumes += [
  29. f"{vol}:/mnt/source{vol}:ro" for vol in data_sources
  30. ]
  31. volume_args = [a for vol in volumes for a in ["-v", vol]]
  32. image_name = "ghcr.io/borgmatic-collective/borgmatic"
  33. args = [
  34. "podman",
  35. "run",
  36. "-h",
  37. hostname,
  38. "--detach",
  39. "--name",
  40. container_name,
  41. "-e SSH_AUTH_SOCK",
  42. "-e TZ=Europe/Paris",
  43. "--security-opt=label=disable"
  44. ] + volume_args + [image_name]
  45. print(args)
  46. subprocess.run(args)
  47. if __name__ == "__main__":
  48. main()