Skip to content

Commit

Permalink
[#52] Add rules for Minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
ljupcovangelski committed Jun 28, 2022
1 parent e0dacc2 commit 68b2bc1
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Empty file added minikube/BUILD
Empty file.
66 changes: 66 additions & 0 deletions minikube/minikube.bzl
Original file line number Diff line number Diff line change
@@ -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.",
),
},
)

0 comments on commit 68b2bc1

Please sign in to comment.