Commit ede8cfcd authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

refactor: split meepctl deploy into dep/core subcommands with 'all' target

- Split 'meepctl deploy' into 'meepctl deploy dep' and 'meepctl deploy core' subcommands
- Require explicit 'all' target to deploy everything (matching dockerize pattern)
- Show valid targets list in help output for both subcommands
- Add ANSI colors to help output (error, header, targets) for better visibility
- Update Ansible playbook, RUNBOOK, and shell scripts with new 'all' argument

BREAKING: 'meepctl deploy dep' and 'meepctl deploy core' now show help instead
of deploying everything. Use 'meepctl deploy dep all' / 'meepctl deploy core all'.
parent bf57c64c
Loading
Loading
Loading
Loading
+150 −58
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"fmt"
	"os"
	"os/exec"
	"sort"
	"strconv"
	"strings"
	"time"
@@ -53,23 +54,57 @@ Optional registry & tag parameters allows to specify a shared registry & tag for
Default registry is configured in ~/.meepctl.yaml.
Defaut tag is: latest`

const deployExample = `  # Deploy AdvantEDGE dependencies
  meepctl deploy dep
const deployDepDesc = `Deploy dependency containers on the K8s cluster

Deploy dep command deploys dependency containers in the K8s cluster.
Multiple targets can be specified (e.g. meepctl deploy dep <target1> <target2>...)`

const deployDepExample = `  # Deploy all dependencies
  meepctl deploy dep all
  # Deploy a single dependency
  meepctl deploy dep meep-couchdb
  meepctl deploy dep meep-couchdb`

const deployCoreDesc = `Deploy core containers on the K8s cluster

Deploy core command deploys core containers in the K8s cluster.
Multiple targets can be specified (e.g. meepctl deploy core <target1> <target2>...)`

