matross 0.5.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjA3ODRjMThlMzYzOTgxZGE5OTg0NTQ4NDNjZjcyODQxYjNlMmU1Nw==
5
- data.tar.gz: !binary |-
6
- OWUzYWRkYmFjOGU2ZmE3OGQwMTVmNjUwY2MwZDcyMDU5OGFjZDkzMQ==
2
+ SHA1:
3
+ metadata.gz: 16ea939d8285bf5288eea7bcf72c0ed739114c39
4
+ data.tar.gz: 5e6cbf82b320fbad26557833a5cb6747969324a8
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZDJiNjU2M2U1ZTg5ZmQwNDUwODgxZjU1ZDNhY2VjNmQ4YjU2Y2U2MmRiYjgx
10
- M2ZmMzY0ODNjYTVlOGU5ODY4MWUxNTlkODQ5OTEwNWFlN2JkNWY0ZmQ5N2E3
11
- ODFmN2I3ZWE3MDcyNzI3ZTg5YzVhYWIxNTU5NmVlYTIwOTJmOTE=
12
- data.tar.gz: !binary |-
13
- MzA1MjBkNDdiMDE3ODExNDA5YzY3ZDU0ZWVjNjhhOTVjNDExZjg0ZGVlN2Yx
14
- MjRkNDM5YjA0M2I5YTVkMGYxNTJkODhhOTM4M2Y1YmU4ZWVlNDM3ZWRkN2Zj
15
- N2Q4MmM2NDU1YjJhNDQyMGQ1NzQ4OTI0YWRlNjFmYThlNWRlYmM=
6
+ metadata.gz: 2a27e55db950c079071df47755b76b7ab22297843ee802ff2a12926424f5128d5980aed5a63227725b7e7efa0631ce7fd3711e46d90eeadd6e79844d41f1c925
7
+ data.tar.gz: 5ccfb6730d71d8577eafa1c70e916820e3e20ec11745cfe47450d11d17fa147ccb212ca56189c556f99d444daa5ba04888cfd26248ddcbadcd5ea3b1f07ff47d
data/README.md CHANGED
@@ -112,7 +112,7 @@ Procfile task: `web: bundle exec unicorn -c <%= unicorn_config %> -E <%= rails_e
112
112
 
113
113
  ### Nginx
114
114
 
115
- This recipes creates and configures the virtual_host for the application. [This virtual host] has some sane defaults, suitable for most of our deployments (non-SSL). The file is created at `/etc/nginx/sites-available` and symlinked to `/etc/nginx/sites-enabled`. These are the defaults for the Nginx installation in Ubuntu. You can take a look at [our general `nginx.conf`](https://github.com/innvent/parcelles/blob/puppet/puppet/modules/nginx/files/nginx.conf).
115
+ This recipes creates and configures the virtual_host for the application. [This virtual host] has some sane defaults, suitable for most of our deployments (non-SSL). The file is created at `/etc/nginx/sites-available` and symlinked to `/etc/nginx/sites-enabled`. These are the defaults for the Nginx installation in Ubuntu. You can take a look at [our general `nginx.conf`](https://github.com/innvent/parcelles/blob/master/puppet/modules/nginx/files/nginx.conf).
116
116
 
117
117
  Overwritable template: [`nginx_virtual_host_conf.erb`](lib/matross/templates/nginx/nginx_virtual_host_conf.erb)
118
118
 
@@ -156,17 +156,42 @@ Overwritable template: [`database.yml.erb`](lib/matross/templates/mysql/database
156
156
 
157
157
  > Tasks
158
158
 
159
- | Task | Description |
160
- | --- | --- |
161
- | `mysql:setup` | Creates the `database.yml` in the `shared_path` |
162
- | `mysql:symlink` | Creates a symlink for the `database.yml` file in the `current_path` |
163
- | `mysql:create` | Creates the database if it hasn't been created |
164
- | `mysql:schema_load` | Loads the schema if there are no tables in the DB |
165
- | `mysql:backup:setup` | Creates the backup script and configures the user's cron - *Not hooked to any other task* |
166
- | `mysql:dump:do` | Dumps the application database |
167
- | `mysql:dump:get` | Downloads a copy of the last generated database dump |
168
- | `mysql:dump:apply` | Apply the latest dump generated stored in 'dumps' locally |
159
+ | Task | Description |
160
+ | --- | --- |
161
+ | `mysql:setup` | Creates the `database.yml` in the `shared_path` |
162
+ | `mysql:symlink` | Creates a symlink for the `database.yml` file in the `current_path` |
163
+ | `mysql:create` | Creates the database if it hasn't been created |
164
+ | `mysql:schema_load` | Loads the schema if there are no tables in the DB |
165
+ | `mysql:backup:setup` | Creates the backup script and configures the user's cron - *Not hooked to any other task* |
166
+ | `mysql:dump:do` | Dumps the application database |
167
+ | `mysql:dump:get` | Downloads a copy of the last generated database dump |
168
+ | `mysql:dump:apply` | Applies the latest dump generated stored in 'dumps' locally |
169
+ | `mysql:dump:post` | Uploads a copy of the last generated database dump |
170
+ | `mysql:dump:apply_remotely` | Applies the latest uploaded dump in the remote server |
169
171
 
172
+ ### PostgreSQL
173
+
174
+ Requires having [`pg`](http://rubygems.org/gems/pg) available in the application. In our PostgreSQL recipe we dynamically generate a `database.yml` based on the variables that should be set globally or per-stage.
175
+
176
+ **Please note** that we rely on local peer connection, hence, remote connections should use a custom template for `database.yml.erb`. **The PG cluster must have `UTF8` encoding.
177
+
178
+ Overwritable template: [`database.yml.erb`](lib/matross/templates/postgresql/database.yml.erb)
179
+
180
+ > Variables
181
+
182
+ | Variable | Default value | Description |
183
+ | --- | --- | --- |
184
+ | `:database_config` | `"#{shared_path}/config/database.yml"` | Location of the configuration file |
185
+ | `:postgresql_database` | None | PostgreSQL database name. Dashes `-` are *gsubed* for underscores `_` |
186
+ | `:postgresql_user` | `user` | PostgreSQL user |
187
+
188
+ > Tasks
189
+
190
+ | Task | Description |
191
+ | --- | --- |
192
+ | `postgresql:setup` | Creates the `database.yml` in the `shared_path`, and the user if needed |
193
+ | `postgresql:symlink` | Creates a symlink for the `database.yml` file in the `current_path` |
194
+ | `postgresql:create` | Creates the database if it hasn't been created and loads the schema |
170
195
 
171
196
  ## Mongoid
172
197
 
@@ -6,20 +6,20 @@ _cset :mysql_backup_cron_schedule, '30 3 * * *'
6
6
 
7
7
  namespace :mysql do
8
8
 
9
- desc "Creates the database.yml file in shared path"
9
+ desc "Create the database.yml file in shared path"
10
10
  task :setup, :roles => [:app, :dj] do
11
11
  run "mkdir -p #{shared_path}/config"
12
12
  template "mysql/database.yml.erb", database_config
13
13
  end
14
14
  after "deploy:setup", "mysql:setup"
15
15
 
16
- desc "Updates the symlink for database.yml for deployed release"
16
+ desc "Update the symlink for database.yml for deployed release"
17
17
  task :symlink, :roles => [:app, :dj] do
18
18
  run "ln -nfs #{database_config} #{release_path}/config/database.yml"
19
19
  end
20
20
  after "bundle:install", "mysql:symlink"
21
21
 
22
- desc "Creates the application database"
22
+ desc "Create the application database"
23
23
  task :create, :roles => :db do
24
24
  sql = <<-EOF.gsub(/^\s+/, '')
25
25
  CREATE DATABASE IF NOT EXISTS #{mysql_database.gsub("-", "_")};
@@ -31,7 +31,7 @@ namespace :mysql do
31
31
  end
32
32
  after "mysql:setup", "mysql:create"
33
33
 
34
- desc "Loads the application schema into the database"
34
+ desc "Load the application schema into the database"
35
35
  task :schema_load, :roles => :db do
36
36
  sql = <<-EOF.gsub(/^\s+/, '')
37
37
  SELECT count(*) FROM information_schema.TABLES WHERE (TABLE_SCHEMA = '#{mysql_database.gsub("-", "_")}');
@@ -51,7 +51,7 @@ namespace :mysql do
51
51
 
52
52
  # This routine is heavily inspired by whenever's approach
53
53
  # https://github.com/javan/whenever
54
- desc "Updates the crontab"
54
+ desc "Update the crontab with the backup entry"
55
55
  task :setup, :roles => :db do
56
56
  template "mysql/backup.sh.erb", mysql_backup_script
57
57
  run "chmod +x #{mysql_backup_script}"
@@ -91,7 +91,7 @@ namespace :mysql do
91
91
 
92
92
  namespace :dump do
93
93
 
94
- desc "Dumps the application database"
94
+ desc "Dump the application database"
95
95
  task :do, :roles => :db, :except => { :no_release => true } do
96
96
  run "mkdir -p #{shared_path}/dumps"
97
97
  run %W{cd #{shared_path}/dumps &&
@@ -103,7 +103,7 @@ namespace :mysql do
103
103
  gzip > "$(date +'#{mysql_database}_\%Y\%m\%d\%H\%M.sql.gz')"} * ' '
104
104
  end
105
105
 
106
- desc "Downloads a copy of the last generated database dump"
106
+ desc "Download a copy of the last generated database dump"
107
107
  task :get, :roles => :db, :except => { :no_release => true } do
108
108
  run_locally "mkdir -p dumps"
109
109
  most_recent_bkp = capture(%W{find #{shared_path} -type f -name
@@ -127,5 +127,33 @@ namespace :mysql do
127
127
  #{'--password=' + db_config['password'] unless db_config['password'].nil?}
128
128
  #{db_config['database']} < #{most_recent_bkp}} * ' '
129
129
  end
130
+
131
+ desc "Upload a copy of the last generated database dump"
132
+ task :post, :roles => :db, :except => { :no_release => true } do
133
+ run "mkdir -p #{shared_path}/dumps"
134
+ most_recent_bkp = %x[find dumps -type f -name '*.sql'].split.sort.last
135
+ abort 'No dump found. Run mysql:dump:get' if most_recent_bkp.nil?
136
+
137
+ run_locally "gzip -k #{most_recent_bkp}"
138
+ zipped_bkp = most_recent_bkp + '.gz'
139
+
140
+ upload zipped_bkp, "#{shared_path}/dumps", :via => :scp
141
+ run_locally "rm #{zipped_bkp}"
142
+ end
143
+
144
+ desc "Apply the latest uploaded dump in the remote server"
145
+ task :apply_remotely, :roles => :db, :except => { :no_release => true } do
146
+ most_recent_bkp = capture(%W{find #{shared_path} -type f -name '*.sql.gz'} * ' ').split.sort.last
147
+ abort 'No dump found. Run mysql:dump:post' if most_recent_bkp.nil?
148
+
149
+ db_config = YAML.load(capture("cat #{shared_path}/config/database.yml"))[rails_env]
150
+ run %W{zcat #{most_recent_bkp} | mysql --user=#{db_config['username']}
151
+ --host=#{db_config['host']}
152
+ #{'--password=' + db_config['password'] unless db_config['password'].nil?}
153
+ #{db_config['database']}} * ' '
154
+ end
155
+ before "mysql:dump:apply_remotely", "foreman:stop"
156
+ after "mysql:dump:apply_remotely", "foreman:restart"
157
+
130
158
  end
131
159
  end
@@ -0,0 +1,44 @@
1
+ dep_included? 'pg'
2
+
3
+ _cset(:database_config) { "#{shared_path}/config/database.yml" }
4
+ _cset(:postgresql_user) { user }
5
+
6
+ namespace :postgresql do
7
+
8
+ desc 'Create the database.yml file in shared path. User is created if needed'
9
+ task :setup, :roles => [:app, :dj] do
10
+ run "mkdir -p #{shared_path}/config"
11
+ template "postgresql/database.yml.erb", database_config
12
+ user_count = capture(%W{ sudo -u postgres psql postgres -tAc
13
+ "SELECT 1 FROM pg_roles
14
+ WHERE rolname='#{postgresql_user}'" } * ' ').to_i
15
+ if user_count == 0
16
+ run "#{sudo} -u postgres createuser -d -r -s #{postgresql_user}"
17
+ else
18
+ logger.info 'User already created, skpping'
19
+ end
20
+ end
21
+ after 'deploy:setup', 'postgresql:setup'
22
+
23
+ desc 'Update the symlink for database.yml for deployed release'
24
+ task :symlink, :roles => [:app, :dj] do
25
+ run "ln -nfs #{database_config} #{release_path}/config/database.yml"
26
+ end
27
+ after 'bundle:install', 'postgresql:symlink'
28
+
29
+ desc "Create the database and load the schema"
30
+ task :create, :roles => :db do
31
+ db_count = capture(%W{ #{sudo} -u postgres psql -lqt |
32
+ cut -d \\| -f 1 |
33
+ grep -w #{postgresql_database.gsub("-", "_")} |
34
+ wc -l } * ' ').to_i
35
+ if db_count == 0
36
+ run %W{ cd #{release_path} &&
37
+ RAILS_ENV=#{rails_env.to_s.shellescape}
38
+ bundle exec rake db:create db:schema:load } * ' '
39
+ else
40
+ logger.info 'DB is already configured, skipping'
41
+ end
42
+ end
43
+ after 'postgresql:symlink', 'postgresql:create'
44
+ end
@@ -0,0 +1,6 @@
1
+ <%= rails_env %>:
2
+ adapter: postgresql
3
+ encoding: utf8
4
+ database: <%= postgresql_database.gsub("-", "_") %>
5
+ pool: 5
6
+ reconnect: true
@@ -1,3 +1,3 @@
1
1
  module Matross
2
- VERSION = '0.5.5'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matross
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Rodrigues
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-16 00:00:00.000000000 Z
12
+ date: 2014-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.3'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.3'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: pry
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ! '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
@@ -61,7 +61,7 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - .gitignore
64
+ - ".gitignore"
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -77,6 +77,7 @@ files:
77
77
  - lib/matross/mongoid.rb
78
78
  - lib/matross/mysql.rb
79
79
  - lib/matross/nginx.rb
80
+ - lib/matross/postgresql.rb
80
81
  - lib/matross/templates/base/logrotate.erb
81
82
  - lib/matross/templates/faye/faye.ru.erb
82
83
  - lib/matross/templates/faye/faye_server.yml.erb
@@ -86,6 +87,7 @@ files:
86
87
  - lib/matross/templates/mysql/backup.sh.erb
87
88
  - lib/matross/templates/mysql/database.yml.erb
88
89
  - lib/matross/templates/nginx/nginx_virtual_host_conf.erb
90
+ - lib/matross/templates/postgresql/database.yml.erb
89
91
  - lib/matross/templates/unicorn/unicorn.rb.erb
90
92
  - lib/matross/unicorn.rb
91
93
  - lib/matross/version.rb
@@ -100,18 +102,19 @@ require_paths:
100
102
  - lib
101
103
  required_ruby_version: !ruby/object:Gem::Requirement
102
104
  requirements:
103
- - - ! '>='
105
+ - - ">="
104
106
  - !ruby/object:Gem::Version
105
107
  version: '0'
106
108
  required_rubygems_version: !ruby/object:Gem::Requirement
107
109
  requirements:
108
- - - ! '>='
110
+ - - ">="
109
111
  - !ruby/object:Gem::Version
110
112
  version: '0'
111
113
  requirements: []
112
114
  rubyforge_project:
113
- rubygems_version: 2.2.1
115
+ rubygems_version: 2.2.2
114
116
  signing_key:
115
117
  specification_version: 4
116
118
  summary: Our collection of opnionated Capistrano recipes
117
119
  test_files: []
120
+ has_rdoc: