capistrano3-postgres 0.2.0 → 0.2.1
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/README.md +3 -0
- data/lib/capistrano3/postgres/version.rb +1 -1
- data/lib/capistrano3/tasks/postgres.rb +51 -4
- 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: c1823e5322b73aef1707629d1de248d157cd8620
|
|
4
|
+
data.tar.gz: a724ae00fb4140bb00d173d7464ba9a3842d7fd8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a96d1e6c8d2259c76a81f21042fa1bf4b08b91ca3423c41a76992f74f47f88f963b282ea822e41371db5d74c70daf2aeecd62cd3e50426c3ad79dd494897b1ce
|
|
7
|
+
data.tar.gz: e55fca4756984d06bb0519bec5c54fdabac9e39854175e6afee747d6765667a73d2ece519603cf8bc7d731be50b6f0f857f2d6bd90520562423af0b27bee115c
|
data/README.md
CHANGED
|
@@ -19,6 +19,9 @@ Or install it yourself as:
|
|
|
19
19
|
$ gem install capistrano3-postgres
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
|
+
|
|
23
|
+
Capistrano3::Postgres supports [Dotenv](https://github.com/bkeepers/dotenv) gem and automatically loads environment variables from `.env` files if they are used in the project.
|
|
24
|
+
|
|
22
25
|
```ruby
|
|
23
26
|
# Capfile
|
|
24
27
|
|
|
@@ -12,9 +12,7 @@ namespace :load do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
namespace :postgres do
|
|
15
|
-
|
|
16
15
|
namespace :backup do
|
|
17
|
-
|
|
18
16
|
desc 'Create database dump'
|
|
19
17
|
task :create do
|
|
20
18
|
on roles(fetch(:postgres_role)) do |role|
|
|
@@ -128,7 +126,8 @@ namespace :postgres do
|
|
|
128
126
|
on roles(fetch(:postgres_role)) do |role|
|
|
129
127
|
run_locally do
|
|
130
128
|
env = 'development'
|
|
131
|
-
|
|
129
|
+
preload_env_variables(env)
|
|
130
|
+
yaml_content = ERB.new(capture 'cat config/database.yml').result
|
|
132
131
|
set :postgres_local_database_config, database_config_defaults.merge(YAML::load(yaml_content)[env])
|
|
133
132
|
end
|
|
134
133
|
end
|
|
@@ -141,7 +140,13 @@ namespace :postgres do
|
|
|
141
140
|
within release_path do
|
|
142
141
|
env = fetch(:postgres_env).to_s.downcase
|
|
143
142
|
filename = "#{deploy_to}/current/config/database.yml"
|
|
144
|
-
|
|
143
|
+
eval_yaml_with_erb = <<-RUBY.strip
|
|
144
|
+
#{env_variables_loader_code}
|
|
145
|
+
require 'erb'
|
|
146
|
+
puts ERB.new(File.read('#{filename}')).result
|
|
147
|
+
RUBY
|
|
148
|
+
|
|
149
|
+
capture_config_cmd = "ruby -e \"#{eval_yaml_with_erb}\""
|
|
145
150
|
yaml_content = test('ruby -v') ? capture(capture_config_cmd) : capture(:bundle, :exec, capture_config_cmd)
|
|
146
151
|
set :postgres_remote_database_config, database_config_defaults.merge(YAML::load(yaml_content)[env])
|
|
147
152
|
end
|
|
@@ -152,4 +157,46 @@ namespace :postgres do
|
|
|
152
157
|
{ 'host' => 'localhost' }
|
|
153
158
|
end
|
|
154
159
|
|
|
160
|
+
# Load environment variables for configurations.
|
|
161
|
+
# Useful for such gems as Dotenv, Figaro, etc.
|
|
162
|
+
def preload_env_variables(env)
|
|
163
|
+
safely_require_gems('dotenv')
|
|
164
|
+
|
|
165
|
+
if defined?(Dotenv)
|
|
166
|
+
load_env_variables_with_dotenv(env)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def load_env_variables_with_dotenv(env)
|
|
171
|
+
Dotenv.load(
|
|
172
|
+
File.expand_path('.env.local'),
|
|
173
|
+
File.expand_path(".env.#{env}"),
|
|
174
|
+
File.expand_path('.env')
|
|
175
|
+
)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def safely_require_gems(*gem_names)
|
|
179
|
+
gem_names.each do |name|
|
|
180
|
+
begin
|
|
181
|
+
require name
|
|
182
|
+
rescue LoadError
|
|
183
|
+
# Ignore if gem doesn't exist
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Requires necessary gems (Dotenv, Figaro, ...) if present
|
|
189
|
+
# and loads environment variables for configurations
|
|
190
|
+
def env_variables_loader_code
|
|
191
|
+
<<-RUBY.strip
|
|
192
|
+
begin
|
|
193
|
+
require 'dotenv'
|
|
194
|
+
Dotenv.load(
|
|
195
|
+
File.expand_path('.env.production'),
|
|
196
|
+
File.expand_path('.env')
|
|
197
|
+
)
|
|
198
|
+
rescue LoadError
|
|
199
|
+
end
|
|
200
|
+
RUBY
|
|
201
|
+
end
|
|
155
202
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capistrano3-postgres
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Krasynskyi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: capistrano
|