diff --git a/README.md b/README.md index f1fc5a5..09d8220 100644 --- a/README.md +++ b/README.md @@ -407,6 +407,52 @@ bazel run //.../helm-chart:push Note that only `basic` auth is supported at the moment. If you are using it, you must export `HELM_REPO_USERNAME` and `HELM_REPO_PASSWORD` with the username and the password of your Chartmuseum helm repository. +## Minikube + +Currently the Minikube rule set supports starting (creating) and stopping (destroying) a Minikube Kubernetes cluster. + +For downloading the Minikube binary, add this to your WORKSPACES file: + +```python +load("@com_github_airyhq_bazel_tools//minikube:minikube.bzl", "minikube_tool") + +minikube_tool( + name = "minikube_binary", +) +``` + +For creating a Kubernetes cluster add this to your BUILD file: + +```python +load("@com_github_airyhq_bazel_tools//minikube:minikube.bzl", "minikube_start") + +minikube_start( + name = "minikube-start", +) +``` + +Then run: + +```shell +bazel run //.../infrastructure:minikube-start +``` + +For destroying a Kubernetes cluster add this to your BUILD file: + +```python +load("@com_github_airyhq_bazel_tools//minikube:minikube.bzl", "minikube_stop") + +minikube_stop( + name = "minikube-stop", +) +``` + +Then run: + +```shell +bazel run //.../infrastructure:minikube-stop +``` + ## Aspects We provide a simple [aspect](https://docs.bazel.build/versions/main/skylark/aspects.html) that helps discover the output groups of a target. diff --git a/minikube/BUILD b/minikube/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/minikube/minikube.bzl b/minikube/minikube.bzl new file mode 100644 index 0000000..7d4cd9d --- /dev/null +++ b/minikube/minikube.bzl @@ -0,0 +1,66 @@ +def _minikube_tool_impl(ctx): + os_build_name = "linux" + if ctx.os.name.startswith("mac"): + os_build_name = "darwin" + ctx.download( + "https://storage.googleapis.com/minikube/releases/latest/minikube-%s-amd64" % (os_build_name), + output='minikube', + executable=True, + ) + ctx.file("BUILD", 'exports_files(["minikube"])') + +minikube_tool = repository_rule( + implementation = _minikube_tool_impl, +) + +def _minikube_start_impl(ctx): + script = "{} -p airy-core start --driver=docker --cpus=4 --memory=7168 --container-runtime=containerd --ports=80:80 --extra-config=apiserver.service-nodeport-range=1-65535".format(ctx.executable._minikube_binary.path) + + ctx.actions.write( + output = ctx.outputs.executable, + content = script, + is_executable = True, + ) + + runfiles = ctx.runfiles(files = [ctx.executable._minikube_binary]) + return [DefaultInfo(runfiles = runfiles)] + +minikube_start = rule( + implementation = _minikube_start_impl, + executable = True, + attrs = { + "_minikube_binary": attr.label( + executable = True, + cfg = "exec", + allow_files = True, + default = Label("@minikube_binary//:minikube"), + doc = "The Minikube binary downloaded with a repository rule.", + ), + }, +) + +def _minikube_stop_impl(ctx): + script = "{} -p airy-core delete".format(ctx.executable._minikube_binary.path) + + ctx.actions.write( + output = ctx.outputs.executable, + content = script, + is_executable = True, + ) + + runfiles = ctx.runfiles(files = [ctx.executable._minikube_binary]) + return [DefaultInfo(runfiles = runfiles)] + +minikube_stop = rule( + implementation = _minikube_stop_impl, + executable = True, + attrs = { + "_minikube_binary": attr.label( + executable = True, + cfg = "exec", + allow_files = True, + default = Label("@minikube_binary//:minikube"), + doc = "The Minikube binary downloaded with a repository rule.", + ), + }, +)