*: do not require env.sh
This removes the need to source env.{sh,fish} when working with hscloud.
This is done by:
1. Implementing a Go library to reliably detect the location of the
active hscloud checkout. That in turn is enabled by
BUILD_WORKSPACE_DIRECTORY being now a thing in Bazel.
2. Creating a tool `hscloud`, with a command `hscloud workspace` that
returns the workspace path.
3. Wrapping this tool to be accessible from Python and Bash.
4. Bumping all users of hscloud_root to use either the Go library or
one of the two implemented wrappers.
We also drive-by replace tools/install.sh to be a proper sh_binary, and
make it yell at people if it isn't being ran as `bazel run
//tools:install`.
Finally, we also drive-by delete cluster/tools/nixops.sh which was never used.
Change-Id: I7873714319bfc38bbb930b05baa605c5aa36470a
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1169
Reviewed-by: informatic <informatic@hackerspace.pl>
diff --git a/cluster/prodaccess/BUILD.bazel b/cluster/prodaccess/BUILD.bazel
index 6c72082..4db48dd 100644
--- a/cluster/prodaccess/BUILD.bazel
+++ b/cluster/prodaccess/BUILD.bazel
@@ -13,6 +13,7 @@
"//cluster/certs:go_default_library",
"//cluster/prodvider/proto:go_default_library",
"//go/pki:go_default_library",
+ "//go/workspace:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
diff --git a/cluster/prodaccess/kubernetes.go b/cluster/prodaccess/kubernetes.go
index 7226423..c50cd07 100644
--- a/cluster/prodaccess/kubernetes.go
+++ b/cluster/prodaccess/kubernetes.go
@@ -14,17 +14,18 @@
"github.com/golang/glog"
pb "code.hackerspace.pl/hscloud/cluster/prodvider/proto"
+ "code.hackerspace.pl/hscloud/go/workspace"
)
func kubernetesPaths() (string, string, string) {
- localRoot := os.Getenv("hscloud_root")
- if localRoot == "" {
- glog.Exitf("Please source env.sh")
+ ws, err := workspace.Get()
+ if err != nil {
+ glog.Exitf("%v", err)
}
- localKey := path.Join(localRoot, ".kubectl", fmt.Sprintf("%s.key", flagUsername))
- localCert := path.Join(localRoot, ".kubectl", fmt.Sprintf("%s.crt", flagUsername))
- localCA := path.Join(localRoot, ".kubectl", fmt.Sprintf("ca.crt"))
+ localKey := path.Join(ws, ".kubectl", fmt.Sprintf("%s.key", flagUsername))
+ localCert := path.Join(ws, ".kubectl", fmt.Sprintf("%s.crt", flagUsername))
+ localCA := path.Join(ws, ".kubectl", fmt.Sprintf("ca.crt"))
return localKey, localCert, localCA
}