build_command.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import click
  2. import asyncio
  3. import sys
  4. import dagger
  5. import pathlib
  6. import uuid
  7. from nd import (
  8. Distribution,
  9. NetdataInstaller,
  10. FeatureFlags,
  11. Endpoint,
  12. AgentContext,
  13. SUPPORTED_PLATFORMS,
  14. SUPPORTED_DISTRIBUTIONS,
  15. )
  16. def run_async(func):
  17. def wrapper(*args, **kwargs):
  18. return asyncio.run(func(*args, **kwargs))
  19. return wrapper
  20. @run_async
  21. async def simple_build(platform, distro):
  22. config = dagger.Config(log_output=sys.stdout)
  23. async with dagger.Connection(config) as client:
  24. repo_root = pathlib.Path("/netdata")
  25. prefix_path = pathlib.Path("/opt/netdata")
  26. installer = NetdataInstaller(
  27. platform, distro, repo_root, prefix_path, FeatureFlags.DBEngine
  28. )
  29. endpoint = Endpoint("node", 19999)
  30. api_key = uuid.uuid4()
  31. allow_children = False
  32. agent_ctx = AgentContext(
  33. client, platform, distro, installer, endpoint, api_key, allow_children
  34. )
  35. await agent_ctx.build_container()
  36. @click.command()
  37. @click.option(
  38. "--platform",
  39. "-p",
  40. type=click.Choice(sorted([str(p) for p in SUPPORTED_PLATFORMS])),
  41. help="Specify the platform.",
  42. )
  43. @click.option(
  44. "--distribution",
  45. "-d",
  46. type=click.Choice(sorted([str(p) for p in SUPPORTED_DISTRIBUTIONS])),
  47. help="Specify the distribution.",
  48. )
  49. def build(platform, distribution):
  50. platform = dagger.Platform(platform)
  51. distro = Distribution(distribution)
  52. simple_build(platform, distro)