const deployCoreExample = `  # Deploy all core components
  meepctl deploy core all
  # Deploy a single core component
  meepctl deploy core meep-platform-ctrl
  # Delete and re-deploy only AdvantEDGE core containers
  meepctl deploy core --force
  meepctl deploy core all --force
  # Deploy AdvantEDGE version 1.0.0 from my.registry.com
  meepctl deploy core --registry my.registry.com --tag 1.0.0`
  meepctl deploy core all --registry my.registry.com --tag 1.0.0`

// deployCmd represents the deploy command
// deployCmd represents the parent deploy command
var deployCmd = &cobra.Command{
	Use:     "deploy <group> [app]",
	Use:   "deploy",
	Short: "Deploy containers on the K8s cluster",
	Long:  deployDesc,
	Example: deployExample,
	Args:    cobra.RangeArgs(1, 2),
	Run:     deployRun,
}

// deployDepCmd represents the deploy dep subcommand
var deployDepCmd = &cobra.Command{
	Use:       "dep <targets>",
	Short:     "Deploy dependency containers on the K8s cluster",
	Long:      deployDepDesc,
	Example:   deployDepExample,
	Args:      cobra.OnlyValidArgs,
	ValidArgs: nil,
	Run:       deployDepRun,
}

// deployCoreCmd represents the deploy core subcommand
var deployCoreCmd = &cobra.Command{
	Use:       "core <targets>",
	Short:     "Deploy core containers on the K8s cluster",
	Long:      deployCoreDesc,
	Example:   deployCoreExample,
	Args:      cobra.OnlyValidArgs,
	ValidArgs: nil,
	Run:       deployCoreRun,
}

var deployData DeployData
@@ -81,58 +116,64 @@ func init() {
	deployData.sboxApps = utils.GetTargets("repo.sandbox.go-apps", "deploy")
	deployData.depApps = utils.GetTargets("repo.dep", "deploy")

	// Configure the list of valid arguments
	deployCmd.ValidArgs = []string{"dep", "core"}

	// Add list of arguments to Example usage
	deployCmd.Example += "\n\nValid Targets:"
	for _, arg := range deployCmd.ValidArgs {
		deployCmd.Example += "\n  * " + arg
	}

	// Set deploy-specific flags
	deployCmd.Flags().BoolP("force", "f", false, "Deployed components are deleted and deployed")
	deployCmd.Flags().BoolVar(&deployData.codecov, "codecov", false, "Use when deploying code coverage binaries (dev. option)")
	deployCmd.Flags().BoolVar(&deployData.onboardedapp, "onboardedapp", false, "Use when shared folder with host (meep-dai)")
	deployCmd.Flags().StringP("registry", "r", "", "Override registry from config file")
	deployCmd.Flags().StringP("tag", "", "latest", "Repo tag to use")
	// Build valid args for deploy dep
	depBaseArgs := []string{"all"}
	depConfigArgs := make([]string, len(deployData.depApps))
	copy(depConfigArgs, deployData.depApps)
	sort.Strings(depConfigArgs)
	deployDepCmd.ValidArgs = append(depBaseArgs, depConfigArgs...)

	// Add list of arguments to dep Example usage
	deployDepCmd.Example += "\n\n" + utils.FormatHeader("Valid Targets:")
	for _, arg := range deployDepCmd.ValidArgs {
		deployDepCmd.Example += "\n  * " + utils.FormatStep(arg)
	}

	// Build valid args for deploy core
	coreBaseArgs := []string{"all"}
	coreConfigArgs := make([]string, len(deployData.coreApps))
	copy(coreConfigArgs, deployData.coreApps)
	sort.Strings(coreConfigArgs)
	deployCoreCmd.ValidArgs = append(coreBaseArgs, coreConfigArgs...)

	// Add list of arguments to core Example usage
	deployCoreCmd.Example += "\n\n" + utils.FormatHeader("Valid Targets:")
	for _, arg := range deployCoreCmd.ValidArgs {
		deployCoreCmd.Example += "\n  * " + utils.FormatStep(arg)
	}

	// Set deploy-specific flags on each subcommand
	deployDepCmd.Flags().BoolP("force", "f", false, "Deployed components are deleted and deployed")
	deployDepCmd.Flags().BoolVar(&deployData.codecov, "codecov", false, "Use when deploying code coverage binaries (dev. option)")
	deployDepCmd.Flags().BoolVar(&deployData.onboardedapp, "onboardedapp", false, "Use when shared folder with host (meep-dai)")
	deployDepCmd.Flags().StringP("registry", "r", "", "Override registry from config file")
	deployDepCmd.Flags().StringP("tag", "", "latest", "Repo tag to use")

	deployCoreCmd.Flags().BoolP("force", "f", false, "Deployed components are deleted and deployed")
	deployCoreCmd.Flags().BoolVar(&deployData.codecov, "codecov", false, "Use when deploying code coverage binaries (dev. option)")
	deployCoreCmd.Flags().BoolVar(&deployData.onboardedapp, "onboardedapp", false, "Use when shared folder with host (meep-dai)")
	deployCoreCmd.Flags().StringP("registry", "r", "", "Override registry from config file")
	deployCoreCmd.Flags().StringP("tag", "", "latest", "Repo tag to use")

	// Add subcommands
	deployCmd.AddCommand(deployDepCmd)
	deployCmd.AddCommand(deployCoreCmd)

	// Add command
	rootCmd.AddCommand(deployCmd)
}

func deployRun(cmd *cobra.Command, args []string) {
	if !utils.ConfigValidate("") {
		fmt.Println("Fix configuration issues")
		return
	}

	group := args[0]
	var targetApp string
	if len(args) > 1 {
		targetApp = args[1]
	}

func deploySetup(cmd *cobra.Command) {
	deployData.registry, _ = cmd.Flags().GetString("registry")
	deployData.tag, _ = cmd.Flags().GetString("tag")
	f, _ := cmd.Flags().GetBool("force")
	v, _ := cmd.Flags().GetBool("verbose")
	t, _ := cmd.Flags().GetBool("time")

	if v {
		fmt.Println("Deploy called")
		fmt.Println("[arg]  group:", group)
		if targetApp != "" {
			fmt.Println("[arg]  app:", targetApp)
		}
		fmt.Println("[arg]  registry:", deployData.registry)
		fmt.Println("[arg]  tag:", deployData.tag)
		fmt.Println("[flag] force:", f)
		fmt.Println("[flag] verbose:", v)
		fmt.Println("[flag] time:", t)
	}

	start := time.Now()

	// Retrieve registry from config file if not already set
	if deployData.registry == "" {
		deployData.registry = viper.GetString("meep.registry")
@@ -146,21 +187,72 @@ func deployRun(cmd *cobra.Command, args []string) {

	// Ensure local storage
	deployEnsureStorage(cmd)
}

	// Deploy microservices
	switch group {
	case "core":
		if targetApp != "" {
			deploySingleApp(targetApp, cmd)
		} else {
			deployCore(cmd)
func deployDepRun(cmd *cobra.Command, args []string) {
	if !utils.ConfigValidate("") {
		fmt.Println("Fix configuration issues")
		return
	}
	case "dep":
		if targetApp != "" {
			deploySingleDepApp(targetApp, cmd)
		} else {

	targets := args
	if len(targets) == 0 {
		fmt.Println(utils.FormatError("Error: Need to specify at least one target"))
		_ = cmd.Usage()
		return
	}

	v, _ := cmd.Flags().GetBool("verbose")
	t, _ := cmd.Flags().GetBool("time")
	if v {
		fmt.Println("[arg]  targets:", targets)
	}

	start := time.Now()
	deploySetup(cmd)

	for _, target := range targets {
		if target == "all" {
			createCRD(cmd)
			deployDep(cmd)
		} else {
			deploySingleDepApp(target, cmd)
		}
	}

	elapsed := time.Since(start)
	if t {
		fmt.Println("Took ", elapsed.Round(time.Millisecond).String())
	}
}

func deployCoreRun(cmd *cobra.Command, args []string) {
	if !utils.ConfigValidate("") {
		fmt.Println("Fix configuration issues")
		return
	}

	targets := args
	if len(targets) == 0 {
		fmt.Println(utils.FormatError("Error: Need to specify at least one target"))
		_ = cmd.Usage()
		return
	}

	v, _ := cmd.Flags().GetBool("verbose")
	t, _ := cmd.Flags().GetBool("time")
	if v {
		fmt.Println("[arg]  targets:", targets)
	}

	start := time.Now()
	deploySetup(cmd)

	for _, target := range targets {
		if target == "all" {
			deployCore(cmd)
		} else {
			deploySingleApp(target, cmd)
		}
	}

+3 −3
Original line number Diff line number Diff line
@@ -76,9 +76,9 @@ func init() {
	dockerizeCmd.ValidArgs = append(baseArgs, configArgs...)

	// Add list of arguments to Example usage
	dockerizeCmd.Example += "\n\nValid Targets:"
	dockerizeCmd.Example += "\n\n" + utils.FormatHeader("Valid Targets:")
	for _, arg := range dockerizeCmd.ValidArgs {
		dockerizeCmd.Example += "\n  * " + arg
		dockerizeCmd.Example += "\n  * " + utils.FormatStep(arg)
	}

	// Set dockerize-specific flags
@@ -97,7 +97,7 @@ func dockerizeRun(cmd *cobra.Command, args []string) {

	targets := args
	if len(targets) == 0 {
		fmt.Println("Error: Need to specify at least one target")
		fmt.Println(utils.FormatError("Error: Need to specify at least one target"))
		_ = cmd.Usage()
		return
	}
+3 −3
Original line number Diff line number Diff line
@@ -158,11 +158,11 @@ This role builds and deploys all MEC Sandbox components:
   cd etsi-mec-sandbox-frontend && bash build.sh && bash deploy.sh
   ```
