load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

go_library(
    name = "cmd_lib",
    srcs = ["main.go"],
    importpath = "github.com/edgelesssys/constellation/v2/keyservice/cmd",
    visibility = ["//visibility:private"],
    deps = [
        "//internal/constants",
        "//internal/crypto",
        "//internal/file",
        "//internal/kms/setup",
        "//internal/kms/uri",
        "//internal/logger",
        "//keyservice/internal/server",
        "@com_github_spf13_afero//:afero",
        "@org_uber_go_zap//:zap",
    ],
)

go_binary(
    name = "cmd",
    embed = [":cmd_lib"],
    # keep
    pure = "on",
    visibility = ["//visibility:public"],
)

go_cross_binary(
    name = "keyservice_linux_amd64",
    platform = "@io_bazel_rules_go//go/toolchain:linux_amd64",
    target = ":cmd",
    visibility = ["//visibility:public"],
)

pkg_tar(
    name = "layer",
    srcs = [
        ":keyservice_linux_amd64",
    ],
    mode = "0755",
    remap_paths = {"/keyservice_linux_amd64": "/keyservice"},
)

oci_image(
    name = "keyservice",
    base = "@distroless_static_linux_amd64",
    entrypoint = ["/keyservice"],
    tars = [
        ":layer",
    ],
    visibility = ["//visibility:public"],
)
