Skip to content

Command env variables#99

Merged
idroz merged 2 commits intobravetools:masterfrom
Szubie:command-env-variables
Aug 18, 2022
Merged

Command env variables#99
idroz merged 2 commits intobravetools:masterfrom
Szubie:command-env-variables

Conversation

@Szubie
Copy link
Collaborator

@Szubie Szubie commented Jun 29, 2022

Passing environment variables to commands in the run section of a Bravefile currently has to be done using shell commands (sh -c 'TEST_VAR="test" ...'). Relying on the shell is not ideal and leans into an imperative style of programming, rather than the declarative style of the rest of the Bravefile.

The LXD client provides official support for passing environment variables to exec commands, which works reliably and with minimal changes to the code. A small extension to the Bravefile's command to include an "env" field that exposes this would allow for an easy, declarative way to pass env variables to commands that does not involve spinning up a shell process.

Additionally, being able to avoid the sh command tends to make the intent of the command clearer - see the example below.

Before:

run:
  - command: sh
    args:
      - -c
      - 'AUTH_ADDR=10.0.0.15:80 LOG_ADDR=10.0.0.25:8000 flask run'

After:

run:
  - command: flask
    args:
      - run
    env:
      AUTH_ADDR: 10.0.0.15:80
      LOG_ADDR: 10.0.0.25:8000

Szubie added 2 commits August 18, 2022 15:57
…al args for Exec function. This prevents the function signature getting too long.
…ronment variables will be available to the programs run by the command.
@Szubie Szubie force-pushed the command-env-variables branch from 34f5fa7 to 7879c84 Compare August 18, 2022 15:07
@idroz idroz merged commit da7945e into bravetools:master Aug 18, 2022
@Szubie Szubie deleted the command-env-variables branch September 3, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants