# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0

github.setup        kubetail-org kubetail 0.9.0 cli/v
github.tarball_from archive
revision            0

master_sites-append https://github.com/${github.author}/${github.project}/releases/download/${github.tag_prefix}${github.version}/:vendor

distfiles-append    vendor-bundle-${version}-go.tar.zst:vendor \
                    vendor-bundle-${version}-pnpm.tar.zst:vendor

supported_archs     arm64 x86_64

categories          devel
license             Apache-2
maintainers         {kubetail.com:andres @amorey} openmaintainer

description         Real-time logging tool for Kubernetes
long_description    Kubetail is a general-purpose logging tool for Kubernetes, optimized \
                    for tailing logs across multi-container workloads in real-time. With \
                    Kubetail, you can view logs from all the containers in a workload \
                    merged into a single, chronological timeline, in a browser or a \
                    terminal.

checksums           kubetail-${version}.tar.gz \
                    rmd160  5f33993dfab8648a826ceff25be8d6e8940f3dfa \
                    sha256  f71cf335f81e76f882efe11feed4ed8af691cc1d9fa8f6b5ee630ee22a99dabb \
                    size    618012 \
                    vendor-bundle-${version}-go.tar.zst \
                    rmd160  608c21e6ca3981b7c8a641c06bf4c1361f2345b9 \
                    sha256  01f4f1c95315a72508397c379c34e01cc1b6f25095431289ab95e2614cb65d6f \
                    size    13630282 \
                    vendor-bundle-${version}-pnpm.tar.zst \
                    rmd160  b92a85689dc351c41adb56adf2db16e594fbfcb7 \
                    sha256  30c7e8e9c9efba953a59efbdd5acc774aacf117d602bf2ab20fb4c0fa5dcd155 \
                    size    242703827

extract.only        ${github.project}-${github.version}${extract.suffix}

post-extract {
    system -W ${worksrcpath} "zstd -d ${distpath}/vendor-bundle-${version}-go.tar.zst --stdout | tar -xf -"
    system -W ${worksrcpath} "mv vendor modules/"

    system -W ${worksrcpath} "zstd -d ${distpath}/vendor-bundle-${version}-pnpm.tar.zst --stdout | tar -xf -"
    system -W ${worksrcpath} "mv pnpm-store dashboard-ui/.pnpm-store"
}

use_configure       no

pre-build {
    system -W ${worksrcpath}/dashboard-ui "pnpm config set store-dir .pnpm-store"
}

build.cmd           make
build.target        build
build.env-append    GOFLAGS="-mod=vendor"
build.args-append   VERSION=${version}

depends_build-append port:go port:pnpm
depends_extract      port:zstd

destroot {
    xinstall -m 0755 ${worksrcpath}/bin/kubetail ${destroot}${prefix}/bin/kubetail

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    if {[file exists ${worksrcpath}/LICENSE]} {
        xinstall -m 0644 ${worksrcpath}/LICENSE ${destroot}${prefix}/share/doc/${name}/
    }
}
