diff --git a/README.md b/README.md index fbbafef..de449b5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Deploy your Rails App to [uberspace](http://uberspace.de) with Capistrano 3. -Has support for MySQL, Potsgresql, and sqlite3 databases. Runs your app with any ruby version available at your uberpace. +Has support for MySQL, Potsgresql, mongoid and sqlite3 databases. Runs your app with any ruby version available at your uberpace. ## Installation @@ -67,7 +67,7 @@ require 'capistrano/rails' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' require 'capistrano/uberspace' -# in the following line replace with mysql, postgresql, or sqlite3 +# in the following line replace with mysql, mongoid, postgresql, or sqlite3 require 'capistrano/uberspace/' ``` @@ -84,6 +84,18 @@ Configurable options: set :ruby_version, '2.2' # default is '2.2', can be set to every ruby version supported by uberspace. set :domain, nil # if you want to deploy your app as a subdomain, configure it here. Use the full URI. E.g. my-custom.example.tld set :add_www_domain, true # default: true; set this to false if you do not want to also use your subdomain with prefixed www. + +# Now you have two options + +set :mongo_db, "databaseName" +set :mongo_host, "localhost" +set :mongo_user, "your-mongodb-username" # must be created first (Do NOT use the ADMIN) +set :mongo_password, "your-mongodb-password" + +# OR + +set :mongo_uri, 'mongodb://user:pass@localhost:PORT/DATABASE_NAME' # DATABASE_NAME could be ENV['APPLICATION'] + ``` Useful tasks: diff --git a/lib/capistrano/tasks/uberspace/mongoid.rake b/lib/capistrano/tasks/uberspace/mongoid.rake new file mode 100644 index 0000000..e9a3aba --- /dev/null +++ b/lib/capistrano/tasks/uberspace/mongoid.rake @@ -0,0 +1,43 @@ +require 'inifile' + +namespace :uberspace do + namespace :mongoid do + task :setup_database_and_config do + on roles fetch(:uberspace_roles) do + config = {} + stages.each do |env| + + if fetch(:mongo_uri, false) + default_params = {'default' => { + 'uri' => "#{fetch(:mongoid_uri)}" + + }} + else + default_params = {'default' => { + 'database' => fetch(:application), + 'hosts' => [ + "#{fetch(:mongo_host)}:#{fetch(:mongo_port)}" + ], + 'options' => {'password' => fetch(:mongo_password), + 'user' => fetch(:mongo_user), + 'auth_source' => fetch(:application), + 'roles' => ['dbOwner']} + }} + end + + config[env] = { + 'clients' => default_params + } + end + + execute "mkdir -p #{shared_path}/config" + execute "touch #{shared_path}/config/mongoid.yml" + puts "deploying to #{shared_path}/config/mongoid.yml" + upload! StringIO.new(config.to_yaml), "#{shared_path}/config/mongoid.yml" + set :linked_files, fetch(:linked_files, []).push('config/mongoid.yml') + end + end + + after :'uberspace:check', :'uberspace:mongoid:setup_database_and_config' + end +end diff --git a/lib/capistrano/uberspace/defaults.rb b/lib/capistrano/uberspace/defaults.rb index 88c8747..4ef4b3b 100644 --- a/lib/capistrano/uberspace/defaults.rb +++ b/lib/capistrano/uberspace/defaults.rb @@ -14,7 +14,7 @@ set :uberspace_roles, :all set :extra_env_variables, fetch(:extra_env_variables) || {} -set :ruby_version, fetch(:ruby_version, '2.2') +set :ruby_version, fetch(:ruby_version, '2.2.3') set :gem_path, (lambda do begin @@ -39,7 +39,7 @@ set :default_env, -> { default_env.merge(fetch(:uberspace_env_variables)) } set :linked_dirs, fetch(:linked_dirs, []).push(*%w(log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads)) -set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml') +set :linked_files, fetch(:linked_files, []).push('config/secrets.yml') # default is "set :bundle_bins, %w{gem rake rails}", but we want to 'gem install bundler' without bundle :) set :bundle_bins, %w(rake rails) diff --git a/lib/capistrano/uberspace/mongoid.rb b/lib/capistrano/uberspace/mongoid.rb new file mode 100644 index 0000000..90f6fe3 --- /dev/null +++ b/lib/capistrano/uberspace/mongoid.rb @@ -0,0 +1 @@ +load File.expand_path('../../tasks/uberspace/mongoid.rake', __FILE__)