5. **Configure Secrets**: Runs `configure-secrets.py set`
6. **Deploy Dependencies**: `meepctl deploy dep` (with up to 3 retries using `-f` flag)
6. **Deploy Dependencies**: `meepctl deploy dep all` (with up to 3 retries using `-f` flag)
7. **Build All**: `meepctl build --nolint all`
8. **Dockerize All**: `meepctl dockerize all` (runs via `sg docker`)
9. **Prune Docker Images**: `docker image prune -f`
10. **Deploy Core**: `meepctl deploy core`
10. **Deploy Core**: `meepctl deploy core all`

---

@@ -243,7 +243,7 @@ source ~/etsi-mec-sandbox/playbooks/ansible-venv/bin/activate
```

### Thanos/Prometheus Deployment Failures
During `meepctl deploy dep`, thanos and prometheus failures are **expected and ignored**. The deployment will continue.
During `meepctl deploy dep all`, thanos and prometheus failures are **expected and ignored**. The deployment will continue.

### Repository Not Found Errors
Ensure both repositories are cloned as siblings:
+5 −5
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@
# --- Deploy dependencies (with retries, ignoring thanos/prometheus failures) ---

- name: "Deploy dependencies (meepctl deploy dep)"
  shell: "meepctl deploy dep 2>&1 | tee /tmp/meepctl_deploy_dep.log"
  shell: "meepctl deploy dep all 2>&1 | tee /tmp/meepctl_deploy_dep.log"
  args:
    executable: /bin/bash
    chdir: "{{ mec_sandbox_dir }}"
@@ -148,7 +148,7 @@
    msg: "{{ dep_deploy.stdout_lines | default([]) }}"

- name: "Retry deploy dep with force if failed (attempt 1 of 3)"
  shell: "meepctl deploy dep -f 2>&1 | tee /tmp/meepctl_deploy_dep_retry1.log"
  shell: "meepctl deploy dep all -f 2>&1 | tee /tmp/meepctl_deploy_dep_retry1.log"
  args:
    executable: /bin/bash
    chdir: "{{ mec_sandbox_dir }}"
@@ -163,7 +163,7 @@
  ignore_errors: true

- name: "Retry deploy dep with force if failed (attempt 2 of 3)"
  shell: "meepctl deploy dep -f 2>&1 | tee /tmp/meepctl_deploy_dep_retry2.log"
  shell: "meepctl deploy dep all -f 2>&1 | tee /tmp/meepctl_deploy_dep_retry2.log"
  args:
    executable: /bin/bash
    chdir: "{{ mec_sandbox_dir }}"
@@ -178,7 +178,7 @@
  ignore_errors: true

- name: "Retry deploy dep with force if failed (attempt 3 of 3)"
  shell: "meepctl deploy dep -f 2>&1 | tee /tmp/meepctl_deploy_dep_retry3.log"
  shell: "meepctl deploy dep all -f 2>&1 | tee /tmp/meepctl_deploy_dep_retry3.log"
  args:
    executable: /bin/bash
    chdir: "{{ mec_sandbox_dir }}"
@@ -273,7 +273,7 @@
# --- Deploy core ---

- name: "Deploy core (meepctl deploy core)"
  shell: "meepctl deploy core 2>&1 | tee /tmp/meepctl_deploy_core.log"
  shell: "meepctl deploy core all 2>&1 | tee /tmp/meepctl_deploy_core.log"
  args:
    executable: /bin/bash
    chdir: "{{ mec_sandbox_dir }}"
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ stop_etsi_mec_sandbox() {
}

build_etsi_mec_sandbox() {
    meepctl deploy dep
    meepctl deploy dep all
    sleep $TIMEOUT
    rm -fr $ADV_PATH/bin/meep-*
    if [ "$DO_NOT_BUILD_EX" != "--noexamplesbuilt" ]; then
Loading