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

Support dokku cli #227

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,34 @@ For more information:
$ figaro help heroku:set
```

#### Dokku

[Dokku](https://github.com/progrium/dokku), like Heroku, provides a way to set application configuration ENV variables via the command line.

```bash
$ dokku config:set google_analytics_key=UA-35722661-5
```

Using the `figaro` command, you can set values from your configuration file all at once:

```bash
$ figaro dokku:set -e production
```

For more information:

```bash
$ figaro help dokku:set
```

In this initial implementation, you need to:

1. Add git remote dokku repository => `git remote add dokku [email protected]:example-app`
2. Do following command => `gem install dokku-cli`

#### Other Hosts

If you're not deploying to Heroku, you have two options:
If you're not deploying to Heroku or Dokku, you have two options:

* Generate a remote configuration file
* Set `ENV` variables directly
Expand Down
26 changes: 26 additions & 0 deletions lib/figaro/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,31 @@ def install
require "figaro/cli/heroku_set"
HerokuSet.run(options)
end

# figaro dokku:set

desc "dokku:set", "Send Figaro configuration to a Dokku app."
long_desc <<-LONGDESC
Sends the Figaro configuration to a Dokku APP on the Dokku SERVER.

Since Dokku does not provide a client, this command requires that:\n\n
1. Add git remote dokku repository => `git remote add dokku [email protected]:example-app`\n\n
2. Do following command => `gem install dokku-cli`
\n\n
LONGDESC

method_option "environment",
aliases: ["-e"],
desc: "Specify an application environment"
method_option "path",
aliases: ["-p"],
default: "config/application.yml",
desc: "Specify a configuration file path"

define_method "dokku:set" do
require "figaro/cli/dokku_set"
DokkuSet.run(options)
end

end
end
25 changes: 25 additions & 0 deletions lib/figaro/cli/dokku_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "figaro/cli/task"

module Figaro
class CLI < Thor
class DokkuSet < Task
def run
system(configuration, command)
end

private

def command
"dokku config:set #{vars}"
end

def vars
configuration.keys.map { |k| var(k) }.join(" ")
end

def var(key)
Gem.win_platform? ? %(#{key}="%#{key}%") : %(#{key}="$#{key}")
end
end
end
end
49 changes: 49 additions & 0 deletions spec/figaro/cli/dokku_set_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
describe "figaro dokku:set" do
before do
create_dir("example")
cd("example")
write_file("config/application.yml", "foo: bar")
end

it "sends Figaro configuration to dokku" do
run_simple("figaro dokku:set")

command = commands.last
expect(command.name).to eq("dokku")
expect(command.args).to eq(["config:set", "foo=bar"])
end

it "respects path" do
write_file("env.yml", "foo: bar")

run_simple("figaro dokku:set -p env.yml")

command = commands.last
expect(command.name).to eq("dokku")
expect(command.args).to eq(["config:set", "foo=bar"])
end

it "respects environment" do
overwrite_file("config/application.yml", <<-EOF)
foo: bar
test:
foo: baz
EOF

run_simple("figaro dokku:set -e test")

command = commands.last
expect(command.name).to eq("dokku")
expect(command.args).to eq(["config:set", "foo=baz"])
end

it "handles values with special characters" do
overwrite_file("config/application.yml", "foo: bar baz")

run_simple("figaro dokku:set")

command = commands.last
expect(command.name).to eq("dokku")
expect(command.args).to eq(["config:set", "foo=bar baz"])
end
end
5 changes: 5 additions & 0 deletions spec/support/bin/dokku
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require File.expand_path("../../command_interceptor", __FILE__)

CommandInterceptor.intercept("dokku")