0

I'm using Lando (v3.0.0-rc.21 on Windows 10 Enterprise) and trying to set up an environment variable on container creation in my .lando.yml:

services:
  appserver:
    type: ruby # the same for php, but didn't tested other types
  run:
    - export SOMENAME=somevalue

tooling:
  test:
    cmd: export SOMENAME=somevalue
    service: appserver

It looks like the command is not recognized while Lando starts since it throws: OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"export\": executable file not found in $PATH": unknown

The very same error occurs on lando ssh -c "export SOMENAME=somevalue" or adding it as a command into tooling section in .lando.yml (see above) and then running lando test.

However, running the same command from lando ssh after lando has started works as it should:

lando ssh
www-data@81bd623b9c3a:/app$ export SOMENAME=somevalue
www-data@81bd623b9c3a:/app$ printenv SOMENAME
somevalue
www-data@81bd623b9c3a:/app$

Is this a Lando bug? Or some (which?) shell commands should be called somehow different?

3 Answers3

2

you may use this env_file in lando yaml:

env_file:
  - defaults.env

in defaults.env:

SOMENAME=somevalue

see this

LinPy
  • 16,987
  • 4
  • 43
  • 57
  • Thanks! This does not resolves the issue, but could be a workaround indeed. – Eugen Baryshnikau Oct 09 '19 at 12:39
  • Setting overrides in lando.yml also works fine as a workaround: https://docs.lando.dev/config/services.html#overrides – Eugen Baryshnikau Oct 09 '19 at 12:40
  • you will not find a solution using `export SOMENAME=somevalue` since that will work only in the current session you need to define the variable using one of the two methods mentioned above – LinPy Oct 09 '19 at 12:47
  • Well, it does not work even for a current session... But setting environmental variables on the fly may be useful in tooling section to run the same scripts with different environment settings. Take for example a command like `WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server`. And it looks strange why it works via SSH but does not from a Lando config. – Eugen Baryshnikau Oct 09 '19 at 16:10
1

Just to pull this from the comments. Ended up with a workaround with Lando overrides like this:

services:
  appserver:
    type: ruby # or other type
    overrides:
      environment:
        SOMENAME: somevalue

Documentation: https://docs.lando.dev/config/services.html#overrides

Another workaround — as @LinPy suggests in his answer — is to use external env_file

0

If you want to have the variable available in the CLI you can do this:

events:
  post-start:
    - appserver: "export PHP_IDE_CONFIG=\"serverName=appserver\""

Run lando restart -y && lando ssh then check the value via printenv | grep PHP_IDE_CONFIG