diff --git a/README.md b/README.md index 51e4dad..c919f69 100644 --- a/README.md +++ b/README.md @@ -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 dokku@example-dokku-server.com: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 diff --git a/lib/figaro/cli.rb b/lib/figaro/cli.rb index c572615..42cdfc1 100644 --- a/lib/figaro/cli.rb +++ b/lib/figaro/cli.rb @@ -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 dokku@example-dokku-server.com: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 diff --git a/lib/figaro/cli/dokku_set.rb b/lib/figaro/cli/dokku_set.rb new file mode 100644 index 0000000..5962150 --- /dev/null +++ b/lib/figaro/cli/dokku_set.rb @@ -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 diff --git a/spec/figaro/cli/dokku_set_spec.rb b/spec/figaro/cli/dokku_set_spec.rb new file mode 100644 index 0000000..ac6f8d9 --- /dev/null +++ b/spec/figaro/cli/dokku_set_spec.rb @@ -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 diff --git a/spec/support/bin/dokku b/spec/support/bin/dokku new file mode 100755 index 0000000..b8c3540 --- /dev/null +++ b/spec/support/bin/dokku @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require File.expand_path("../../command_interceptor", __FILE__) + +CommandInterceptor.intercept("dokku")