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

Mongoid support #8

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -67,7 +67,7 @@ require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/uberspace'
# in the following line replace <database> with mysql, postgresql, or sqlite3
# in the following line replace <database> with mysql, mongoid, postgresql, or sqlite3
require 'capistrano/uberspace/<database>'
```

Expand All @@ -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:
Expand Down
43 changes: 43 additions & 0 deletions lib/capistrano/tasks/uberspace/mongoid.rake
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/capistrano/uberspace/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
1 change: 1 addition & 0 deletions lib/capistrano/uberspace/mongoid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load File.expand_path('../../tasks/uberspace/mongoid.rake', __FILE__)