Setting Dokku environment variables
Asked Answered
S

2

6

I'm trying to set Some variables on Dokku for deployment. As far as i can see from the dev files, one should create a .env file in the directory and put the variables in there. But this is not updating anything

.env file

DOKKU_NGINX_PORT=3000
MYSQL_URL=http://blabla
MYSQL_USER=mysqluser

I'm trying to map the port of the app to port 3000, and inject the mysql vars into the runtime environment.

I know I can set it with dokku config:set on the server, but I want to be able to automate it during deployment.

Any ideas? Or an example?

Serpasil answered 30/11, 2017 at 13:41 Comment(0)
D
7

You'll need to install a Dokku client, or CLI in order to locally interact with the remote application on your Dokku instance.

Here are a few options:

  • (node.js) dokku-toolbelt

    Dokku toolbelt is a node-based CLI wrapper that proxies requests to the Dokku command running on remote hosts.

You can install it via the following shell command (assuming you have node and npm installed):

$ npm install -g dokku-toolbelt

See documentation here for more information.

  • (python) dokku-client

    Dokku client is an extensible python-based cli wrapper for remote Dokku hosts.

You can install it via the following shell command (assuming you have python and pip installed):

$ pip install dokku-client

See documentation here for more information.

  • (ruby) Dokku CLI

    Dokku CLI is a rubygem that acts as a client for your Dokku installation.

You can install it via the following shell command (assuming you have ruby and rubygems installed):

$ gem install dokku-cli

See documentation here for more information.


After the Dokku client is installed locally, make sure that the dokku app remote is set inside the repository directory.

You can verify this by running $ git remote -v.

If the output doesn't show your dokku application instance, set it with the following command:

$ git remote add dokku [email protected]:your-app-name

Here's an example from my terminal with some information redacted for security purposes.

    seth@linuxmint ~/repos/Adopt-a-Pet $ git remote -v
    dokku   [email protected]:adopt-a-pet (fetch)
    dokku   [email protected]:adopt-a-pet (push)
    origin  https://github.com/sethbergman/Adopt-a-Pet.git (fetch)
    origin  https://github.com/sethbergman/Adopt-a-Pet.git (push)

Then you can set environment variables with the following commands:

$ dokku config:set DOKKU_NGINX_PORT=3000

You can optionally set environment variables with the .env file:

$ dokku config:set:file <path/to/.env>

If the .env file is in the root directory of the repository, then the command would be:

$ dokku config:set:file <.env>
Developing answered 18/8, 2018 at 8:39 Comment(1)
This does not at all answer the original question. OP asked how to get environment variables picked up automatically from a file, not how to set them manually given a file...Misdirect
M
0

If you're using ruby, you can use the gem 'dokku-cli'. With that, you can set config from any file by issuing the command

dokku config:set:file <path/to/file>

See ruby doc

Mauricemauricio answered 15/5, 2018 at 7:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.