summaryrefslogtreecommitdiffstats
path: root/packaging/dag/build_command.py
blob: dcb1b6c8a6a116551f20243c01048dc583110551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import click
import asyncio
import sys
import dagger
import pathlib
import uuid

from nd import (
    Distribution,
    NetdataInstaller,
    FeatureFlags,
    Endpoint,
    AgentContext,
    SUPPORTED_PLATFORMS,
    SUPPORTED_DISTRIBUTIONS,
)


def run_async(func):
    def wrapper(*args, **kwargs):
        return asyncio.run(func(*args, **kwargs))

    return wrapper


@run_async
async def simple_build(platform, distro):
    config = dagger.Config(log_output=sys.stdout)

    async with dagger.Connection(config) as client:
        repo_root = pathlib.Path("/netdata")
        prefix_path = pathlib.Path("/opt/netdata")

        installer = NetdataInstaller(
            platform, distro, repo_root, prefix_path, FeatureFlags.DBEngine
        )

        endpoint = Endpoint("node", 19999)
        api_key = uuid.uuid4()
        allow_children = False

        agent_ctx = AgentContext(
            client, platform, distro, installer, endpoint, api_key, allow_children
        )

        await agent_ctx.build_container()


@click.command()
@click.option(
    "--platform",
    "-p",
    type=click.Choice(sorted([str(p) for p in SUPPORTED_PLATFORMS])),
    help="Specify the platform.",
)
@click.option(
    "--distribution",
    "-d",
    type=click.Choice(sorted([str(p) for p in SUPPORTED_DISTRIBUTIONS])),
    help="Specify the distribution.",
)
def build(platform, distribution):
    platform = dagger.Platform(platform)
    distro = Distribution(distribution)
    simple_build(platform, distro)