devspace icon indicating copy to clipboard operation
devspace copied to clipboard

Defined `vars` will not be overwritten by `DEVSPACE_ENV_FILE: ".env"`

Open ethankhall opened this issue 3 years ago • 6 comments

What happened?

Defining a default value in the devspace.yaml file will not be overwritten by the .env file. I tried putting DEVSPACE_ENV_FILE: ".env" at the beginning and end of the vars.

When running devspace run-pipeline test I get

info Using namespace 'ethan-hall'
info Using kube context 'loft_ethan-hall_portland'
false

What did you expect to happen instead?

When running devspace run-pipeline test I get

info Using namespace 'ethan-hall'
info Using kube context 'loft_ethan-hall_portland'
true

How can we reproduce the bug? (as minimally and precisely as possible)

My devspace.yaml:

version: v2beta1
name: foo
vars:
  CLOUDDEV_AUTO_MIGRATE: false
  DEVSPACE_ENV_FILE: ".env"
functions:
  test_fun: |-
    echo ${CLOUDDEV_AUTO_MIGRATE}
pipelines:
  test: |-
    test_fun

My .env:

CLOUDDEV_AUTO_MIGRATE=true

Local Environment:

  • DevSpace Version: v6.0.0
  • Operating System: mac
  • ARCH of the OS: ARM64

/kind bug

ethankhall avatar Aug 25 '22 23:08 ethankhall

Playing around with this example verbatim, I can't even override CLOUDDEV_AUTO_MIGRATE with an explicit environment variable either:

`CLOUDDEV_AUTO_MIGRATE=true devspace print`
❯ CLOUDDEV_AUTO_MIGRATE=true devspace print

-------------------

Vars:

               NAME             |                       VALUE
  ------------------------------+----------------------------------------------------
    CLOUDDEV_AUTO_MIGRATE       | false
...
-------------------

Loaded path: /Users/adam.neumann/workspace/v6-vars/devspace.yaml

-------------------

version: v2beta1
name: foo
functions:
    test_fun: echo false
pipelines:
    test:
        run: test_fun

Reading the variable docs closely, it looks like CLOUDDEV_AUTO_MIGRATE is a static value and must be explicitly overridden with --var CLOUDDEV_AUTO_MIGRATE=foobar. This does change the value, but it's still not from the .env file:

`devspace-beta print --var CLOUDDEV_AUTO_MIGRATE=foobar`
❯ devspace-beta print --var CLOUDDEV_AUTO_MIGRATE=foobar

-------------------

Vars:

               NAME             |                       VALUE
  ------------------------------+----------------------------------------------------
    CLOUDDEV_AUTO_MIGRATE       | foobar
...
-------------------

Loaded path: /Users/adam.neumann/workspace/v6-vars/devspace.yaml

-------------------

version: v2beta1
name: foo
functions:
    test_fun: echo foobar
pipelines:
    test:
        run: test_fun

The section on env vars states that:

... without the need to explictly define them.

Removing the CLOUDDEV_AUTO_MIGRATE: false line results in the expected output to devspace run-pipeline test:

`devspace-beta run-pipeline test` fixed
❯ cat .env
CLOUDDEV_AUTO_MIGRATE=true

❯ cat devspace.yaml
version: v2beta1
name: foo
vars:
  DEVSPACE_ENV_FILE: ".env"
functions:
  test_fun: |-
    echo ${CLOUDDEV_AUTO_MIGRATE}
pipelines:
  test: |-
    test_fun

❯ devspace-beta run-pipeline test
17:40:43 info Using namespace 'adam-neumann'
17:40:43 info Using kube context 'loft_adam-neumann_portland'
17:40:43 true

but with the loss of the default false behavior:

Loss of default `false` behavior
❯ cat .env
#CLOUDDEV_AUTO_MIGRATE=true

❯ cat devspace.yaml
version: v2beta1
name: foo
vars:
  DEVSPACE_ENV_FILE: ".env"
functions:
  test_fun: |-
    echo ${CLOUDDEV_AUTO_MIGRATE}
pipelines:
  test: |-
    test_fun

❯ devspace-beta run-pipeline test
17:45:37 info Using namespace 'adam-neumann'
17:45:37 info Using kube context 'loft_adam-neumann_portland'
17:45:38

noizwaves avatar Aug 26 '22 00:08 noizwaves

It looks like the v1beta style default config is still available, and this appears to mitigate the issue:

With default value ✅
❯ cat .env
#CLOUDDEV_AUTO_MIGRATE=true

❯ cat devspace.yaml
version: v2beta1
name: foo
vars:
  CLOUDDEV_AUTO_MIGRATE:
    default: false
    source: env
  DEVSPACE_ENV_FILE: ".env"
functions:
  test_fun: |-
    echo ${CLOUDDEV_AUTO_MIGRATE}
pipelines:
  test: |-
    test_fun

❯ devspace-beta run-pipeline test
17:53:53 info Using namespace 'adam-neumann'
17:53:53 info Using kube context 'loft_adam-neumann_portland'
17:53:53 false
With override in .env ✅
❯ cat .env
CLOUDDEV_AUTO_MIGRATE=true

❯ cat devspace.yaml
version: v2beta1
name: foo
vars:
  CLOUDDEV_AUTO_MIGRATE:
    default: false
    source: env
  DEVSPACE_ENV_FILE: ".env"
functions:
  test_fun: |-
    echo ${CLOUDDEV_AUTO_MIGRATE}
pipelines:
  test: |-
    test_fun

❯ devspace-beta run-pipeline test
17:54:46 info Using namespace 'adam-neumann'
17:54:46 info Using kube context 'loft_adam-neumann_portland'
17:54:46 true

noizwaves avatar Aug 26 '22 00:08 noizwaves

@ethankhall @noizwaves thanks for creating this issue! The correct syntax is to use:

vars:
  MY_ENV_VAR:
    source: env
    default: my-default

which would be then overridable from the .env file as @noizwaves has suggested

FabianKramm avatar Aug 26 '22 09:08 FabianKramm

We'll also update the documentation for this

FabianKramm avatar Aug 26 '22 09:08 FabianKramm

@FabianKramm can you also update the parsing of v1beta11 into v2beta1 to show the values of vars?

When I run devspace print against the v1beta11, the only var in the yaml output is

vars:
    DEVSPACE_ENV_FILE:
        value: .env
        alwaysResolve: false

ethankhall avatar Aug 26 '22 15:08 ethankhall

@ethankhall variables should be shown separately within the devspace print section as these could change or not even be defined (in the case of environment variables), so the vars section would be incomplete anyways

FabianKramm avatar Aug 29 '22 08:08 FabianKramm