86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"oc-k8s/utils"
|
|
"os"
|
|
)
|
|
|
|
var REPOS = []string{
|
|
"oc-auth",
|
|
"oc-catalog",
|
|
"oc-datacenter",
|
|
"oc-front",
|
|
"oc-monitord",
|
|
"oc-peer",
|
|
"oc-shared",
|
|
"oc-scheduler",
|
|
"oc-schedulerd",
|
|
"oc-workflow",
|
|
"oc-workspace",
|
|
}
|
|
|
|
func Help_Service() {
|
|
fmt.Println(`
|
|
Service commands: oc-k8s <action> services
|
|
create - Build all opencloud services
|
|
help - Show this help message
|
|
|
|
Usage:
|
|
oc-k8s create services [env_folder] [branch] [target]
|
|
env_folder - Helm config folder (required, default: .)
|
|
branch - Git branch to build (default: main)
|
|
target - make target (default: all)
|
|
oc-k8s help services `)
|
|
}
|
|
|
|
func Create_Service(args ...string) error {
|
|
folder := "."
|
|
release := "dev"
|
|
branch := "main"
|
|
target := "all"
|
|
|
|
if len(args) > 0 {
|
|
folder = args[0]
|
|
}
|
|
if len(args) > 1 {
|
|
release = args[1]
|
|
}
|
|
if len(args) > 3 {
|
|
branch = args[3]
|
|
}
|
|
if len(args) > 4 {
|
|
target = args[4]
|
|
}
|
|
hostname := "beta.opencloud.com"
|
|
if b, err := os.ReadFile(folder + "/" + release + "-values.yaml"); err == nil {
|
|
hostname, _ = utils.Extract(string(b), "host")
|
|
}
|
|
|
|
for _, repo := range REPOS {
|
|
repo_url := "https://cloud.o-forge.io/core/" + repo + ".git"
|
|
host := "$(ip -4 addr show $(ip route | awk '/default/ {print $5}') | awk '/inet / {print $2}' | cut -d/ -f1)"
|
|
port := "6443"
|
|
ca := "$(kubectl config view --raw --minify -o jsonpath='{.clusters[0].cluster.certificate-authority-data}')"
|
|
cert := "$(kubectl config view --raw --minify -o jsonpath='{.users[0].user.client-certificate-data}')"
|
|
key := "$(kubectl config view --raw --minify -o jsonpath='{.users[0].user.client-key-data}')"
|
|
|
|
if inf, err := os.Stat("./" + repo); err != nil || !inf.IsDir() {
|
|
fmt.Println("Cloning repository: " + repo)
|
|
if err := utils.Exec("git clone " + repo_url); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
fmt.Println("Repository '" + repo + "' now exists. Pulling latest changes...")
|
|
if err := utils.Exec("cd " + repo + " && git checkout " + branch + " && git pull"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := utils.Exec("cd " + repo + " && export HOST=" + hostname + " && export KUBERNETES_SERVICE_HOST=" + host + " && export KUBERNETES_SERVICE_PORT=" + port + " && export KUBE_CA=" + ca + " && export KUBE_CERT=" + cert + " && export KUBE_DATA=" + key + " && make " + target); err != nil {
|
|
return err
|
|
}
|
|
|
|
}
|
|
return nil
|
|
}
|