Simplify installation scripts and update dev.md with instructions of how to use them
diff --git a/bazel_tools/helm.bzl b/bazel_tools/helm.bzl
index 7b71492..6accf8b 100644
--- a/bazel_tools/helm.bzl
+++ b/bazel_tools/helm.bzl
@@ -26,6 +26,10 @@
helm --namespace={namespace} install --create-namespace {release_name} \$$CHART_TARBALL {args}
"""
+__HELM_UNINSTALL_TMPL = """
+helm --namespace={namespace} uninstall {release_name}
+"""
+
def helm_install(name, namespace, release_name, chart, args):
args_str = ""
for arg, value in args.items():
@@ -44,7 +48,7 @@
package = native.package_name(),
chart = "%s.tar.gz" % chart.split(":")[1],
args = args_str,
- ))
+ ))
native.sh_binary(
name = name,
srcs = ["helm_install.sh",],
@@ -53,4 +57,21 @@
],
deps = [
"@bazel_tools//tools/bash/runfiles",
- ])
+ ])
+
+def helm_uninstall(name, namespace, release_name):
+ native.genrule(
+ name = "%s.sh" % name,
+ executable = False,
+ outs = ["helm_uninstall.sh",],
+ cmd = """cat > $@ <<EOM
+%s
+EOM
+""" % __HELM_UNINSTALL_TMPL.format(
+ namespace = namespace,
+ release_name = release_name,
+ ))
+ native.sh_binary(
+ name = name,
+ srcs = ["helm_uninstall.sh",]
+ )
diff --git a/core/api/BUILD b/core/api/BUILD
index 48e6b37..8ea877a 100644
--- a/core/api/BUILD
+++ b/core/api/BUILD
@@ -1,5 +1,5 @@
load("//:bazel_tools/docker.bzl", "docker_image")
-load("//:bazel_tools/helm.bzl", "helm_install")
+load("//:bazel_tools/helm.bzl", "helm_install", "helm_uninstall")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
# TODO(lekva): figure out how to build py_binary with pip dependencies and
@@ -30,3 +30,9 @@
"image.pullPolicy": "Always",
},
)
+
+helm_uninstall(
+ name = "uninstall",
+ namespace = "pcloud",
+ release_name = "init",
+)
diff --git a/core/appmanager/BUILD b/core/appmanager/BUILD
index ac84729..3ba5e53 100644
--- a/core/appmanager/BUILD
+++ b/core/appmanager/BUILD
@@ -1,5 +1,5 @@
load("//:bazel_tools/docker.bzl", "docker_image")
-load("//:bazel_tools/helm.bzl", "helm_install")
+load("//:bazel_tools/helm.bzl", "helm_install", "helm_uninstall")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
# TODO(lekva): figure out how to build py_binary with pip dependencies and
@@ -30,3 +30,9 @@
"image.pullPolicy": "Always",
},
)
+
+helm_uninstall(
+ name = "uninstall",
+ namespace = "pcloud-app-manager",
+ release_name = "init",
+)
diff --git a/core/events/BUILD b/core/events/BUILD
index 71bacea..aaf0d51 100644
--- a/core/events/BUILD
+++ b/core/events/BUILD
@@ -1,5 +1,5 @@
load("//:bazel_tools/docker.bzl", "docker_image")
-load("//:bazel_tools/helm.bzl", "helm_install")
+load("//:bazel_tools/helm.bzl", "helm_install", "helm_uninstall")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
# TODO(lekva): figure out how to build py_binary with pip dependencies and
@@ -30,3 +30,9 @@
"image.pullPolicy": "Always",
},
)
+
+helm_uninstall(
+ name = "uninstall",
+ namespace = "pcloud-event-processor",
+ release_name = "init",
+)
diff --git a/dev/create_dev_cluster.sh b/dev/create_dev_cluster.sh
index e6b01e1..54e66af 100755
--- a/dev/create_dev_cluster.sh
+++ b/dev/create_dev_cluster.sh
@@ -1,6 +1,7 @@
#!/bin/bash
-ROOT="$(dirname -- $(pwd))"
+ROOT=$(pwd)
+ROOT=${ROOT%/pcloud*}/pcloud
k3d cluster create pcloud-dev \
--servers=1 \
@@ -12,8 +13,7 @@
# Traefik
helm repo add traefik https://containous.github.io/traefik-helm-chart
helm repo update
-kubectl create namespace traefik
-helm --namespace=traefik install traefik traefik/traefik \
+helm --namespace=traefik install --create-namespace traefik traefik/traefik \
--set additionalArguments="{--providers.kubernetesingress,--global.checknewversion=true}" \
--set ports.traefik.expose=True
diff --git a/dev/install_core_services.sh b/dev/install_core_services.sh
index 0a7601f..1ab542a 100755
--- a/dev/install_core_services.sh
+++ b/dev/install_core_services.sh
@@ -1,6 +1,7 @@
#!/bin/sh
-ROOT="$(dirname -- $(pwd))"
+ROOT=$(pwd)
+ROOT=${ROOT%/pcloud*}/pcloud
# Dgraph
source $ROOT/apps/dgraph/install.sh
diff --git a/docs/dev.md b/docs/dev.md
index 7f6553f..c34b788 100644
--- a/docs/dev.md
+++ b/docs/dev.md
@@ -2,14 +2,32 @@
## Prerequisites
PCloud uses following tools to build and deploy it's packages:
-* Docker - To build container images: https://helm.sh/docs/intro/install/
+* Docker - To build container images: https://docs.docker.com/get-docker/
* k3d - To create local Kubernetes cluster for development environment: https://k3d.io/#installation
* kubectl - To interacto with the cluster: https://kubectl.docs.kubernetes.io/installation/kubectl/
* Helm - To package and distributes both PCloud core services and applications running on it: https://helm.sh/docs/intro/install/
Each of these tools provide multiple ways of installing them, choose the one which best suits you and your Host OS.
+# Development Instructions
+
## Installing PCloud
PCloud installation is two step process:
-1) First local Kubernetes cluster has to be created: ./dev/create_dev_cluster.sh
-2) Now we can install PCloud core services top of it: ./dev/install_core_services.sh
+> ./dev/create_dev_cluster.sh # creates local Kubernetes cluster
+> ./dev/install_core_services.sh # installs PCloud core services
+
+## Installing applications
+Under apps/ directory one can find number of sample application for PCloud. Installing any of those requires building container image, creating Helm Chart tarball and uploading it to Application Manager.
+Let's see what that looks like for rpuppy application:
+> bazel run //apps/rpuppy:push_to_dev # builds and pushes container image to localhost:30500 container registry, which is running inside PCloud cluster
+> bazel build //apps/rpuppy:chart # creates Helm Chart tartball which can be found at bazel-bin/apps/rpuppy/chart.tar.gz
+
+## Redeploying core services
+To redeploy one of the core services after making changes in it you have to rebuild container images and restart the running service. Let's see what that looks like for API Service:
+> bazel run //core/api:push_to_dev # builds and pushes container image to localhost:30500 container registry, which is running inside PCloud cluster
+> kubectl -n pcloud rollout restart deployment/api
+
+Reflecting changes in the chart configuration requires reinstallation of the chart itself:
+> bazel build //core/api:chart # creates chart tarball
+> bazel run //core/api:uninstall # uninstalls old Helm Chart from the cluster
+> bazel run //core/api:install # installs new Helm Chart to the cluster