Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy to Heroku button with env variables

Tags:

heroku

I'd like to add a "Deploy to Heroku" button to my application hosted on GitHub, but the only problem is it requires env variables to run, and will require the user to enter them before it will work. Is there a way in the app.json schema to prompt the user prior to install to set these up? Or is my best bet setting them to a standard string such as "replace_me" and telling the users to enter their data from there in my readme file.

I saw that you could generate a "secret" in their documentation but I'm not sure if that's what I'm looking for.

like image 833
James Ives Avatar asked May 17 '17 13:05

James Ives


People also ask

Does Heroku use .ENV file?

Heroku Local is a command-line tool to run Procfile-backed apps. It is installed automatically as part of the Heroku CLI. Heroku Local reads configuration variables from a . env file.

How do I view env variables in Heroku?

Once you are on the "Settings" page, scroll until you see the "Config Vars" section. To add config vars (environment variables) or modify the existing ones, click on "Reveal Config Vars". Since you do not have any config vars, you should see the same message as shown in Figure 4.

Can you deploy to Heroku without git?

You can use https://github.com/ddollar/heroku-push and push directories without git.


1 Answers

You may have found this already, but it looks like you define the env variables in the app.json schema. (Described more in detail here: https://blog.heroku.com/introducing_the_app_json_application_manifest)

The example schema they provide:

{
  "name": "Ruby on Rails",
  "description": "A template for getting started with the popular Ruby framework.",
  "website": "http://rubyonrails.org",
  "success_url": "/welcome",
  "addons": ["heroku-postgresql:hobby-dev", "papertrail"],
  "env": {
    "RAILS_ENV": "production",
    "COOKIE_SECRET": {
            "description": "This gets generated",
            "generator": "secret"
    },
    "SETUP_BY": {
            "description": "Who initiated this setup",
            "value": ""
    }
  },
  "scripts": {
    "postdeploy": "bundle exec rake db:migrate"
  }
}

Then, when you visit this deploy URL, you pass in the path to your Github repository where the app.json file lives, as well as any hard-coded ENV variables in the URL:

https://heroku.com/deploy?template=https://github.com/rauchg/slackin/tree/0.5.1& env[SLACK_SUBDOMAIN]=testdomain

When you visit the URL, it will automatically generate a form prompting you to enter the remaining env values.

Here's an example form generated by an app config I made here:

enter image description here

When the app deploys, it stores the values the user entered in the correct environment variables.

like image 59
ninapavlich Avatar answered Sep 29 '22 05:09

ninapavlich