How can I run a shell script on k8s by using bazel?

Viewed 125

Usually, I run a python script on k8s. When I do this, I define below three and run with bazel run my_py_job_k8s.create

py_binary(
    name = "my_py_job",
    srcs = ["my_py_job.py"],
)

py3_image(
    name = "my_py_job_image",
    srcs = ["my_py_job.py"],
    base = "//donguk:base_image",
    main = "my_py_job.py",
    deps = [":my_py_job"],
)

k8s_object(
    name = "my_py_job_k8s",
    cluster = "my_cluster",
    images = {
        "experimental:my_py_job": ":my_py_job_image",
    },
    namespace = "{BUILD_USER}",
    template = ":my_py_job.yaml",
)

but this time I need to run shell script on k8s.

I defined similar way and tried to run bazel build my_sh_job_k8s, but even build was failed

sh_binary(
    name = "my_sh_job",
    srcs = ["my_sh_job.sh"],
)

py3_image(
    name = "my_sh_job_image",
    srcs = ["my_sh_job.sh"],
    base = "//donguk:base_image_2",
    main = "my_sh_job.py",
    deps = [":my_sh_job"],
)

k8s_object(
    name = "my_sh_job_k8s",
    cluster = "my_cluster",
    images = {
        "experimental:my_sh_job": ":my_sh_job_image",
    },
    namespace = "{BUILD_USER}",
    template = ":my_sh_job.yaml",
)

Error message

BUILD:12:10: in srcs attribute of py_binary rule //experimental/tools:my_sh_job_image.binary: source file '//experimental/tools:my_sh_job.sh' is misplaced here (expected .py or .py3). Since this rule was created by the macro 'py3_image', the error might have been caused by the macro implementation

So it seems that I should've not use py3_image for shell script, but I couldn't find which image format to use. There is no sh_image, do I need to use container_image in this case? or shell scripts files are not allow to run on k8s?

0 Answers
Related