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