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

Setting environment variables (for :start task, maybe :compile)? #213

Closed
pmeinhardt opened this issue Feb 9, 2018 · 10 comments
Closed

Setting environment variables (for :start task, maybe :compile)? #213

pmeinhardt opened this issue Feb 9, 2018 · 10 comments
Assignees
Labels
Milestone

Comments

@pmeinhardt
Copy link
Contributor

Hi, I hope you don’t mind me bothering you 🙂 Thanks a lot for your quick replies!
I was wondering what your strategy for environment variables with bootleg is.

More specifically: I would like to pass a PORT environment variable when starting an app. For now what I did is to override the :start task in the environment – obviously a hack:

# config/deploy/production.exs

use Bootleg.Config

# …

task :start do
  remote :app do
    "PORT=20673 bin/#{Bootleg.Config.app} start"
  end
  Bootleg.UI.info "#{Bootleg.Config.app} started"
  :ok
end

Unfortunately I don't have any control over what environment the system sets by default.

I bet there's a better way, maybe you can help me out?

@pmeinhardt pmeinhardt changed the title Setting environment variables (for start, maybe compile)? Setting environment variables (for :start task, maybe :compile)? Feb 9, 2018
@brienw
Copy link
Contributor

brienw commented Feb 9, 2018

For now we pass the responsibility down to distillery. Check out https://github.com/bitwalker/distillery/blob/master/docs/Runtime%20Configuration.md

the current gist is that you would set an ENV variable on your target host and then use the REPLACE_OS_VARS/vm.args mechanism to set run-time options.

We're kind of hoping that the research/work that bitwalker is doing around deploys for Dockyard results in a nicer way to handle runtime variables. He's giving a talk at Lonestar ElixirConf in a couple weeks and i'm hoping this topic comes up

@pmeinhardt
Copy link
Contributor Author

pmeinhardt commented Feb 9, 2018

It sounds like it might still be desirable for Bootleg to allow passing through environment variables to the :generate_release task so Distillery has a chance to pick them up?

task :generate_release do
UI.info "Generating release"
mix_env = config({:mix_env, "prod"})
source_path = config({:ex_path, ""})
remote :build, cd: source_path do
"MIX_ENV=#{mix_env} mix release"
end
end

@brienw
Copy link
Contributor

brienw commented Feb 9, 2018

yeah, that's a good point. we could just prepend any provided ENV vars to the mix release and start commands... i like it 👍

@brienw
Copy link
Contributor

brienw commented Feb 9, 2018

brainstorming:

role :build, "build.example.com", workspace: "/tmp/build/myapp", env: %{port: 1234, var2: "foo"}

then during task the env contents could be parsed and prepended:

MIX_ENV=prod PORT=1234 VAR2=foo ... mix release

@brienw brienw added this to the 0.8.0 milestone Feb 9, 2018
@brienw brienw added the feature label Feb 9, 2018
@pmeinhardt
Copy link
Contributor Author

That looks like a nice approach to me @brienw 👍

I think you probably meant to make the :env value a Map though [nitpick 😁]

@pmeinhardt
Copy link
Contributor Author

As an extra, it might be useful to add a BOOTLEG_ENV=<environment> to the environment variables in case people need to change release information based on the environment they deploy to. Just a thought…

@rjanja
Copy link
Contributor

rjanja commented Feb 12, 2018

👍 to env role option
👍 to BOOTLEG_ENV override

@brienw brienw self-assigned this Feb 12, 2018
@pmeinhardt
Copy link
Contributor Author

Awesome 🙌 So looking forward to this.

Currently I am overwriting the :start, :stop, :restart and :ping tasks per environment just to set a custom VMARGS_PATH environment variable, which works – whoop – but is pretty scary at the same time 😱

Let me know if you'd like me to test-drive any changes here or I can chip in.


On a side note: I also hope to work on SSHKit some more in whatever time I can find and hope to get around to things like connection caching which should make deployments slightly faster. I also have some vague ideas about an alternative "backend" from the Erlang default, which could allow for ssh-agent support. As a first step though, I am currently introducing Mox for unit testing and ironing out a few smaller inconsistencies.

I'd be more than happy to hear from you guys if you have any priorities on your wishlist for SSHKit 🙏

brienw added a commit that referenced this issue Feb 15, 2018
@brienw
Copy link
Contributor

brienw commented Feb 15, 2018

I'm gonna add another Issue to track the addition of an automatic BOOTLEG_ENV variable

@brienw
Copy link
Contributor

brienw commented Feb 15, 2018

Closed by [#218]

@brienw brienw closed this as completed Feb 15, 2018
brienw added a commit that referenced this issue Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants