capistrano-postgresql 3.0.1 → 4.0.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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +22 -113
- data/lib/capistrano/postgresql/helper_methods.rb +6 -0
- data/lib/capistrano/postgresql/psql_helpers.rb +10 -1
- data/lib/capistrano/postgresql/version.rb +1 -1
- data/lib/capistrano/tasks/postgresql.rake +57 -8
- data/lib/generators/capistrano/postgresql/templates/postgresql.yml.erb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4979d4dae2bd808a75c9656d8206de81940ed8a
|
4
|
+
data.tar.gz: 985c1c832fcde7f17e129e196e1a4d41ee19420f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc3160801f01359dfe35aad44085910b8056ddf09be8e194caff6b0dbb70e0427f469a6223e288c32a10d97085d5d67f55f0cd13237428ab753df08b0bb4da79
|
7
|
+
data.tar.gz: c4cf87e7bff7d00e1163f50cdd54e9a9bca1ad55b0be1c9bd2bb96edf9a289006bc0a3dc7a4e0058682e57cc01e123caa8469070abff0380ed80c8c68b6a2bbb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### master
|
4
|
+
|
5
|
+
### v4.0.0, 2014-10-06
|
6
|
+
- enable setting DB environment with `rails_env` option. If `rails_env` is not
|
7
|
+
set, `stage` option is used as until now. (@bruno-)
|
8
|
+
- create a task that helps with the upgrade to gem version 4 (@bruno-)
|
9
|
+
- optionally create a hstore extension on the server (@rhomeister)
|
10
|
+
- `database.yml` is now copied to all release_roles (@rhomeister)
|
11
|
+
- introduce archetype `database.yml` that is stored on primary `db` node and
|
12
|
+
is copied to all `release` nodes on `setup` task (@rhomeister)
|
13
|
+
|
1
14
|
### v3.0.0, 2014-04-11
|
2
15
|
- all the work is moved to the `setup` task
|
16
|
+
|
3
17
|
### v2.0.0, 2014-03-30
|
4
18
|
- shorten variable names: postgresql -> pg
|
5
19
|
- better helpers module separation
|
@@ -7,5 +21,6 @@
|
|
7
21
|
- lots of code improvements
|
8
22
|
- less layered and simpler code
|
9
23
|
- readme updates
|
24
|
+
|
10
25
|
### v1.0.0, 2014-03-19
|
11
26
|
- all the v1.0.0 features
|
data/README.md
CHANGED
@@ -15,17 +15,22 @@ Here are the specific things this plugin does for your capistrano deployment
|
|
15
15
|
process:
|
16
16
|
|
17
17
|
* creates a new PostgreSQL database and database user on the server
|
18
|
-
* generates and populates `database.yml` file
|
18
|
+
* generates and populates `database.yml` file on all release nodes
|
19
19
|
(no need to ssh to the server and do this manually!)
|
20
20
|
* zero-config
|
21
|
+
* support for multi-server setup: separate `db` and `app` nodes (from version 4.0)
|
22
|
+
|
23
|
+
**Note**: gem version 4 introduces some breaking changes. If you installed gem
|
24
|
+
version 3 or below you might want to follow the
|
25
|
+
[upgrade instructions](https://github.com/capistrano-plugins/capistrano-postgresql/wiki/Upgrade-instructions-for-gem-version-4.0).
|
21
26
|
|
22
27
|
### Installation
|
23
28
|
|
24
29
|
Put the following in your application's `Gemfile`:
|
25
30
|
|
26
31
|
group :development do
|
27
|
-
gem 'capistrano', '~> 3.
|
28
|
-
gem 'capistrano-postgresql', '~>
|
32
|
+
gem 'capistrano', '~> 3.2.0'
|
33
|
+
gem 'capistrano-postgresql', '~> 4.0.0'
|
29
34
|
end
|
30
35
|
|
31
36
|
Then:
|
@@ -42,139 +47,43 @@ the following in `Capfile` file:
|
|
42
47
|
Make sure the `deploy_to` path exists and has the right privileges on the
|
43
48
|
server (i.e. `/var/www/myapp`).<br/>
|
44
49
|
Or just install
|
45
|
-
[capistrano-safe-deploy-to](https://github.com/
|
50
|
+
[capistrano-safe-deploy-to](https://github.com/capistrano-plugins/capistrano-safe-deploy-to)
|
46
51
|
plugin and don't think about it.
|
47
52
|
|
48
|
-
To setup the server, run:
|
53
|
+
To setup the server(s), run:
|
49
54
|
|
50
55
|
$ bundle exec cap production setup
|
51
56
|
|
52
|
-
Easy, right?
|
53
|
-
|
54
|
-
Check below to see what happens in the background.
|
55
|
-
|
56
|
-
### How it works
|
57
|
-
|
58
|
-
Check here for the full capistrano deployment flow
|
59
|
-
[http://capistranorb.com/documentation/getting-started/flow/](http://capistranorb.com/documentation/getting-started/flow/).
|
60
|
-
|
61
|
-
The following tasks run during the `setup` task:
|
62
|
-
|
63
|
-
* `postgresql:create_db_user`<br/>
|
64
|
-
creates a postgresql user. Password for the user is automatically generated and
|
65
|
-
used in the next steps.
|
66
|
-
* `postgresql:create_database`<br/>
|
67
|
-
creates database for your app.
|
68
|
-
* `postgresql:generate_database_yml`<br/>
|
69
|
-
creates a `database.yml` file and copies it to
|
70
|
-
`#{shared_path}/config/database.yml` on the server.
|
71
|
-
|
72
|
-
Also, the plugin ensures `config/database.yml` is symlinked from `shared_path`.
|
73
|
-
The above tasks are all you need for getting a Rails app to work with PostgreSQL.
|
74
|
-
|
75
57
|
### Gotchas
|
76
58
|
|
77
59
|
Be sure to remove `config/database.yml` from your application's version control.
|
78
60
|
|
79
|
-
###
|
80
|
-
|
81
|
-
This plugin should just work with no configuration whatsoever. However,
|
82
|
-
configuration is possible. Put all your configs in capistrano stage files i.e.
|
83
|
-
`config/deploy/production.rb`.
|
84
|
-
|
85
|
-
Here's the list of options and the defaults for each option:
|
86
|
-
|
87
|
-
* `set :pg_database`<br/>
|
88
|
-
Name of the database for your app. Defaults to `#{application}_#{stage}`,
|
89
|
-
example: `myface_production`.
|
90
|
-
|
91
|
-
* `set :pg_user`<br/>
|
92
|
-
Name of the database user. Defaults to whatever is set for `pg_database`
|
93
|
-
option.
|
94
|
-
|
95
|
-
* `set :pg_password`<br/>
|
96
|
-
Password for the database user. By default this option is not set and a
|
97
|
-
**new random password** is generated each time you create a new database.<br/>
|
98
|
-
If you set this option to `"some_secure_password"` - that will be the db user's
|
99
|
-
password. Keep in mind that having a hardcoded password in `deploy.rb` (or
|
100
|
-
anywhere in version control) is a bad practice.<br/>
|
101
|
-
I recommend sticking to the default and generating a new secure and random
|
102
|
-
password each time a db user is generated. That way you don't have to worry
|
103
|
-
about it or try to remember it.
|
104
|
-
|
105
|
-
* `set :pg_ask_for_password`<br/>
|
106
|
-
Default `false`. Set this option to `true` if you want to be prompted for the
|
107
|
-
password when database user is created. This is safer than setting the password
|
108
|
-
via `pg_password`. The downside is you have to choose and remember
|
109
|
-
yet another fricking password.<br/>
|
110
|
-
`pg_password` option has precedence. If it is set,
|
111
|
-
`pg_ask_for_password` is ignored.
|
112
|
-
|
113
|
-
* `set :pg_system_user`<br/>
|
114
|
-
Default `postgres`. Set this option to the user that owns the postgres process
|
115
|
-
on your system. Normally the default is fine, but for instance on FreeBSD the
|
116
|
-
default prostgres user is `pgsql`.
|
61
|
+
### How it works
|
117
62
|
|
118
|
-
|
119
|
-
|
120
|
-
Usually there should be no reason to change this from the default.
|
63
|
+
[How the plugin works](https://github.com/capistrano-plugins/capistrano-postgresql/wiki/How-it-works)
|
64
|
+
wiki page contains a list of actions the plugin executes.
|
121
65
|
|
122
|
-
|
66
|
+
Read it only if you want to learn more about the plugin internals.
|
123
67
|
|
124
|
-
|
125
|
-
Pool config in `database.yml` template. Defaults to `5`.
|
68
|
+
### Configuration
|
126
69
|
|
127
|
-
|
128
|
-
|
70
|
+
A full
|
71
|
+
[list of configuration options](https://github.com/capistrano-plugins/capistrano-postgresql/wiki/Configuration-options).
|
129
72
|
|
130
|
-
|
131
|
-
|
73
|
+
The list can be overwhelming so consult it only if you're looking for something
|
74
|
+
specific.
|
132
75
|
|
133
76
|
### Customizing the `database.yml` template
|
134
77
|
|
135
|
-
|
136
|
-
shared directory on the server:
|
137
|
-
|
138
|
-
```yml
|
139
|
-
<%= fetch :stage %>:
|
140
|
-
adapter: postgresql
|
141
|
-
encoding: <%= pg_encoding %>
|
142
|
-
database: <%= pg_database %>
|
143
|
-
pool: <%= pg_pool %>
|
144
|
-
username: <%= pg_user %>
|
145
|
-
password: '<%= pg_password %>'
|
146
|
-
host: <%= pg_host %>
|
147
|
-
```
|
148
|
-
|
149
|
-
If for any reason you want to edit or tweak this template, you can copy it to
|
150
|
-
`config/deploy/templates/postgresql.yml.erb` with this command:
|
151
|
-
|
152
|
-
$ bundle exec rails g capistrano:postgresql:template
|
153
|
-
|
154
|
-
After you edit this newly created file in your repo, it will be used as a
|
155
|
-
template for `database.yml` on the server.
|
156
|
-
|
157
|
-
You can configure the template location. For example:
|
158
|
-
`set :pg_templates_path, "config"` and the template will be copied to
|
159
|
-
`config/postgresql.yml.erb`.
|
78
|
+
[Wiki page about the database.yml format](https://github.com/capistrano-plugins/capistrano-postgresql/wiki/Customizing-the-database.yml-template).
|
160
79
|
|
161
80
|
### More Capistrano automation?
|
162
81
|
|
163
|
-
|
164
|
-
these zero-configuration, plug-n-play plugins:
|
165
|
-
|
166
|
-
- [capistrano-unicorn-nginx](https://github.com/bruno-/capistrano-unicorn-nginx)<br/>
|
167
|
-
no-configuration unicorn and nginx setup with sensible defaults
|
168
|
-
- [capistrano-rbenv-install](https://github.com/bruno-/capistrano-rbenv-install)<br/>
|
169
|
-
would you like Capistrano to install rubies for you?
|
170
|
-
- [capistrano-safe-deploy-to](https://github.com/bruno-/capistrano-safe-deploy-to)<br/>
|
171
|
-
if you're annoyed that Capistrano does **not** create a deployment path for the
|
172
|
-
app on the server (default `/var/www/myapp`), this is what you need!
|
82
|
+
Check out [capistrano-plugins](https://github.com/capistrano-plugins) github org.
|
173
83
|
|
174
84
|
### Contributing and bug reports
|
175
85
|
|
176
|
-
Contributions and improvements are very welcome.
|
177
|
-
I'll look it up shortly.
|
86
|
+
Contributions and improvements are very welcome.
|
178
87
|
|
179
88
|
If something is not working for you, or you find a bug please report it.
|
180
89
|
|
@@ -15,10 +15,16 @@ module Capistrano
|
|
15
15
|
StringIO.new ERB.new(File.read(config_file)).result(binding)
|
16
16
|
end
|
17
17
|
|
18
|
+
# location of database.yml file on clients
|
18
19
|
def database_yml_file
|
19
20
|
shared_path.join('config/database.yml')
|
20
21
|
end
|
21
22
|
|
23
|
+
# location of archetypical database.yml file created on primary db role when user and
|
24
|
+
# database are first created
|
25
|
+
def archetype_database_yml_file
|
26
|
+
deploy_path.join("db/database.yml")
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -4,7 +4,12 @@ module Capistrano
|
|
4
4
|
|
5
5
|
# returns true or false depending on the remote command exit status
|
6
6
|
def psql(*args)
|
7
|
-
|
7
|
+
psql_on_db(fetch(:pg_system_db), *args)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Runs psql on the application database
|
11
|
+
def psql_on_app_db(*args)
|
12
|
+
psql_on_db(fetch(:pg_database), *args)
|
8
13
|
end
|
9
14
|
|
10
15
|
def db_user_exists?(name)
|
@@ -15,6 +20,10 @@ module Capistrano
|
|
15
20
|
psql '-tAc', %Q{"SELECT 1 FROM pg_database WHERE datname='#{db_name}';" | grep -q 1}
|
16
21
|
end
|
17
22
|
|
23
|
+
private
|
24
|
+
def psql_on_db(db_name, *args)
|
25
|
+
test :sudo, "-u #{fetch(:pg_system_user)} psql -d #{db_name}", *args
|
26
|
+
end
|
18
27
|
end
|
19
28
|
end
|
20
29
|
end
|
@@ -14,8 +14,10 @@ namespace :load do
|
|
14
14
|
set :pg_password, -> { ask_for_or_generate_password }
|
15
15
|
set :pg_system_user, 'postgres'
|
16
16
|
set :pg_system_db, 'postgres'
|
17
|
+
set :pg_use_hstore, false
|
17
18
|
# template only settings
|
18
19
|
set :pg_templates_path, 'config/deploy/templates'
|
20
|
+
set :pg_env, -> { fetch(:rails_env) || fetch(:stage) }
|
19
21
|
set :pg_pool, 5
|
20
22
|
set :pg_encoding, 'unicode'
|
21
23
|
set :pg_host, 'localhost'
|
@@ -24,19 +26,42 @@ end
|
|
24
26
|
|
25
27
|
namespace :postgresql do
|
26
28
|
|
29
|
+
desc 'Steps to upgrade the gem to version 4.0'
|
30
|
+
task :upgrade4 do
|
31
|
+
on roles :db do
|
32
|
+
execute :mkdir, '-pv', File.dirname(archetype_database_yml_file)
|
33
|
+
execute :cp, database_yml_file, archetype_database_yml_file
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
27
37
|
# undocumented, for a reason: drops database. Use with care!
|
28
38
|
task :remove_all do
|
29
|
-
on
|
39
|
+
on release_roles :all do
|
30
40
|
if test "[ -e #{database_yml_file} ]"
|
31
41
|
execute :rm, database_yml_file
|
32
42
|
end
|
33
43
|
end
|
44
|
+
|
45
|
+
on primary :db do
|
46
|
+
if test "[ -e #{archetype_database_yml_file} ]"
|
47
|
+
execute :rm, archetype_database_yml_file
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
34
51
|
on roles :db do
|
35
52
|
psql '-c', %Q{"DROP database #{fetch(:pg_database)};"}
|
36
53
|
psql '-c', %Q{"DROP user #{fetch(:pg_user)};"}
|
37
54
|
end
|
38
55
|
end
|
39
56
|
|
57
|
+
desc "Add the hstore extension to postgresql"
|
58
|
+
task :add_hstore do
|
59
|
+
next unless fetch(:pg_use_hstore)
|
60
|
+
on roles :db do
|
61
|
+
psql_on_app_db '-c', %Q{"CREATE EXTENSION IF NOT EXISTS hstore;"}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
40
65
|
desc 'Create DB user'
|
41
66
|
task :create_db_user do
|
42
67
|
on roles :db do
|
@@ -59,12 +84,29 @@ namespace :postgresql do
|
|
59
84
|
end
|
60
85
|
end
|
61
86
|
|
62
|
-
|
87
|
+
# This task creates the archetype database.yml file on the primary db server. This is done once when a
|
88
|
+
# new DB user is created.
|
89
|
+
desc 'Generate database.yml archetype'
|
90
|
+
task :generate_database_yml_archetype do
|
91
|
+
on roles :db, primary: true do
|
92
|
+
next if test "[ -e #{archetype_database_yml_file} ]"
|
93
|
+
execute :mkdir, '-pv', File.dirname(archetype_database_yml_file)
|
94
|
+
upload! pg_template('postgresql.yml.erb'), archetype_database_yml_file
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# This task copies the archetype database file on the primary db server to all clients. This is done on
|
99
|
+
# every setup, to ensure new servers get a copy as well.
|
100
|
+
desc 'Copy archetype database.yml from primary db server to clients'
|
63
101
|
task :generate_database_yml do
|
64
|
-
|
65
|
-
|
102
|
+
database_yml_contents = nil
|
103
|
+
on primary :db do
|
104
|
+
database_yml_contents = download! archetype_database_yml_file
|
105
|
+
end
|
106
|
+
|
107
|
+
on release_roles :all do
|
66
108
|
execute :mkdir, '-pv', shared_path.join('config')
|
67
|
-
upload!
|
109
|
+
upload! StringIO.new(database_yml_contents), database_yml_file
|
68
110
|
end
|
69
111
|
end
|
70
112
|
|
@@ -73,11 +115,18 @@ namespace :postgresql do
|
|
73
115
|
end
|
74
116
|
|
75
117
|
after 'deploy:started', 'postgresql:database_yml_symlink'
|
118
|
+
|
119
|
+
desc 'Postgresql setup tasks'
|
120
|
+
task :setup do
|
121
|
+
invoke "postgresql:create_db_user"
|
122
|
+
invoke "postgresql:create_database"
|
123
|
+
invoke 'postgresql:add_hstore'
|
124
|
+
invoke "postgresql:generate_database_yml_archetype"
|
125
|
+
invoke "postgresql:generate_database_yml"
|
126
|
+
end
|
76
127
|
end
|
77
128
|
|
78
129
|
desc 'Server setup tasks'
|
79
130
|
task :setup do
|
80
|
-
invoke
|
81
|
-
invoke 'postgresql:create_database'
|
82
|
-
invoke 'postgresql:generate_database_yml'
|
131
|
+
invoke "postgresql:setup"
|
83
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Sutic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|