Skip to content

Instantly share code, notes, and snippets.

@steeve
Created May 31, 2019 17:38
Show Gist options
  • Save steeve/2c1608d007764f5e6a32802ed9980735 to your computer and use it in GitHub Desktop.
Save steeve/2c1608d007764f5e6a32802ed9980735 to your computer and use it in GitHub Desktop.
genrule(
name = "kubeconfig",
stamp = True,
outs = ["k3s.yaml"],
cmd = """\
docker cp k3s:/etc/rancher/k3s/k3s.yaml $@
""",
visibility = ["//visibility:public"],
)
# Inject k3s container id in the workspace
k3s_id=$(docker ps -aqf "name=k3s")
echo "STABLE_K3S_CONTAINER_ID" "${k3s_id}"
@steeve
Copy link
Author

steeve commented May 31, 2019

k3s_id changes, and thus introduces stamp invalidation to the genrule, which is then re-executed.

@steeve
Copy link
Author

steeve commented May 31, 2019

I also have this handy rule, for quick stamp references in genrules/shell scripts:

genrule(
    name = "stamps_sh",
    outs = ["stamps.sh"],
    cmd = """sed -E 's/ +/=/' bazel-out/stable-status.txt > $@""",
    stamp = True,
    visibility = ["//visibility:public"],
)

Which is then used:

. $(location //:stamps_sh)
echo ${STABLE_SOME_KEY} > $@

@borg286
Copy link

borg286 commented Aug 12, 2020

@steeve can you share the build rules that can spin up a k3s cluster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment