Skip to content

Commit

Permalink
Provision and print endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Pröschel committed Mar 12, 2021
1 parent c27ee20 commit f5ebe6f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 170 deletions.
2 changes: 1 addition & 1 deletion docs/docs/concepts/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here's an outline of the process:
- We clean up the draft release and name it `x.y.z`
- We run `./scripts/release.sh start x.y.z`
- Once release days comes, we execute the following steps:
- We test our release (`./scripts/bootstrap.sh`) and any
- We test our release (`airy create --provider=local`) and any
additional hot-fix is committed directly to the release branch
- Once we're satisfied with the release, we finish the release by running `./scripts/release.sh finish x.y.z`
- We update the version string and the sha in the [Homebrew Formula](https://github.com/airyhq/homebrew-airy/blob/main/Formula/cli.rb) for the CLI.
Expand Down
1 change: 1 addition & 0 deletions infrastructure/cli/pkg/cmd/create/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
"//infrastructure/cli/pkg/providers",
"//infrastructure/cli/pkg/workspace",
"@com_github_spf13_cobra//:cobra",
"@com_github_spf13_viper//:viper",
"@io_k8s_api//batch/v1:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
"@io_k8s_api//rbac/v1:go_default_library",
Expand Down
40 changes: 30 additions & 10 deletions infrastructure/cli/pkg/cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"cli/pkg/providers"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
)

var (
provider string
namespace string
version string
CreateCmd = &cobra.Command{
providerName string
namespace string
version string
CreateCmd = &cobra.Command{
Use: "create",
Short: "Creates an instance of Airy Core",
Long: ``,
Expand All @@ -20,16 +21,16 @@ var (
)

func init() {
CreateCmd.Flags().StringVar(&provider, "provider", "local", "One of the supported providers (aws|local|minikube).")
CreateCmd.Flags().StringVar(&providerName, "provider", "local", "One of the supported providers (aws|local|minikube).")
CreateCmd.Flags().StringVar(&namespace, "namespace", "default", "(optional) Kubernetes namespace that Airy should be installed to.")
CreateCmd.MarkFlagRequired("provider")

}

func create(cmd *cobra.Command, args []string) {
fmt.Println("⚙️ Creating core with provider", provider)
fmt.Println("⚙️ Creating core with provider", providerName)

provider := providers.MustGet(providers.ProviderName(provider))
provider := providers.MustGet(providers.ProviderName(providerName))

context, err := provider.Provision()
if err != nil {
Expand All @@ -53,9 +54,28 @@ func create(cmd *cobra.Command, args []string) {
os.Exit(1)
}

viper.Set("KubeConfig", context.KubeConfigPath)
viper.Set("ContextName", context.ContextName)
if err = viper.WriteConfig(); err != nil {
fmt.Println("could not store the kube context: ", err)
os.Exit(1)
}

fmt.Println("🚀 Starting core with default components")
fmt.Println("🎉 Your Airy Core is ready")
fmt.Println("\t Link to the API")
fmt.Println("\t Link to the UI")
fmt.Println("\t Link to more docs")

hosts, err := provider.GetHosts()
if err != nil {
fmt.Println("failed to get installation endpoints: ", err)
os.Exit(1)
}

fmt.Println("\t Available hosts:")
for hostName, host := range hosts {
fmt.Printf("\t\t %s:\t %s", hostName, host)
}

fmt.Println()
fmt.Printf("For more information about the %s provider visit https://airy.co/docs/core/getting-started/installation/%s", providerName, providerName)
fmt.Println()
}
16 changes: 8 additions & 8 deletions infrastructure/cli/pkg/kube/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ import (
)

type KubeCtx struct {
kubeConfigPath string
contextName string
KubeConfigPath string
ContextName string
}

func New(kubeConfigPath, contextName string) KubeCtx {
return KubeCtx{
kubeConfigPath: kubeConfigPath,
contextName: contextName,
KubeConfigPath: kubeConfigPath,
ContextName: contextName,
}
}

func (c *KubeCtx) GetClientSet() (*kubernetes.Clientset, error) {
if c.contextName == "" {
config, err := clientcmd.BuildConfigFromFlags("", c.kubeConfigPath)
if c.ContextName == "" {
config, err := clientcmd.BuildConfigFromFlags("", c.KubeConfigPath)
if err != nil {
return nil, err
}

return kubernetes.NewForConfig(config)
}

file, err := clientcmd.LoadFromFile(c.kubeConfigPath)
file, err := clientcmd.LoadFromFile(c.KubeConfigPath)
if err != nil {
return nil, err
}

config, err := clientcmd.NewNonInteractiveClientConfig(*file, c.contextName, nil, nil).ClientConfig()
config, err := clientcmd.NewNonInteractiveClientConfig(*file, c.ContextName, nil, nil).ClientConfig()
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/cli/pkg/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (a *Aws) GetHelmOverrides() []string {
return []string{}
}

func (a *Aws) GetHosts() (map[string]string, error) {
return nil, nil
}

func (a *Aws) Provision() (kube.KubeCtx, error) {
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
Expand Down
28 changes: 23 additions & 5 deletions infrastructure/cli/pkg/providers/minikube/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"k8s.io/client-go/util/homedir"
"os/exec"
"path/filepath"
"strings"
)

const (
Expand Down Expand Up @@ -43,14 +44,31 @@ func checkInstallation() error {
}

func startCluster() error {
return runMinikube("start", "--driver=virtualbox", "--cpus=4", "--memory=7168")
return run("start", "--driver=virtualbox", "--cpus=4", "--memory=7168")
}

func runMinikube(args ...string) error {
func (m *Minikube) GetHosts() (map[string]string, error) {
endpoint, err := runWithOutput("--namespace=kube-system", "service", "--url", "traefik")
if err != nil {
return nil, err
}
coreId, err := runWithOutput("kubectl", "--", "get", "cm", "core-config", "-o", "jsonpath='{.data.CORE_ID}'")
ngrokEndpoint := fmt.Sprintf("https://%s.tunnel.airy.co", strings.TrimSpace(coreId))

return map[string]string{"Local": endpoint, "Ngrok": ngrokEndpoint}, err
}

func run(args ...string) error {
_, err := runWithOutput(args...)
return err
}

func runWithOutput(args ...string) (string, error) {
defaultArgs := []string{"--profile=" + profile}
cmd := exec.Command("minikube", append(defaultArgs, args...)...)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("running Minikube failed with err: %v\n%v", err, string(out))
out, err := cmd.CombinedOutput()
if err != nil {
return string(out), fmt.Errorf("running Minikube failed with err: %v\n%v", err, string(out))
}
return nil
return string(out), nil
}
1 change: 1 addition & 0 deletions infrastructure/cli/pkg/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (

type Provider interface {
Provision() (kube.KubeCtx, error)
GetHosts() (map[string]string, error)
GetHelmOverrides() []string
}

Expand Down
146 changes: 0 additions & 146 deletions scripts/bootstrap.sh

This file was deleted.

0 comments on commit f5ebe6f

Please sign in to comment.