devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.32k stars 361 forks source link

Enhancement Request: Control over Interactive Input Sequence in Custom Pipeline Command #2779

Open Naveen-oops opened 9 months ago

Naveen-oops commented 9 months ago

Is your feature request related to a problem?

Problem Description

Scenario and expectation when I run the command devspace run-pipeline install , I would like to first ask the question where to install?

Current Behavior and Need for Clarity

Additional Context

Example: (My devspace file)

version: v2beta1
name: install

# has bash functions for custom installation ( installOnKind,  installOnRemoteNode )
imports:
  - path: "./installScripts.yaml"

vars:
  INSTALL:
    question: Where do you want to install the k8s application?
    options: ["local", "remote"]
    default: "local"
    noCache: true
  HOST:
    question: "Enter the hostname in which k8s is running?"
    noCache: true
  PASSWORD:
    question: "Enter the password:"
    password: true
    noCache: true
  USER_NAME:
    question: "Enter the username for the host?"
    default: "test"
    noCache: true

pipelines:
  install-application:
    run: |-
      if [ $INSTALL == "local" ]; then
        # steps to install the local kind k8s cluster and app
        installOnKind
        echo "local kind k8s cluster installed successfully !!!"
      else
        # steps to install the setup on remote node
        # here only I want to get user input for variables
        installOnRemoteNode $HOST $PASSWORD $USER_NAME
      fi

Which solution do you suggest?

  1. Sequential Prompting: Have control over the sequence of interactive prompts within the pipeline command.
  2. Clarification on Variable Declaration: Clarification on the possibility of declaring the 'question' variable inside the pipeline for better control over interactive prompts.

Which alternative solutions exist?

lizardruss commented 9 months ago

@Naveen-oops Thanks for submitting this request!

I came up with an example using commands that may give you some ideas. If it doesn't suit your needs, then lets continue discussing, since I think there's room to improve the user experience with vars.

devspace.yaml:

version: v2beta1

name: test-var

pipelines:
  dev: |
    echo "${ONE}"
    echo "${TWO}"
    echo "${THREE}"

commands:
  test-var: |-
    read -p "Can you spell?" spell
    if [ "$spell" = "yes" ]; then
      read -p "Spell 1?" one
      read -p "Spell 2?" two
      read -p "Spell 3?" three
      devspace dev --var ONE=$one --var TWO=$two --var THREE=$three
    else
      devspace dev --var ONE=one --var TWO=two --var THREE=three
    fi

output

❯ devspace run test-var
Can you spell?yes
Spell 1?eins
Spell 2?zwei
Spell 3?drei
info Using namespace 'loft'
info Using kube context 'kind-kind'
eins
zwei
drei
❯ devspace run test-var
Can you spell?no
info Using namespace 'loft'
info Using kube context 'kind-kind'
one
two
three
Naveen-oops commented 8 months ago

Thanks @lizardruss for your reply.

Yeah, the example you gave is helping, I can implement my use case with the help of that.

My suggestion would be instead of read, if we have any utility POSIX function exposed outside for accessing VAR functionality of devspace, it would be even good. Because the color , theme , and options provided by VAR will increase user experience.