Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to read environment variables from a local file #2669

Closed
mildred opened this issue May 24, 2017 · 2 comments
Closed

Add ability to read environment variables from a local file #2669

mildred opened this issue May 24, 2017 · 2 comments

Comments

@mildred
Copy link
Contributor

mildred commented May 24, 2017

Currently, I have a nomad job running a docker container where some of the environment variables are generated using a nomad template. This is very useful to generate some of the environment variables from consul keys.

Currently, I'm overriding the run command with a sh -c command running a oneliner script. This works for this particular use case but it won't work for every docker image.

What would be nice is to have a possibility to define a list of files containing environment variables that would be read before running the task.

My current job looks like:

task "web" {
  driver = "docker"
  config {
    command = "sh"
    args = [
      "-c",
      "exec 2>&1; . /local/env; env | sort; exec bundle exec rails server -b 0.0.0.0"
    ]
    ...
  }

  ...

  template {
    destination = "local/env"
    data = <<TEMPLATE
export PROJECT_SERVER_URL=http://local-{{key_or_default "squarescale-web/forward-address" ""}}
TEMPLATE
  }
}

I'd prefer something like:

task "web" {
  driver = "docker"

  ...

  environment_files = [ "local/env" ]

  template {
    destination = "local/env"
    data = <<TEMPLATE
PROJECT_SERVER_URL=http://local-{{key_or_default "squarescale-web/forward-address" ""}}
TEMPLATE
  }
}
@schmichael
Copy link
Member

Great minds think alike! #2654 is almost ready and adds almost exactly the behavior you're asking for. The one difference is that instead of the environment_files=[...] key there's an env=true flag on each template you want to read in as an environment variable.

It will be in master soon and released in 0.6.

Closing this as a dupe of #1765 as that's the original inspiration for this feature.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants